first few Util tests

This commit is contained in:
Devin Howard 2016-10-20 18:49:11 +08:00
parent 58fe65a4af
commit 1809293031
2 changed files with 49 additions and 5 deletions

View file

@ -22,11 +22,10 @@ const Util = {
return b + s return b + s
}, },
nowDateFormatted: function () { nowDateFormatted: function (date = new Date(Date.now())) {
var date = new Date(Date.now()) const month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1) const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() const year = date.getFullYear()
var year = date.getFullYear()
return month + '/' + day + '/' + year return month + '/' + day + '/' + year
}, },

View file

@ -0,0 +1,45 @@
/* global describe, it */
import chai from 'chai'
import Util from '../src/Metamaps/Util'
const { expect } = chai
describe('Metamaps.Util.js', function () {
describe('splitLine', function() {
it('splits on words', function() {
expect(Util.splitLine('test test test', 10))
.to.equal('test test\ntest')
})
// TODO this test seems like it's incorrect behaviour
it('splits mid-word if need be', function() {
expect(Util.splitLine('test test', 2))
.to.equal("te\nt\nte\nt")
})
it('splits words over 30 chars', function() {
expect(Util.splitLine('suprainterpostantidisestablishmentarianism', 30))
.to.equal("suprainterpostantidisestablish\nentarianism")
})
})
describe('nowDateFormatted', function() {
// TODO need `Date`
})
describe('decodeEntities', function() {
// TODO need `document`
})
describe('getDistance', function() {
it('(0,0) -> (0,0) = 0', function() {
expect(Util.getDistance({ x: 0, y: 0 }, { x: 0, y: 0 }))
.to.equal(0)
})
it('(-5,0) -> (5,0) = 10', function() {
expect(Util.getDistance({ x: -5, y: 0 }, { x: 5, y: 0 }))
.to.equal(10)
})
it('(0,0) -> (5,7) = 8.6023', function() {
expect(Util.getDistance({ x: 0, y: 0 }, { x: 5, y: 7 }).toFixed(4))
.to.equal('8.6023')
})
})
})