-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
logo.test.js
133 lines (115 loc) · 4.49 KB
/
logo.test.js
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {test} from '../../../util/test.js';
import {createMap as globalCreateMap} from '../../../util/index.js';
import VectorTileSource from '../../../../src/source/vector_tile_source.js';
function createMap(t, logoPosition, logoRequired, deleteStyle) {
const options = {
style: {
version: 8,
sources: {
'composite': createSource({
minzoom: 1,
maxzoom: 10,
attribution: "Mapbox",
tiles: [
"http://example.com/{z}/{x}/{y}.png"
]
}, logoRequired)
},
layers: []
},
logoPosition: logoPosition || undefined,
deleteStyle: deleteStyle || undefined
};
if (deleteStyle) delete options.style;
return globalCreateMap(t, options);
}
function createSource(options, logoRequired) {
const source = new VectorTileSource('id', options, {send () {}});
source.onAdd({
_requestManager: {
_skuToken: '1234567890123',
canonicalizeTileset: tileJSON => tileJSON.tiles
},
transform: {angle: 0, pitch: 0, showCollisionBoxes: false},
_getMapId: () => 1
});
source.on('error', (e) => {
throw e.error;
});
const logoFlag = "mapbox_logo";
source[logoFlag] = logoRequired === undefined ? true : logoRequired;
return source;
}
test('LogoControl appears in bottom-left by default', (t) => {
const map = createMap(t);
map.on('load', () => {
t.equal(map.getContainer().querySelectorAll(
'.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-logo'
).length, 1);
t.end();
});
});
test('LogoControl appears in the position specified by the position option', (t) => {
const map = createMap(t, 'top-left');
map.on('load', () => {
t.equal(map.getContainer().querySelectorAll(
'.mapboxgl-ctrl-top-left .mapboxgl-ctrl-logo'
).length, 1);
t.end();
});
});
test('LogoControl is displayed when no style is supplied', (t) => {
const map = createMap(t, 'bottom-left', false, true, true);
t.equal(map.getContainer().querySelector('.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl').style.display, 'block');
t.end();
});
test('LogoControl is not displayed when the mapbox_logo property is false', (t) => {
const map = createMap(t, 'top-left', false);
map.on('load', () => {
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left > .mapboxgl-ctrl')[0].style.display, 'none');
t.end();
});
});
test('LogoControl is not added more than once', (t) => {
const map = createMap(t);
const source = createSource({
minzoom: 1,
maxzoom: 10,
attribution: "Mapbox",
tiles: [
"http://example.com/{z}/{x}/{y}.png"
]
});
map.on('load', () => {
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-logo').length, 1, 'first LogoControl');
map.addSource('source2', source);
map.on('sourcedata', (e) => {
if (e.isSourceLoaded && e.sourceId === 'source2' && e.sourceDataType === 'metadata') {
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-logo').length, 1, 'only one LogoControl is added with multiple sources');
t.end();
}
});
});
});
test('LogoControl appears in compact mode if container is less then 250 pixel wide', (t) => {
const map = createMap(t);
const container = map.getContainer();
Object.defineProperty(map.getContainer(), 'getBoundingClientRect', {value: () => ({height: 200, width: 255})});
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 255, configurable: true});
map.resize();
t.equal(container.querySelectorAll('.mapboxgl-ctrl-logo:not(.mapboxgl-compact)').length, 1);
Object.defineProperty(map.getContainer(), 'getBoundingClientRect', {value: () => ({height: 200, width: 245})});
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 245, configurable: true});
map.resize();
t.equal(container.querySelectorAll('.mapboxgl-ctrl-logo.mapboxgl-compact').length, 1);
t.end();
});
test('LogoControl has `rel` nooper and nofollow', (t) => {
const map = createMap(t);
map.on('load', () => {
const container = map.getContainer();
const logo = container.querySelector('.mapboxgl-ctrl-logo');
t.equal(logo.rel, 'noopener nofollow');
t.end();
});
});