-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
declass.test.ts
118 lines (104 loc) · 3.19 KB
/
declass.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import {declassStyle} from './declass';
describe('declass', () => {
test('declass a style, one class', () => {
const style = {
layers: [{
id: 'a',
paint: {
'fill-color': {base: 2, stops: [[0, 'red'], [22, 'yellow']]},
'fill-outline-color': 'green'
},
'paint.one': {
'fill-color': {base: 1},
'fill-opacity': 0.5
}
}]
};
const declassed = declassStyle(style, ['one']);
expect(declassed).not.toBe(style);
expect(declassed.layers).not.toBe(style.layers);
expect(declassed.layers[0]).not.toBe(style.layers[0]);
expect(declassed.layers[0].paint).not.toBe(style.layers[0].paint);
expect(declassed).toEqual({
layers: [{
id: 'a',
paint: {
'fill-color': {base: 1},
'fill-outline-color': 'green',
'fill-opacity': 0.5
}
}]
});
});
test('declass a style, missing class ==> noop', () => {
const style = {
layers: [{
id: 'a',
paint: {
'fill-color': 'red',
'fill-outline-color': 'green'
}
}]
};
expect(declassStyle(style, ['one'])).toEqual({
layers: [{
id: 'a',
paint: {
'fill-color': 'red',
'fill-outline-color': 'green'
}
}]
});
});
test('declass a style, multiple classes', () => {
const style = {
layers: [{
id: 'a',
paint: {
'fill-color': 'red',
'fill-outline-color': 'green'
},
'paint.one': {
'fill-color': 'blue',
'fill-opacity': 0.5
},
'paint.two': {
'fill-opacity': 0.75,
'fill-something-else': true
}
}]
};
expect(declassStyle(style, ['one', 'two'])).toEqual({
layers: [{
id: 'a',
paint: {
'fill-color': 'blue',
'fill-outline-color': 'green',
'fill-opacity': 0.75,
'fill-something-else': true
}
}]
});
});
test('declassing a style removes paint.CLASS definitions, whether or not they are applied', () => {
const style = {
layers: [{
id: 'a',
paint: {
'fill-color': 'red',
'fill-outline-color': 'green'
},
'paint.one': {}
}]
};
expect(declassStyle(style, ['one'])).toEqual({
layers: [{
id: 'a',
paint: {
'fill-color': 'red',
'fill-outline-color': 'green'
}
}]
});
});
});