Something went wrong. Try again.
Your trusty automation assistant in TLE Community misadventures!
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171/* global describe *//* global it */
import chai from 'chai'import _ from 'lodash'
import { util } from '@tlecommunity/super-core'
const { expect } = chai
describe('util', () => { describe('#array', () => { it('should handle undefined', () => { expect(util.array(undefined)).to.a('array') expect(util.array(null)).to.a('array') expect(util.array()).to.a('array') })
it('should make something into an array', () => { expect(util.array({})).to.be.a('array') expect(util.array([]).length).to.equal(0) expect(util.array(10)[0]).to.equal(10) }) })
describe('#commify', () => { it('should handle undefined', () => { expect(util.commify(undefined)).to.equal('') expect(util.commify(null)).to.equal('') })
it('should commify numbers', () => { expect(util.commify(111111)).to.equal('111, 111') }) })
describe('#formatMs', () => { it('should handle undefined', () => { expect(util.formatMs(undefined)).to.equal('') expect(util.formatMs(null)).to.equal('') })
it('should format milliseconds properly', () => { expect(util.formatMs(10 * 1000)).to.equal('0:10') expect(util.formatMs(5 * 60 * 1000 + 3 * 1000)).to.equal('5:03') expect(util.formatMs(60 * 60 * 1000)).to.equal('1:00:00') expect(util.formatMs(60 * 60 * 1000 + 10 * 1000)).to.equal('1:00:10') expect(util.formatMs(2 * 24 * 60 * 60 * 1000 + 3 * 60 * 60 * 1000)).to.equal('2:03:00:00') }) })
describe('#formatServerDate', () => { it('should handle undefined', () => { expect(util.formatServerDate(undefined)).to.equal('') expect(util.formatServerDate(null)).to.equal('') })
it('should format server dates', () => { // We can't actually test the content of the string because it's different for each time zone! expect(util.formatServerDate('28 01 2016 06:40:45 +0000')).to.be.a('string') }) })
describe('#int', () => { it('should handle undefined', () => { expect(util.int(undefined)).to.equal(0) expect(util.int(null)).to.equal(0) })
it('should make numbers into integers', () => { expect(util.int('10')).to.equal(10) expect(util.int('10.78592340')).to.equal(10) expect(util.int(10.7859234)).to.equal(10) }) })
describe('#isCLI', () => { it('should be correct for the CLI', () => { // At time of writing, these tests are only run in the command line. expect(util.isCLI()).to.equal(true) }) })
describe('#isMultiple', () => { it('should know math', () => { expect(util.isMultiple(10, 5)).to.equal(true) }) })
describe('#isWeb', () => { it('should be correct for the CLI', () => { // At time of writing, these tests are only run in the command line. expect(util.isWeb()).to.equal(false) }) })
describe('#mean', () => { it('should handle undefined', () => { expect(util.mean(undefined)).to.equal(0) expect(util.mean(null)).to.equal(0) })
it('should be mean to those numbers', () => { expect(util.mean([1, 2, 3])).to.equal(2) }) })
// This will be quite tricky to unit test. describe('#msFromNow', _.noop)
describe('#objectToArray', () => { it('should convert an object to an array', () => { const start = { 1111: { foo: 'bar', }, 2222: { spam: 'eggs', }, }
const end = [ { id: '1111', foo: 'bar', }, { id: '2222', spam: 'eggs', }, ]
expect(_.isEqual(util.objectToArray(start, 'id'), end)).to.equal(true) }) })
describe('#handlePlurality', () => { it('should handle undefined input', () => { expect(util.handlePlurality(undefined, 'ship')).to.equal('ship') expect(util.handlePlurality(null, 'ship')).to.equal('ship')
expect(util.handlePlurality(10, undefined)).to.equal('') expect(util.handlePlurality(10, null)).to.equal('')
expect(util.handlePlurality(undefined, undefined)).to.equal('') expect(util.handlePlurality(null, null)).to.equal('') }) it('should make words plural when necessary', () => { expect(util.handlePlurality(10, 'ship')).to.equal('ships') expect(util.handlePlurality(10, 'ships')).to.equal('ships') })
it('should make works singular when necessary', () => { expect(util.handlePlurality(1, 'ship')).to.equal('ship') expect(util.handlePlurality(1, 'ships')).to.equal('ship') }) })
describe('#regexMatch', () => { it('should return true when a regex matches', () => { expect(util.regexMatch(/fuck shit donkey dick/, 'fuck shit donkey dick')).to.equal(true) }) })
describe('#round', () => { it('should round a number', () => { expect(util.round(10.1178490174892107, 2)).to.equal(10.12) }) })})