Skip to content

Commit bdb34e7

Browse files
joswinterandrewharvey
authored andcommitted
Tested some uncovered parts of the src/style and scr/style-spec module (mapbox#4431)
* Tested setTransition behaviour in diff#diffStyles * Tested incorrect url match behaviour in composite * Tested color_spaces#hcl.{forward,reverse} * Tested migrate function on different input * Tested uncovered behaviour in StyleLayer * Fixed incorrect identation in migrate test
1 parent e221ace commit bdb34e7

File tree

5 files changed

+135
-1
lines changed

5 files changed

+135
-1
lines changed

test/unit/style-spec/composite.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,23 @@ test('does not composite vector + raster', (t) => {
5858
t.deepEqual(Object.keys(result.sources), ["a", "b"]);
5959
t.end();
6060
});
61+
62+
test('incorrect url match', (t) => {
63+
const result = composite({
64+
"version": 7,
65+
"sources": {
66+
"a": {
67+
"type": "vector",
68+
"url": "mapbox://a"
69+
},
70+
"b": {
71+
"type": "vector",
72+
"url": ""
73+
}
74+
},
75+
"layers": []
76+
});
77+
78+
t.deepEqual(Object.keys(result.sources), ["a", "b"]);
79+
t.end();
80+
});

test/unit/style-spec/diff.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,20 @@ t('diff', (t) => {
292292
{ command: 'addLayer', args: [{id: 'b', source: 'foo'}, 'c'] }
293293
], 'changing a source removes and re-adds dependent layers');
294294

295+
t.deepEqual(diffStyles({
296+
sources: { foo: { data: 1 }, bar: {} },
297+
layers: [
298+
{ id: 'a', source: 'bar' }
299+
]
300+
}, {
301+
sources: { foo: { data: 1 }, bar: {} },
302+
layers: [
303+
{ id: 'a', source: 'bar' }
304+
],
305+
transition: 'transition'
306+
}), [
307+
{ command: 'setTransition', args: ['transition'] }
308+
], 'changing transition');
309+
295310
t.end();
296311
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const test = require('mapbox-gl-js-test').test;
4+
const colorSpaces = require('../../../../src/style-spec/function/color_spaces');
5+
6+
test('#hclToRgb zero', (t) => {
7+
const hclColor = [0, 0, 0, null];
8+
const rgbColor = [0, 0, 0, null];
9+
t.deepEqual(colorSpaces.hcl.reverse(hclColor), rgbColor);
10+
t.end();
11+
});
12+
13+
test('#hclToRgb', (t) => {
14+
const hclColor = [20, 20, 20, null];
15+
const rgbColor = [76.04087881379073, 36.681898967046166, 39.08743507357837, null];
16+
t.deepEqual(colorSpaces.hcl.reverse(hclColor), rgbColor);
17+
t.end();
18+
});
19+
20+
test('#rgbToHcl zero', (t) => {
21+
const hclColor = [0, 0, 0, null];
22+
const rgbColor = [0, 0, 0, null];
23+
t.deepEqual(colorSpaces.hcl.forward(rgbColor), hclColor);
24+
t.end();
25+
});
26+
27+
test('#rgbToHcl', (t) => {
28+
const hclColor = [158.19859051364818, 0.0000029334887311101764, 6.318928745123017, null];
29+
const rgbColor = [20, 20, 20, null];
30+
t.deepEqual(colorSpaces.hcl.forward(rgbColor), hclColor);
31+
t.end();
32+
});

test/unit/style-spec/migrate.test.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@ const t = require('mapbox-gl-js-test').test,
1212

1313
const UPDATE = !!process.env.UPDATE;
1414

15-
t('migrates to latest version', (t) => {
15+
t('does not migrate from version 5', (t) => {
16+
t.throws(() => {
17+
migrate({version: 5, layers: []});
18+
}, new Error('cannot migrate from', 5));
19+
t.end();
20+
});
21+
22+
t('migrates to latest version from version 6', (t) => {
23+
t.deepEqual(migrate({version: 6, layers: []}).version, spec.latest.$version);
24+
t.end();
25+
});
26+
27+
t('migrates to latest version from version 7', (t) => {
1628
t.deepEqual(migrate({version: 7, layers: []}).version, spec.latest.$version);
1729
t.end();
1830
});

test/unit/style/style_layer.test.js

+55
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,61 @@ test('StyleLayer#setPaintProperty', (t) => {
305305
t.end();
306306
});
307307

308+
t.test('sets null property value', (t) => {
309+
const layer = StyleLayer.create({
310+
"id": "background",
311+
"type": "background"
312+
});
313+
314+
layer.setPaintProperty('background-color-transition', null);
315+
316+
t.deepEqual(layer.getPaintProperty('background-color-transition'), null);
317+
t.end();
318+
});
319+
320+
test('StyleLayer#getPaintValueStopZoomLevels', (t) => {
321+
t.test('get undefined paint value stop zoom levels', (t) => {
322+
const layer = StyleLayer.create({
323+
"id": "background",
324+
"type": "fill",
325+
"paint.blue": {
326+
"fill-color": "#8ccbf7",
327+
"fill-opacity": 1
328+
},
329+
"paint": {
330+
"fill-opacity": 0
331+
}
332+
});
333+
334+
t.deepEqual(layer.getPaintValueStopZoomLevels('background-color'), []);
335+
336+
t.end();
337+
});
338+
339+
t.end();
340+
});
341+
342+
test('StyleLayer#isPaintValueZoomConstant', (t) => {
343+
t.test('is paint value zoom constant undefined', (t) => {
344+
const layer = StyleLayer.create({
345+
"id": "background",
346+
"type": "fill",
347+
"paint.blue": {
348+
"fill-color": "#8ccbf7",
349+
"fill-opacity": 1
350+
},
351+
"paint": {
352+
"fill-opacity": 0
353+
}
354+
});
355+
356+
t.equal(layer.isPaintValueZoomConstant('background-color'), true);
357+
358+
t.end();
359+
});
360+
361+
t.end();
362+
});
308363

309364
t.end();
310365
});

0 commit comments

Comments
 (0)