@geolonia/embed 4.3.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +99 -36
- package/.nvmrc +1 -1
- package/.prettierrc.json +4 -0
- package/.tool-versions +1 -1
- package/README.md +7 -1
- package/dist/e2e/basic.spec.d.ts +8 -0
- package/dist/e2e/helper.d.ts +4 -0
- package/dist/embed +2 -1
- package/dist/embed-chunks/2489af4328c51b71e92d.js +2 -0
- package/dist/embed-chunks/6e05bbf5f391fda5b858.js +1 -0
- package/dist/embed.js +2 -1
- package/dist/embed.js.LICENSE.txt +4 -0
- package/dist/playwright.config.d.ts +9 -0
- package/dist/{embed.d.ts → src/embed.d.ts} +3 -1
- package/dist/{lib → src/lib}/geolonia-map.d.ts +10 -2
- package/dist/{lib → src/lib}/geolonia-marker.d.ts +1 -2
- package/dist/{lib → src/lib}/maplibre-util.d.ts +1 -3
- package/dist/{lib → src/lib}/util.d.ts +6 -3
- package/dist/src/lib/util.test.d.ts +1 -0
- package/dist/src/testability.test.d.ts +1 -0
- package/dist/src/version.d.ts +1 -0
- package/e2e/basic.spec.ts +52 -0
- package/e2e/helper.ts +12 -0
- package/e2e/map.spec.ts +69 -0
- package/eslint.config.js +232 -0
- package/package.json +25 -12
- package/playwright.config.ts +79 -0
- package/src/embed.ts +13 -7
- package/src/lib/CustomAttributionControl.ts +52 -29
- package/src/lib/geolonia-map.ts +144 -38
- package/src/lib/geolonia-marker.ts +9 -6
- package/src/lib/keyring.test.ts +18 -0
- package/src/lib/keyring.ts +11 -13
- package/src/lib/maplibre-util.ts +31 -19
- package/src/lib/parse-atts.test.ts +2 -1
- package/src/lib/render.ts +18 -7
- package/src/lib/simplestyle-vector.ts +42 -13
- package/src/lib/simplestyle.test.ts +80 -69
- package/src/lib/simplestyle.ts +61 -43
- package/src/lib/util.test.ts +108 -21
- package/src/lib/util.ts +115 -32
- package/src/testability.test.ts +46 -0
- package/tsconfig.json +3 -1
- package/webpack.config.js +10 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -14
- package/.prettierrc.js +0 -1
- package/dist/embed-chunks/b52b89229e47dc93c64b.js +0 -2
- package/dist/embed-chunks/d0f087405f7ae2fcf1c1.js +0 -1
- package/dist/version.d.ts +0 -1
- /package/dist/{lib/keyring.test.d.ts → e2e/map.spec.d.ts} +0 -0
- /package/dist/embed-chunks/{b52b89229e47dc93c64b.js.LICENSE.txt → 2489af4328c51b71e92d.js.LICENSE.txt} +0 -0
- /package/dist/{lib → src/lib}/CustomAttributionControl.d.ts +0 -0
- /package/dist/{lib → src/lib}/controls/geolonia-control.d.ts +0 -0
- /package/dist/{lib → src/lib}/keyring.d.ts +0 -0
- /package/dist/{lib/parse-atts.test.d.ts → src/lib/keyring.test.d.ts} +0 -0
- /package/dist/{lib → src/lib}/parse-atts.d.ts +0 -0
- /package/dist/{lib/simplestyle.test.d.ts → src/lib/parse-atts.test.d.ts} +0 -0
- /package/dist/{lib → src/lib}/render.d.ts +0 -0
- /package/dist/{lib → src/lib}/simplestyle-vector.d.ts +0 -0
- /package/dist/{lib → src/lib}/simplestyle.d.ts +0 -0
- /package/dist/{lib/util.test.d.ts → src/lib/simplestyle.test.d.ts} +0 -0
- /package/dist/{types-internal.d.ts → src/types-internal.d.ts} +0 -0
package/src/lib/simplestyle.ts
CHANGED
|
@@ -11,8 +11,8 @@ const backgroundColor = 'rgba(255, 0, 0, 0.4)';
|
|
|
11
11
|
const strokeColor = '#FFFFFF';
|
|
12
12
|
|
|
13
13
|
const template = {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
type: 'FeatureCollection',
|
|
15
|
+
features: [],
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export class SimpleStyle {
|
|
@@ -35,21 +35,24 @@ export class SimpleStyle {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
updateData(geojson) {
|
|
38
|
-
|
|
39
38
|
this.setGeoJSON(geojson);
|
|
40
39
|
|
|
41
40
|
const features = this.geojson.features;
|
|
42
|
-
const polygonandlines = features.filter(
|
|
43
|
-
|
|
41
|
+
const polygonandlines = features.filter(
|
|
42
|
+
(feature) => feature.geometry.type.toLowerCase() !== 'point',
|
|
43
|
+
);
|
|
44
|
+
const points = features.filter(
|
|
45
|
+
(feature) => feature.geometry.type.toLowerCase() === 'point',
|
|
46
|
+
);
|
|
44
47
|
|
|
45
48
|
this.map.getSource(this.options.id).setData({
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
type: 'FeatureCollection',
|
|
50
|
+
features: polygonandlines,
|
|
48
51
|
});
|
|
49
52
|
|
|
50
53
|
this.map.getSource(`${this.options.id}-points`).setData({
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
type: 'FeatureCollection',
|
|
55
|
+
features: points,
|
|
53
56
|
});
|
|
54
57
|
|
|
55
58
|
return this;
|
|
@@ -59,8 +62,12 @@ export class SimpleStyle {
|
|
|
59
62
|
this.map = map;
|
|
60
63
|
|
|
61
64
|
const features = this.geojson.features;
|
|
62
|
-
const polygonandlines = features.filter(
|
|
63
|
-
|
|
65
|
+
const polygonandlines = features.filter(
|
|
66
|
+
(feature) => feature.geometry.type.toLowerCase() !== 'point',
|
|
67
|
+
);
|
|
68
|
+
const points = features.filter(
|
|
69
|
+
(feature) => feature.geometry.type.toLowerCase() === 'point',
|
|
70
|
+
);
|
|
64
71
|
|
|
65
72
|
this.map.addSource(this.options.id, {
|
|
66
73
|
type: 'geojson',
|
|
@@ -91,7 +98,11 @@ export class SimpleStyle {
|
|
|
91
98
|
filter: ['==', '$type', 'Polygon'],
|
|
92
99
|
paint: {
|
|
93
100
|
'text-color': ['string', ['get', 'text-color'], textColor],
|
|
94
|
-
'text-halo-color': [
|
|
101
|
+
'text-halo-color': [
|
|
102
|
+
'string',
|
|
103
|
+
['get', 'text-halo-color'],
|
|
104
|
+
textHaloColor,
|
|
105
|
+
],
|
|
95
106
|
'text-halo-width': 1,
|
|
96
107
|
},
|
|
97
108
|
layout: {
|
|
@@ -110,7 +121,11 @@ export class SimpleStyle {
|
|
|
110
121
|
filter: ['==', '$type', 'LineString'],
|
|
111
122
|
paint: {
|
|
112
123
|
'text-color': ['string', ['get', 'text-color'], textColor],
|
|
113
|
-
'text-halo-color': [
|
|
124
|
+
'text-halo-color': [
|
|
125
|
+
'string',
|
|
126
|
+
['get', 'text-halo-color'],
|
|
127
|
+
textHaloColor,
|
|
128
|
+
],
|
|
114
129
|
'text-halo-width': 1,
|
|
115
130
|
},
|
|
116
131
|
layout: {
|
|
@@ -130,7 +145,6 @@ export class SimpleStyle {
|
|
|
130
145
|
}
|
|
131
146
|
|
|
132
147
|
fitBounds(options = {}) {
|
|
133
|
-
|
|
134
148
|
this.callFitBounds = true;
|
|
135
149
|
|
|
136
150
|
const _options = {
|
|
@@ -203,8 +217,10 @@ export class SimpleStyle {
|
|
|
203
217
|
paint: {
|
|
204
218
|
'circle-radius': [
|
|
205
219
|
'case',
|
|
206
|
-
['==', 'small', ['get', 'marker-size']],
|
|
207
|
-
|
|
220
|
+
['==', 'small', ['get', 'marker-size']],
|
|
221
|
+
7,
|
|
222
|
+
['==', 'large', ['get', 'marker-size']],
|
|
223
|
+
13,
|
|
208
224
|
9,
|
|
209
225
|
],
|
|
210
226
|
'circle-color': ['string', ['get', 'marker-color'], backgroundColor],
|
|
@@ -222,7 +238,11 @@ export class SimpleStyle {
|
|
|
222
238
|
filter: ['!', ['has', 'point_count']],
|
|
223
239
|
paint: {
|
|
224
240
|
'text-color': ['string', ['get', 'text-color'], textColor],
|
|
225
|
-
'text-halo-color': [
|
|
241
|
+
'text-halo-color': [
|
|
242
|
+
'string',
|
|
243
|
+
['get', 'text-halo-color'],
|
|
244
|
+
textHaloColor,
|
|
245
|
+
],
|
|
226
246
|
'text-halo-width': 1,
|
|
227
247
|
},
|
|
228
248
|
layout: {
|
|
@@ -236,8 +256,10 @@ export class SimpleStyle {
|
|
|
236
256
|
'text-variable-anchor': ['top', 'bottom', 'left', 'right'],
|
|
237
257
|
'text-radial-offset': [
|
|
238
258
|
'case',
|
|
239
|
-
['==', 'small', ['get', 'marker-size']],
|
|
240
|
-
|
|
259
|
+
['==', 'small', ['get', 'marker-size']],
|
|
260
|
+
1,
|
|
261
|
+
['==', 'large', ['get', 'marker-size']],
|
|
262
|
+
1.6,
|
|
241
263
|
1.2,
|
|
242
264
|
],
|
|
243
265
|
},
|
|
@@ -249,12 +271,18 @@ export class SimpleStyle {
|
|
|
249
271
|
|
|
250
272
|
async setPopup(map, source) {
|
|
251
273
|
map.on('click', source, async (e) => {
|
|
252
|
-
const center = turfCenter(e.features[0]).geometry.coordinates as [
|
|
274
|
+
const center = turfCenter(e.features[0]).geometry.coordinates as [
|
|
275
|
+
number,
|
|
276
|
+
number,
|
|
277
|
+
];
|
|
253
278
|
const description = e.features[0].properties.description;
|
|
254
279
|
|
|
255
280
|
if (description) {
|
|
256
281
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
257
|
-
new maplibregl.Popup()
|
|
282
|
+
new maplibregl.Popup()
|
|
283
|
+
.setLngLat(center)
|
|
284
|
+
.setHTML(sanitizedDescription)
|
|
285
|
+
.addTo(map);
|
|
258
286
|
}
|
|
259
287
|
});
|
|
260
288
|
|
|
@@ -297,17 +325,18 @@ export class SimpleStyle {
|
|
|
297
325
|
},
|
|
298
326
|
});
|
|
299
327
|
|
|
300
|
-
this.map.on('click', `${this.options.id}-clusters`, (e) => {
|
|
301
|
-
const features = this.map.queryRenderedFeatures(e.point, {
|
|
328
|
+
this.map.on('click', `${this.options.id}-clusters`, async (e) => {
|
|
329
|
+
const features = this.map.queryRenderedFeatures(e.point, {
|
|
330
|
+
layers: [`${this.options.id}-clusters`],
|
|
331
|
+
});
|
|
302
332
|
const clusterId = features[0].properties.cluster_id;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
});
|
|
333
|
+
const zoom = await this.map
|
|
334
|
+
.getSource(`${this.options.id}-points`)
|
|
335
|
+
.getClusterExpansionZoom(clusterId);
|
|
336
|
+
|
|
337
|
+
this.map.easeTo({
|
|
338
|
+
center: features[0].geometry.coordinates,
|
|
339
|
+
zoom: zoom,
|
|
311
340
|
});
|
|
312
341
|
});
|
|
313
342
|
|
|
@@ -321,39 +350,28 @@ export class SimpleStyle {
|
|
|
321
350
|
}
|
|
322
351
|
|
|
323
352
|
setGeoJSON(geojson) {
|
|
324
|
-
|
|
325
353
|
if (typeof geojson === 'string' && isURL(geojson)) {
|
|
326
|
-
|
|
327
354
|
this.geojson = template;
|
|
328
355
|
|
|
329
356
|
const fetchGeoJSON = async () => {
|
|
330
|
-
|
|
331
357
|
try {
|
|
332
|
-
|
|
333
358
|
const response = await window.fetch(geojson);
|
|
334
|
-
const data = await response.json();
|
|
359
|
+
const data = response.ok ? await response.json() : {};
|
|
335
360
|
this.geojson = data;
|
|
336
361
|
this.updateData(data);
|
|
337
362
|
|
|
338
363
|
if (this.callFitBounds) {
|
|
339
|
-
|
|
340
364
|
this.fitBounds();
|
|
341
365
|
this.callFitBounds = false;
|
|
342
|
-
|
|
343
366
|
}
|
|
344
|
-
|
|
345
367
|
} catch (error) {
|
|
346
|
-
|
|
347
368
|
console.error('[Geolonia] Failed to load GeoJSON:', error); // eslint-disable-line no-console
|
|
348
369
|
}
|
|
349
|
-
|
|
350
370
|
};
|
|
351
371
|
|
|
352
372
|
this._loadingPromise = fetchGeoJSON();
|
|
353
|
-
|
|
354
373
|
} else {
|
|
355
374
|
this.geojson = geojson;
|
|
356
375
|
}
|
|
357
|
-
|
|
358
376
|
}
|
|
359
377
|
}
|
package/src/lib/util.test.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import { JSDOM } from 'jsdom';
|
|
5
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getContainer,
|
|
5
|
+
getLang,
|
|
6
|
+
getOptions,
|
|
7
|
+
getStyle,
|
|
8
|
+
handleMarkerOptions,
|
|
9
|
+
isDomElement,
|
|
10
|
+
isURL,
|
|
11
|
+
isGeoloniaTilesHost,
|
|
12
|
+
parseControlOption,
|
|
13
|
+
parseSimpleVector,
|
|
14
|
+
sanitizeDescription,
|
|
15
|
+
loadImageCompatibility,
|
|
16
|
+
} from './util';
|
|
6
17
|
|
|
7
18
|
const base = 'https://base.example.com/parent/';
|
|
8
19
|
|
|
@@ -47,12 +58,38 @@ describe('Tests for util.js', () => {
|
|
|
47
58
|
assert.deepEqual(false, isURL('example.com/hello'));
|
|
48
59
|
});
|
|
49
60
|
|
|
61
|
+
describe('isGeoloniaTilesHost', () => {
|
|
62
|
+
it('detects primary tileserver hostname', () => {
|
|
63
|
+
const url =
|
|
64
|
+
'https://tileserver.geolonia.com/v3/tiles.json?key=YOUR-API-KEY';
|
|
65
|
+
assert.strictEqual(isGeoloniaTilesHost(url), true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('detects tiles.geolonia.com subdomains', () => {
|
|
69
|
+
const url = new URL('https://osm.v2.tiles.geolonia.com/tiles.json');
|
|
70
|
+
assert.strictEqual(isGeoloniaTilesHost(url), true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('detects tiles.geolonia.com subdomains', () => {
|
|
74
|
+
const url = new URL('https://osm.v3.tiles.geolonia.com/tiles.json');
|
|
75
|
+
assert.strictEqual(isGeoloniaTilesHost(url), true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('returns false for other hosts or invalid urls', () => {
|
|
79
|
+
assert.strictEqual(isGeoloniaTilesHost('https://example.com/tiles'), false);
|
|
80
|
+
assert.strictEqual(isGeoloniaTilesHost('not-a-url'), false);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
50
84
|
it('should detect the object is DOM correctly', () => {
|
|
51
85
|
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
52
86
|
<div class="test-class"></div>
|
|
53
87
|
</body></html>`).window;
|
|
54
88
|
|
|
55
|
-
assert.deepEqual(
|
|
89
|
+
assert.deepEqual(
|
|
90
|
+
true,
|
|
91
|
+
isDomElement(mocDocument.querySelector('.test-class')),
|
|
92
|
+
);
|
|
56
93
|
assert.deepEqual(false, isDomElement('hello world'));
|
|
57
94
|
assert.deepEqual(false, isDomElement({ hello: 'world' }));
|
|
58
95
|
});
|
|
@@ -62,6 +99,7 @@ describe('Tests for util.js', () => {
|
|
|
62
99
|
<div id="test-element"></div>
|
|
63
100
|
</body></html>`);
|
|
64
101
|
|
|
102
|
+
// @ts-ignore
|
|
65
103
|
global.window = dom.window;
|
|
66
104
|
global.document = dom.window.document;
|
|
67
105
|
|
|
@@ -82,17 +120,22 @@ describe('Tests for util.js', () => {
|
|
|
82
120
|
assert.deepEqual(false, getContainer('#fail-element'));
|
|
83
121
|
assert.deepEqual(false, getContainer({ container: '#fail-element' }));
|
|
84
122
|
assert.deepEqual(false, getContainer('fail-element'));
|
|
85
|
-
assert.deepEqual(false, getContainer({ container: 'fail-element' }));
|
|
123
|
+
assert.deepEqual(false, getContainer({ container: 'fail-element' }));
|
|
124
|
+
});
|
|
86
125
|
|
|
87
126
|
it('should merge legacyoptions into options as expected.', () => {
|
|
88
127
|
const dom = new JSDOM(`<html><body>
|
|
89
128
|
<div id="test-element"></div>
|
|
90
129
|
</body></html>`);
|
|
91
130
|
|
|
131
|
+
// @ts-ignore
|
|
92
132
|
global.window = dom.window;
|
|
93
133
|
global.document = dom.window.document;
|
|
94
134
|
|
|
95
|
-
const options1 = handleMarkerOptions(
|
|
135
|
+
const options1 = handleMarkerOptions(
|
|
136
|
+
document.getElementById('test-element'),
|
|
137
|
+
{ color: '#FF1122' },
|
|
138
|
+
);
|
|
96
139
|
assert.deepEqual(document.getElementById('test-element'), options1.element);
|
|
97
140
|
assert.deepEqual(options1.color, '#FF1122');
|
|
98
141
|
|
|
@@ -133,10 +176,22 @@ describe('Tests for util.js', () => {
|
|
|
133
176
|
key: '1234',
|
|
134
177
|
};
|
|
135
178
|
|
|
136
|
-
assert.deepEqual(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
179
|
+
assert.deepEqual(
|
|
180
|
+
'https://cdn.geolonia.com/style/hello/world/en.json',
|
|
181
|
+
getStyle('hello/world', atts),
|
|
182
|
+
);
|
|
183
|
+
assert.deepEqual(
|
|
184
|
+
'https://example.com/style.json',
|
|
185
|
+
getStyle('https://example.com/style.json', atts),
|
|
186
|
+
);
|
|
187
|
+
assert.deepEqual(
|
|
188
|
+
'https://base.example.com/parent/style.json',
|
|
189
|
+
getStyle('./style.json', atts),
|
|
190
|
+
);
|
|
191
|
+
assert.deepEqual(
|
|
192
|
+
'https://base.example.com/style.json',
|
|
193
|
+
getStyle('/style.json', atts),
|
|
194
|
+
);
|
|
140
195
|
});
|
|
141
196
|
|
|
142
197
|
it('should handle maplibregl options `minZoom` and `maxZoom` well', () => {
|
|
@@ -186,18 +241,12 @@ describe('Tests for util.js', () => {
|
|
|
186
241
|
|
|
187
242
|
it('should parse simple vector value with http.', () => {
|
|
188
243
|
const attributeValue = 'https://example.com/path/to/tile.json';
|
|
189
|
-
assert.strictEqual(
|
|
190
|
-
attributeValue,
|
|
191
|
-
parseSimpleVector(attributeValue),
|
|
192
|
-
);
|
|
244
|
+
assert.strictEqual(attributeValue, parseSimpleVector(attributeValue));
|
|
193
245
|
});
|
|
194
246
|
|
|
195
247
|
it('should parse simple vector value with geolonia schema.', () => {
|
|
196
248
|
const attributeValue = 'geolonia://tiles/username/ct_123';
|
|
197
|
-
assert.strictEqual(
|
|
198
|
-
attributeValue,
|
|
199
|
-
parseSimpleVector(attributeValue),
|
|
200
|
-
);
|
|
249
|
+
assert.strictEqual(attributeValue, parseSimpleVector(attributeValue));
|
|
201
250
|
});
|
|
202
251
|
|
|
203
252
|
it('should parse simple vector value with customtile ID', () => {
|
|
@@ -210,7 +259,8 @@ describe('Tests for util.js', () => {
|
|
|
210
259
|
|
|
211
260
|
describe('Tests for sanitizeDescription', async () => {
|
|
212
261
|
it('should sanitize description', async () => {
|
|
213
|
-
const description =
|
|
262
|
+
const description =
|
|
263
|
+
'<script>alert("hello");</script>ここが集合場所です。13時までに集合してください。';
|
|
214
264
|
assert.strictEqual(
|
|
215
265
|
'ここが集合場所です。13時までに集合してください。',
|
|
216
266
|
await sanitizeDescription(description),
|
|
@@ -219,7 +269,8 @@ describe('Tests for util.js', () => {
|
|
|
219
269
|
|
|
220
270
|
it('should not sanitize img tag, but should sanitize attributes other than "src", "srcset", "alt", "title", "width", "height", "loading"', async () => {
|
|
221
271
|
// Ref. https://www.npmjs.com/package/sanitize-html
|
|
222
|
-
const description =
|
|
272
|
+
const description =
|
|
273
|
+
'<img decoding="auto" src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。';
|
|
223
274
|
assert.strictEqual(
|
|
224
275
|
'<img src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。',
|
|
225
276
|
await sanitizeDescription(description),
|
|
@@ -227,7 +278,8 @@ describe('Tests for util.js', () => {
|
|
|
227
278
|
});
|
|
228
279
|
|
|
229
280
|
it('should not sanitize "class" attribute', async () => {
|
|
230
|
-
const description =
|
|
281
|
+
const description =
|
|
282
|
+
'<span class="red">ここが集合場所です。13時までに集合してください。</span>';
|
|
231
283
|
assert.strictEqual(
|
|
232
284
|
'<span class="red">ここが集合場所です。13時までに集合してください。</span>',
|
|
233
285
|
await sanitizeDescription(description),
|
|
@@ -235,3 +287,38 @@ describe('Tests for util.js', () => {
|
|
|
235
287
|
});
|
|
236
288
|
});
|
|
237
289
|
});
|
|
290
|
+
|
|
291
|
+
describe('loadImageCompatibility', () => {
|
|
292
|
+
it('should call the callback with response data when the promise resolves', (done) => {
|
|
293
|
+
// モックされた成功した promise
|
|
294
|
+
const mockResponse = {
|
|
295
|
+
data: new Image(),
|
|
296
|
+
cacheControl: 'public, max-age=3600',
|
|
297
|
+
expires: '1609459200',
|
|
298
|
+
};
|
|
299
|
+
const promise = Promise.resolve(mockResponse);
|
|
300
|
+
|
|
301
|
+
loadImageCompatibility(promise, (error, data, expiry) => {
|
|
302
|
+
assert.equal(error, null);
|
|
303
|
+
assert.deepEqual(data, mockResponse.data);
|
|
304
|
+
assert.deepEqual(expiry, {
|
|
305
|
+
cacheControl: mockResponse.cacheControl,
|
|
306
|
+
expires: mockResponse.expires,
|
|
307
|
+
});
|
|
308
|
+
done();
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('should call the callback with error when the promise rejects', (done) => {
|
|
313
|
+
// モックされた失敗した promise
|
|
314
|
+
const mockError = new Error('Failed to load image');
|
|
315
|
+
const promise = Promise.reject(mockError);
|
|
316
|
+
|
|
317
|
+
loadImageCompatibility(promise, (error, data, expiry) => {
|
|
318
|
+
assert.deepEqual(error, mockError);
|
|
319
|
+
assert.strictEqual(data, undefined);
|
|
320
|
+
assert.strictEqual(expiry, undefined);
|
|
321
|
+
done();
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
});
|