Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tested some uncovered parts of the src/style and scr/style-spec module #4431

Merged
merged 6 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/unit/style-spec/composite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
15 changes: 15 additions & 0 deletions test/unit/style-spec/diff.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
32 changes: 32 additions & 0 deletions test/unit/style-spec/function/color_spaces.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
14 changes: 13 additions & 1 deletion test/unit/style-spec/migrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
55 changes: 55 additions & 0 deletions test/unit/style/style_layer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down