diff --git a/frontend/src/Metamaps/Util.js b/frontend/src/Metamaps/Util.js index 23fbac7f..749dc32e 100644 --- a/frontend/src/Metamaps/Util.js +++ b/frontend/src/Metamaps/Util.js @@ -88,10 +88,13 @@ const Util = { } return coords }, - getPastelColor: function () { - var r = (Math.round(Math.random() * 127) + 127).toString(16) - var g = (Math.round(Math.random() * 127) + 127).toString(16) - var b = (Math.round(Math.random() * 127) + 127).toString(16) + getPastelColor: function ({ rseed, gseed, bseed }) { + if (rseed === undefined) rseed = Math.random() + if (gseed === undefined) gseed = Math.random() + if (bseed === undefined) bseed = Math.random() + var r = (Math.round(rseed * 127) + 127).toString(16) + var g = (Math.round(gseed * 127) + 127).toString(16) + var b = (Math.round(bseed * 127) + 127).toString(16) return Util.colorLuminance('#' + r + g + b, -0.4) }, // darkens a hex value by 'lum' percentage @@ -113,13 +116,6 @@ const Util = { return rgb }, - generateOptionsList: function (data) { - var newlist = '' - for (var i = 0; i < data.length; i++) { - newlist = newlist + '' - } - return newlist - }, checkURLisImage: function (url) { // when the page reloads the following regular expression will be screwed up // please replace it with this one before you save: /*backslashhere*.(jpeg|jpg|gif|png)$/ diff --git a/frontend/test/Metamaps.Util.spec.js b/frontend/test/Metamaps.Util.spec.js index d6b78f3d..09e6711c 100644 --- a/frontend/test/Metamaps.Util.spec.js +++ b/frontend/test/Metamaps.Util.spec.js @@ -23,10 +23,10 @@ describe('Metamaps.Util.js', function () { }) }) describe('nowDateFormatted', function() { - // TODO need `Date` + it.skip('TODO need `Date`') }) describe('decodeEntities', function() { - // TODO need `document` + it.skip('TODO need `document`') }) describe('getDistance', function() { it('(0,0) -> (0,0) = 0', function() { @@ -42,4 +42,87 @@ describe('Metamaps.Util.js', function () { .to.equal('8.6023') }) }) + describe('coordsToPixels', function() { + it('returns 0,0 for null canvas', function() { + expect(Util.coordsToPixels(null).x).to.equal(0) + expect(Util.coordsToPixels(null).y).to.equal(0) + }) + it.skip('TODO need initialized mGraph to test further') + }) + describe('pixelsToCoords', function() { + it('returns 0,0 for null canvas', function() { + expect(Util.pixelsToCoords(null).x).to.equal(0) + expect(Util.pixelsToCoords(null).y).to.equal(0) + }) + it.skip('TODO need initialized mGraph to test further') + }) + describe('getPastelColor', function() { + it('1 => fefefe', function() { + expect(Util.getPastelColor({ rseed: 1, gseed: 1, bseed: 1 })) + .to.equal(Util.colorLuminance('#fefefe', -0.4)) + }) + it('0 => 7f7f7f', function() { + expect(Util.getPastelColor({ rseed: 0, gseed: 0, bseed: 0 })) + .to.equal(Util.colorLuminance('#7f7f7f', -0.4)) + }) + }) + describe('colorLuminance', function() { + describe('-0.4 lum', function() { + it('white => ?', function() { + expect(Util.colorLuminance('#ffffff', -0.4)).to.equal('#999999') + }) + it('black => ?', function() { + expect(Util.colorLuminance('#000000', -0.4)).to.equal('#000000') + }) + it('7f7f7f => ?', function() { + expect(Util.colorLuminance('#7f7f7f', -0.4)).to.equal('#4c4c4c') + }) + }) + + describe('other lum values', function() { + it('-1', function() { + expect(Util.colorLuminance('#7f7f7f', -1)).to.equal('#000000') + }) + it('-0.5', function() { + expect(Util.colorLuminance('#7f7f7f', -0.5)).to.equal('#404040') + }) + it('0', function() { + expect(Util.colorLuminance('#7f7f7f', 0)).to.equal('#7f7f7f') + }) + it('0.5', function() { + expect(Util.colorLuminance('#7f7f7f', 0.5)).to.equal('#bfbfbf') + }) + it('1', function() { + expect(Util.colorLuminance('#7f7f7f', 1)).to.equal('#fefefe') + }) + }) + }) + describe('openLink', function() { + it.skip('TODO need `window`') + }) + describe('mdToHTML', function() { + it('filters xss', function() { + const md = '' + const html = '' + expect(Util.mdToHTML(md).trim()).to.equal(html) + }) + + it('bold and italics', function() { + const md = '**Bold** *Italics*' + const html = '
Bold Italics
' + expect(Util.mdToHTML(md).trim()).to.equal(html) + }) + + it('links and images', function() { + const md = '[Link](https://metamaps.cc) ' + const html = '' + expect(Util.mdToHTML(md).trim()).to.equal(html) + }) + }) + describe('logCanvasAttributes', function() { + it.skip('TODO need a canvas') + }) + describe('resizeCanvas', function() { + it.skip('TODO need a canvas') + }) }) diff --git a/package.json b/package.json index 8dca7615..940f7c58 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "build": "webpack", "build:watch": "webpack --watch", - "test": "mocha --compilers js:babel-core/register frontend/test || (echo 'Run `npm install` to setup testing' && false)" + "test": "mocha --compilers js:babel-core/register frontend/test" }, "repository": { "type": "git",