From b2f2f5a38c51dfdc2c13bc1875fbf92c05efb5b3 Mon Sep 17 00:00:00 2001 From: joswinter Date: Wed, 15 Mar 2017 18:49:22 +0100 Subject: [PATCH 1/6] Tested setTransition behaviour in diff#diffStyles --- test/unit/style-spec/diff.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/unit/style-spec/diff.test.js b/test/unit/style-spec/diff.test.js index 99b1c8b5d00..606e0b8993d 100644 --- a/test/unit/style-spec/diff.test.js +++ b/test/unit/style-spec/diff.test.js @@ -292,5 +292,20 @@ t('diff', (t) => { { command: 'addLayer', args: [{id: 'b', source: 'foo'}, 'c'] } ], 'changing a source removes and re-adds dependent layers'); + t.deepEqual(diffStyles({ + sources: { foo: { data: 1 }, bar: {} }, + layers: [ + { id: 'a', source: 'bar' } + ] + }, { + sources: { foo: { data: 1 }, bar: {} }, + layers: [ + { id: 'a', source: 'bar' } + ], + transition: 'transition' + }), [ + { command: 'setTransition', args: ['transition'] } + ], 'changing transition'); + t.end(); }); From 9c6662d78dce88a184b863c6e57a14e95c019f1d Mon Sep 17 00:00:00 2001 From: joswinter Date: Wed, 15 Mar 2017 18:50:16 +0100 Subject: [PATCH 2/6] Tested incorrect url match behaviour in composite --- test/unit/style-spec/composite.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/unit/style-spec/composite.test.js b/test/unit/style-spec/composite.test.js index ac6e7627445..9918bb73461 100644 --- a/test/unit/style-spec/composite.test.js +++ b/test/unit/style-spec/composite.test.js @@ -58,3 +58,23 @@ test('does not composite vector + raster', (t) => { t.deepEqual(Object.keys(result.sources), ["a", "b"]); t.end(); }); + +test('incorrect url match', (t) => { + const result = composite({ + "version": 7, + "sources": { + "a": { + "type": "vector", + "url": "mapbox://a" + }, + "b": { + "type": "vector", + "url": "" + } + }, + "layers": [] + }); + + t.deepEqual(Object.keys(result.sources), ["a", "b"]); + t.end(); +}); From e18b888d6899b58055ae310942474e08f7dec360 Mon Sep 17 00:00:00 2001 From: joswinter Date: Wed, 15 Mar 2017 19:01:05 +0100 Subject: [PATCH 3/6] Tested color_spaces#hcl.{forward,reverse} --- .../style-spec/function/color_spaces.test.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/unit/style-spec/function/color_spaces.test.js diff --git a/test/unit/style-spec/function/color_spaces.test.js b/test/unit/style-spec/function/color_spaces.test.js new file mode 100644 index 00000000000..6464086b244 --- /dev/null +++ b/test/unit/style-spec/function/color_spaces.test.js @@ -0,0 +1,32 @@ +'use strict'; + +const test = require('mapbox-gl-js-test').test; +const colorSpaces = require('../../../../src/style-spec/function/color_spaces'); + +test('#hclToRgb zero', (t) => { + const hclColor = [0, 0, 0, null]; + const rgbColor = [0, 0, 0, null]; + t.deepEqual(colorSpaces.hcl.reverse(hclColor), rgbColor); + t.end(); +}); + +test('#hclToRgb', (t) => { + const hclColor = [20, 20, 20, null]; + const rgbColor = [76.04087881379073, 36.681898967046166, 39.08743507357837, null]; + t.deepEqual(colorSpaces.hcl.reverse(hclColor), rgbColor); + t.end(); +}); + +test('#rgbToHcl zero', (t) => { + const hclColor = [0, 0, 0, null]; + const rgbColor = [0, 0, 0, null]; + t.deepEqual(colorSpaces.hcl.forward(rgbColor), hclColor); + t.end(); +}); + +test('#rgbToHcl', (t) => { + const hclColor = [158.19859051364818, 0.0000029334887311101764, 6.318928745123017, null]; + const rgbColor = [20, 20, 20, null]; + t.deepEqual(colorSpaces.hcl.forward(rgbColor), hclColor); + t.end(); +}); From 6ae90dc9dd6c4d394cbb2fd9e3dc7cbb1ab074d2 Mon Sep 17 00:00:00 2001 From: joswinter Date: Wed, 15 Mar 2017 21:04:27 +0100 Subject: [PATCH 4/6] Tested migrate function on different input --- test/unit/style-spec/migrate.test.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/unit/style-spec/migrate.test.js b/test/unit/style-spec/migrate.test.js index bbe5435b3b6..fdd72a93bfe 100644 --- a/test/unit/style-spec/migrate.test.js +++ b/test/unit/style-spec/migrate.test.js @@ -12,7 +12,19 @@ const t = require('mapbox-gl-js-test').test, const UPDATE = !!process.env.UPDATE; -t('migrates to latest version', (t) => { +t('does not migrate from version 5', (t) => { + t.throws(() => { + migrate({version: 5, layers: []}); + }, new Error('cannot migrate from', 5)); + t.end(); +}); + +t('migrates to latest version from version 6', (t) => { + t.deepEqual(migrate({version: 6, layers: []}).version, spec.latest.$version); + t.end(); +}); + +t('migrates to latest version from version 7', (t) => { t.deepEqual(migrate({version: 7, layers: []}).version, spec.latest.$version); t.end(); }); From badae85f11b13e556be17ac37429f52d55acf18f Mon Sep 17 00:00:00 2001 From: joswinter Date: Wed, 15 Mar 2017 21:33:17 +0100 Subject: [PATCH 5/6] Tested uncovered behaviour in StyleLayer --- test/unit/style/style_layer.test.js | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/unit/style/style_layer.test.js b/test/unit/style/style_layer.test.js index 4e780c5c307..76712707ca8 100644 --- a/test/unit/style/style_layer.test.js +++ b/test/unit/style/style_layer.test.js @@ -305,6 +305,61 @@ test('StyleLayer#setPaintProperty', (t) => { t.end(); }); + t.test('sets null property value', (t) => { + const layer = StyleLayer.create({ + "id": "background", + "type": "background" + }); + + layer.setPaintProperty('background-color-transition', null); + + t.deepEqual(layer.getPaintProperty('background-color-transition'), null); + t.end(); + }); + + test('StyleLayer#getPaintValueStopZoomLevels', (t) => { + t.test('get undefined paint value stop zoom levels', (t) => { + const layer = StyleLayer.create({ + "id": "background", + "type": "fill", + "paint.blue": { + "fill-color": "#8ccbf7", + "fill-opacity": 1 + }, + "paint": { + "fill-opacity": 0 + } + }); + + t.deepEqual(layer.getPaintValueStopZoomLevels('background-color'), []); + + t.end(); + }); + + t.end(); + }); + + test('StyleLayer#isPaintValueZoomConstant', (t) => { + t.test('is paint value zoom constant undefined', (t) => { + const layer = StyleLayer.create({ + "id": "background", + "type": "fill", + "paint.blue": { + "fill-color": "#8ccbf7", + "fill-opacity": 1 + }, + "paint": { + "fill-opacity": 0 + } + }); + + t.equal(layer.isPaintValueZoomConstant('background-color'), true); + + t.end(); + }); + + t.end(); + }); t.end(); }); From 3065fc061e4b32a94709340f7f3c5a5f72e1cf8e Mon Sep 17 00:00:00 2001 From: joswinter Date: Wed, 15 Mar 2017 22:26:20 +0100 Subject: [PATCH 6/6] Fixed incorrect identation in migrate test --- test/unit/style-spec/migrate.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/style-spec/migrate.test.js b/test/unit/style-spec/migrate.test.js index fdd72a93bfe..63e94ae0e27 100644 --- a/test/unit/style-spec/migrate.test.js +++ b/test/unit/style-spec/migrate.test.js @@ -14,7 +14,7 @@ const UPDATE = !!process.env.UPDATE; t('does not migrate from version 5', (t) => { t.throws(() => { - migrate({version: 5, layers: []}); + migrate({version: 5, layers: []}); }, new Error('cannot migrate from', 5)); t.end(); });