first few Util tests
This commit is contained in:
parent
58fe65a4af
commit
1809293031
2 changed files with 49 additions and 5 deletions
|
@ -22,11 +22,10 @@ const Util = {
|
|||
return b + s
|
||||
},
|
||||
|
||||
nowDateFormatted: function () {
|
||||
var date = new Date(Date.now())
|
||||
var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
|
||||
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
var year = date.getFullYear()
|
||||
nowDateFormatted: function (date = new Date(Date.now())) {
|
||||
const month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
|
||||
const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
const year = date.getFullYear()
|
||||
|
||||
return month + '/' + day + '/' + year
|
||||
},
|
||||
|
|
45
frontend/test/Metamaps.Util.spec.js
Normal file
45
frontend/test/Metamaps.Util.spec.js
Normal 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')
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Reference in a new issue