diff --git a/frontend/src/Metamaps/Util.js b/frontend/src/Metamaps/Util.js index 773b622f..23fbac7f 100644 --- a/frontend/src/Metamaps/Util.js +++ b/frontend/src/Metamaps/Util.js @@ -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 }, diff --git a/frontend/test/Metamaps.Util.spec.js b/frontend/test/Metamaps.Util.spec.js new file mode 100644 index 00000000..d6b78f3d --- /dev/null +++ b/frontend/test/Metamaps.Util.spec.js @@ -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') + }) + }) +})