@panoramax/web-viewer 3.2.3 → 4.0.0-develop-9f9cf858
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/.gitlab-ci.yml +13 -6
- package/CHANGELOG.md +56 -1
- package/CODE_OF_CONDUCT.md +1 -1
- package/README.md +1 -1
- package/build/editor.html +10 -1
- package/build/index.css +12 -12
- package/build/index.css.map +1 -1
- package/build/index.html +1 -1
- package/build/index.js +2126 -14
- package/build/index.js.map +1 -1
- package/build/map.html +1 -1
- package/build/photo.html +1 -0
- package/build/static/media/atkinson-hyperlegible-next-latin-400-normal..woff +0 -0
- package/build/static/media/atkinson-hyperlegible-next-latin-400-normal..woff2 +0 -0
- package/build/static/media/atkinson-hyperlegible-next-latin-ext-400-normal..woff +0 -0
- package/build/static/media/atkinson-hyperlegible-next-latin-ext-400-normal..woff2 +0 -0
- package/build/viewer.html +12 -1
- package/build/widgets.html +1 -0
- package/config/jest/mocks.js +201 -0
- package/config/paths.js +2 -0
- package/config/webpack.config.js +52 -0
- package/docs/03_URL_settings.md +14 -16
- package/docs/05_Compatibility.md +59 -76
- package/docs/09_Develop.md +46 -11
- package/docs/90_Releases.md +2 -2
- package/docs/images/class_diagram.drawio +60 -45
- package/docs/images/class_diagram.jpg +0 -0
- package/docs/images/screenshot.jpg +0 -0
- package/docs/index.md +135 -0
- package/docs/reference/components/core/Basic.md +196 -0
- package/docs/reference/components/core/CoverageMap.md +210 -0
- package/docs/reference/components/core/Editor.md +224 -0
- package/docs/reference/components/core/PhotoViewer.md +307 -0
- package/docs/reference/components/core/Viewer.md +350 -0
- package/docs/reference/components/layout/BottomDrawer.md +35 -0
- package/docs/reference/components/layout/CorneredGrid.md +29 -0
- package/docs/reference/components/layout/Mini.md +45 -0
- package/docs/reference/components/layout/Tabs.md +45 -0
- package/docs/reference/components/menus/MapBackground.md +32 -0
- package/docs/reference/components/menus/MapFilters.md +15 -0
- package/docs/reference/components/menus/MapLayers.md +15 -0
- package/docs/reference/components/menus/MapLegend.md +15 -0
- package/docs/reference/components/menus/PictureLegend.md +16 -0
- package/docs/reference/components/menus/PictureMetadata.md +15 -0
- package/docs/reference/components/menus/PlayerOptions.md +15 -0
- package/docs/reference/components/menus/QualityScoreDoc.md +15 -0
- package/docs/reference/components/menus/ReportForm.md +15 -0
- package/docs/reference/components/menus/ShareMenu.md +15 -0
- package/docs/reference/components/ui/Button.md +40 -0
- package/docs/reference/components/ui/ButtonGroup.md +36 -0
- package/docs/reference/components/ui/CopyButton.md +38 -0
- package/docs/reference/components/ui/Grade.md +32 -0
- package/docs/reference/components/ui/LinkButton.md +45 -0
- package/docs/reference/components/ui/ListGroup.md +22 -0
- package/docs/reference/components/ui/Loader.md +56 -0
- package/docs/reference/components/ui/Map.md +239 -0
- package/docs/reference/components/ui/MapMore.md +256 -0
- package/docs/reference/components/ui/Photo.md +385 -0
- package/docs/reference/components/ui/Popup.md +56 -0
- package/docs/reference/components/ui/ProgressBar.md +32 -0
- package/docs/reference/components/ui/QualityScore.md +45 -0
- package/docs/reference/components/ui/SearchBar.md +63 -0
- package/docs/reference/components/ui/TogglableGroup.md +39 -0
- package/docs/reference/components/ui/widgets/GeoSearch.md +32 -0
- package/docs/reference/components/ui/widgets/Legend.md +49 -0
- package/docs/reference/components/ui/widgets/MapFiltersButton.md +33 -0
- package/docs/reference/components/ui/widgets/MapLayersButton.md +15 -0
- package/docs/reference/components/ui/widgets/OSMEditors.md +15 -0
- package/docs/reference/components/ui/widgets/PictureLegendActions.md +32 -0
- package/docs/reference/components/ui/widgets/Player.md +33 -0
- package/docs/reference/components/ui/widgets/Zoom.md +15 -0
- package/docs/reference/utils/API.md +334 -0
- package/docs/reference/utils/InitParameters.md +68 -0
- package/docs/reference/utils/URLHandler.md +107 -0
- package/docs/reference.md +79 -0
- package/docs/shortcuts.md +11 -0
- package/docs/tutorials/aerial_imagery.md +19 -0
- package/docs/tutorials/authentication.md +10 -0
- package/docs/tutorials/custom_widgets.md +59 -0
- package/docs/tutorials/map_style.md +39 -0
- package/docs/tutorials/migrate_v4.md +153 -0
- package/docs/tutorials/synced_coverage.md +43 -0
- package/mkdocs.yml +66 -5
- package/package.json +22 -17
- package/public/editor.html +21 -29
- package/public/index.html +17 -12
- package/public/map.html +19 -18
- package/public/photo.html +55 -0
- package/public/viewer.html +22 -26
- package/public/widgets.html +306 -0
- package/scripts/doc.js +79 -0
- package/src/components/core/Basic.css +48 -0
- package/src/components/core/Basic.js +349 -0
- package/src/components/core/CoverageMap.css +9 -0
- package/src/components/core/CoverageMap.js +139 -0
- package/src/components/core/Editor.css +23 -0
- package/src/components/core/Editor.js +390 -0
- package/src/components/core/PhotoViewer.css +48 -0
- package/src/components/core/PhotoViewer.js +499 -0
- package/src/components/core/Viewer.css +98 -0
- package/src/components/core/Viewer.js +564 -0
- package/src/components/core/index.js +12 -0
- package/src/components/index.js +13 -0
- package/src/components/layout/BottomDrawer.js +257 -0
- package/src/components/layout/CorneredGrid.js +112 -0
- package/src/components/layout/Mini.js +117 -0
- package/src/components/layout/Tabs.js +133 -0
- package/src/components/layout/index.js +9 -0
- package/src/components/menus/MapBackground.js +106 -0
- package/src/components/menus/MapFilters.js +400 -0
- package/src/components/menus/MapLayers.js +143 -0
- package/src/components/menus/MapLegend.js +34 -0
- package/src/components/menus/PictureLegend.js +257 -0
- package/src/components/menus/PictureMetadata.js +317 -0
- package/src/components/menus/PlayerOptions.js +95 -0
- package/src/components/menus/QualityScoreDoc.js +36 -0
- package/src/components/menus/ReportForm.js +133 -0
- package/src/components/menus/Share.js +100 -0
- package/src/components/menus/index.js +15 -0
- package/src/components/styles.js +383 -0
- package/src/components/ui/Button.js +77 -0
- package/src/components/ui/ButtonGroup.css +57 -0
- package/src/components/ui/ButtonGroup.js +68 -0
- package/src/components/ui/CopyButton.js +106 -0
- package/src/components/ui/Grade.js +54 -0
- package/src/components/ui/LinkButton.js +67 -0
- package/src/components/ui/ListGroup.js +66 -0
- package/src/components/ui/Loader.js +203 -0
- package/src/components/{Map.css → ui/Map.css} +5 -17
- package/src/components/{Map.js → ui/Map.js} +148 -156
- package/src/components/ui/MapMore.js +324 -0
- package/src/components/{Photo.css → ui/Photo.css} +6 -6
- package/src/components/{Photo.js → ui/Photo.js} +313 -101
- package/src/components/ui/Popup.js +145 -0
- package/src/components/ui/ProgressBar.js +104 -0
- package/src/components/ui/QualityScore.js +147 -0
- package/src/components/ui/SearchBar.js +367 -0
- package/src/components/ui/TogglableGroup.js +157 -0
- package/src/components/ui/index.js +22 -0
- package/src/components/ui/widgets/GeoSearch.css +21 -0
- package/src/components/ui/widgets/GeoSearch.js +139 -0
- package/src/components/ui/widgets/Legend.js +113 -0
- package/src/components/ui/widgets/MapFiltersButton.js +104 -0
- package/src/components/ui/widgets/MapLayersButton.js +79 -0
- package/src/components/ui/widgets/OSMEditors.js +155 -0
- package/src/components/ui/widgets/PictureLegendActions.js +117 -0
- package/src/components/ui/widgets/Player.css +7 -0
- package/src/components/ui/widgets/Player.js +151 -0
- package/src/components/ui/widgets/Zoom.js +82 -0
- package/src/components/ui/widgets/index.js +13 -0
- package/src/img/loader_base.jpg +0 -0
- package/src/img/panoramax.svg +13 -0
- package/src/img/switch_big.svg +20 -10
- package/src/index.js +7 -9
- package/src/translations/br.json +1 -0
- package/src/translations/da.json +38 -15
- package/src/translations/de.json +5 -3
- package/src/translations/en.json +35 -15
- package/src/translations/eo.json +38 -15
- package/src/translations/es.json +1 -1
- package/src/translations/fr.json +36 -16
- package/src/translations/hu.json +1 -1
- package/src/translations/it.json +39 -16
- package/src/translations/ja.json +182 -1
- package/src/translations/nl.json +106 -6
- package/src/translations/pl.json +1 -1
- package/src/translations/sv.json +182 -0
- package/src/translations/zh_Hant.json +35 -14
- package/src/utils/API.js +109 -49
- package/src/utils/InitParameters.js +388 -0
- package/src/utils/PhotoAdapter.js +1 -0
- package/src/utils/URLHandler.js +362 -0
- package/src/utils/geocoder.js +152 -0
- package/src/utils/{I18n.js → i18n.js} +7 -3
- package/src/utils/index.js +11 -0
- package/src/utils/{Map.js → map.js} +256 -77
- package/src/utils/picture.js +442 -0
- package/src/utils/utils.js +324 -0
- package/src/utils/widgets.js +55 -0
- package/tests/components/core/Basic.test.js +121 -0
- package/tests/components/core/BasicMock.js +25 -0
- package/tests/components/core/CoverageMap.test.js +20 -0
- package/tests/components/core/Editor.test.js +20 -0
- package/tests/components/core/PhotoViewer.test.js +57 -0
- package/tests/components/core/Viewer.test.js +84 -0
- package/tests/components/core/__snapshots__/PhotoViewer.test.js.snap +73 -0
- package/tests/components/core/__snapshots__/Viewer.test.js.snap +145 -0
- package/tests/components/ui/CopyButton.test.js +52 -0
- package/tests/components/ui/Loader.test.js +55 -0
- package/tests/components/{Map.test.js → ui/Map.test.js} +73 -61
- package/tests/components/{Photo.test.js → ui/Photo.test.js} +97 -63
- package/tests/components/ui/Popup.test.js +26 -0
- package/tests/components/ui/QualityScore.test.js +18 -0
- package/tests/components/ui/SearchBar.test.js +110 -0
- package/tests/components/ui/__snapshots__/CopyButton.test.js.snap +33 -0
- package/tests/components/ui/__snapshots__/Loader.test.js.snap +56 -0
- package/tests/components/{__snapshots__ → ui/__snapshots__}/Map.test.js.snap +11 -38
- package/tests/components/{__snapshots__ → ui/__snapshots__}/Photo.test.js.snap +70 -6
- package/tests/components/ui/__snapshots__/Popup.test.js.snap +29 -0
- package/tests/components/ui/__snapshots__/QualityScore.test.js.snap +11 -0
- package/tests/components/ui/__snapshots__/SearchBar.test.js.snap +65 -0
- package/tests/utils/API.test.js +83 -83
- package/tests/utils/InitParameters.test.js +499 -0
- package/tests/utils/URLHandler.test.js +401 -0
- package/tests/utils/__snapshots__/API.test.js.snap +10 -0
- package/tests/utils/__snapshots__/URLHandler.test.js.snap +21 -0
- package/tests/utils/__snapshots__/{Map.test.js.snap → geocoder.test.js.snap} +1 -1
- package/tests/utils/__snapshots__/map.test.js.snap +11 -0
- package/tests/utils/__snapshots__/picture.test.js.snap +327 -0
- package/tests/utils/__snapshots__/widgets.test.js.snap +19 -0
- package/tests/utils/geocoder.test.js +37 -0
- package/tests/utils/{I18n.test.js → i18n.test.js} +8 -8
- package/tests/utils/map.test.js +126 -0
- package/tests/utils/picture.test.js +745 -0
- package/tests/utils/utils.test.js +288 -0
- package/tests/utils/widgets.test.js +31 -0
- package/docs/01_Start.md +0 -149
- package/docs/02_Usage.md +0 -831
- package/docs/04_Advanced_examples.md +0 -216
- package/src/Editor.css +0 -37
- package/src/Editor.js +0 -361
- package/src/StandaloneMap.js +0 -114
- package/src/Viewer.css +0 -203
- package/src/Viewer.js +0 -1246
- package/src/components/CoreView.css +0 -70
- package/src/components/CoreView.js +0 -175
- package/src/components/Loader.css +0 -74
- package/src/components/Loader.js +0 -120
- package/src/img/loader_hd.jpg +0 -0
- package/src/utils/Exif.js +0 -193
- package/src/utils/Utils.js +0 -631
- package/src/utils/Widgets.js +0 -562
- package/src/viewer/URLHash.js +0 -469
- package/src/viewer/Widgets.css +0 -880
- package/src/viewer/Widgets.js +0 -1470
- package/tests/Editor.test.js +0 -126
- package/tests/StandaloneMap.test.js +0 -45
- package/tests/Viewer.test.js +0 -366
- package/tests/__snapshots__/Editor.test.js.snap +0 -298
- package/tests/__snapshots__/StandaloneMap.test.js.snap +0 -30
- package/tests/__snapshots__/Viewer.test.js.snap +0 -195
- package/tests/components/CoreView.test.js +0 -92
- package/tests/components/Loader.test.js +0 -38
- package/tests/components/__snapshots__/Loader.test.js.snap +0 -15
- package/tests/utils/Exif.test.js +0 -124
- package/tests/utils/Map.test.js +0 -113
- package/tests/utils/Utils.test.js +0 -300
- package/tests/utils/Widgets.test.js +0 -107
- package/tests/utils/__snapshots__/Exif.test.js.snap +0 -43
- package/tests/utils/__snapshots__/Utils.test.js.snap +0 -41
- package/tests/utils/__snapshots__/Widgets.test.js.snap +0 -44
- package/tests/viewer/URLHash.test.js +0 -559
- package/tests/viewer/Widgets.test.js +0 -127
- package/tests/viewer/__snapshots__/URLHash.test.js.snap +0 -108
- package/tests/viewer/__snapshots__/Widgets.test.js.snap +0 -403
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`close works 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
Array [
|
|
6
|
+
Event {
|
|
7
|
+
"isTrusted": false,
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
]
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
exports[`constructor works 1`] = `
|
|
14
|
+
Array [
|
|
15
|
+
Array [
|
|
16
|
+
"click",
|
|
17
|
+
[Function],
|
|
18
|
+
],
|
|
19
|
+
]
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
exports[`constructor works 2`] = `
|
|
23
|
+
Array [
|
|
24
|
+
Array [
|
|
25
|
+
"keyup",
|
|
26
|
+
[Function],
|
|
27
|
+
],
|
|
28
|
+
]
|
|
29
|
+
`;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`_onIconClick resets on clear 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
Array [],
|
|
6
|
+
]
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
exports[`_onIconClick resets on error 1`] = `
|
|
10
|
+
Array [
|
|
11
|
+
Array [],
|
|
12
|
+
]
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
exports[`_onResultClick resets on null value 1`] = `
|
|
16
|
+
Array [
|
|
17
|
+
Array [
|
|
18
|
+
CustomEvent {
|
|
19
|
+
"isTrusted": false,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
]
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
exports[`_onResultClick works on classic 1`] = `
|
|
26
|
+
Array [
|
|
27
|
+
Array [
|
|
28
|
+
CustomEvent {
|
|
29
|
+
"isTrusted": false,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
]
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
exports[`_onResultClick works on reduced 1`] = `
|
|
36
|
+
Array [
|
|
37
|
+
Array [
|
|
38
|
+
CustomEvent {
|
|
39
|
+
"isTrusted": false,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
]
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
exports[`_search skips if no searcher fct 1`] = `
|
|
46
|
+
Array [
|
|
47
|
+
Array [
|
|
48
|
+
"No search handler defined",
|
|
49
|
+
],
|
|
50
|
+
]
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
exports[`_search skips if value is empty 1`] = `
|
|
54
|
+
Array [
|
|
55
|
+
Array [],
|
|
56
|
+
]
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
exports[`reset works 1`] = `
|
|
60
|
+
Array [
|
|
61
|
+
Array [
|
|
62
|
+
null,
|
|
63
|
+
],
|
|
64
|
+
]
|
|
65
|
+
`;
|
package/tests/utils/API.test.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import API from "../../src/utils/API";
|
|
2
2
|
|
|
3
|
-
jest.mock("maplibre-gl", () => ({
|
|
4
|
-
addProtocol: jest.fn(),
|
|
5
|
-
}));
|
|
6
3
|
global.AbortSignal = { timeout: jest.fn() };
|
|
4
|
+
global.console = { log: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() };
|
|
7
5
|
|
|
8
6
|
const ENDPOINT = "https://panoramax.ign.fr/api";
|
|
9
7
|
const VALID_LANDING = {
|
|
@@ -36,30 +34,28 @@ const LANDING_NO_PREVIEW = {
|
|
|
36
34
|
|
|
37
35
|
describe("constructor", () => {
|
|
38
36
|
// Mock landing fetch
|
|
39
|
-
global.fetch =
|
|
40
|
-
json: () => Promise
|
|
41
|
-
})
|
|
37
|
+
global.fetch = () => Promise.resolve({
|
|
38
|
+
json: () => new Promise(resolve => setTimeout(() => resolve(VALID_LANDING), 50))
|
|
39
|
+
});
|
|
42
40
|
|
|
43
41
|
it("works with valid endpoint", () => {
|
|
44
|
-
const api = new API(ENDPOINT
|
|
42
|
+
const api = new API(ENDPOINT);
|
|
45
43
|
expect(api._endpoint).toBe(ENDPOINT);
|
|
46
44
|
});
|
|
47
45
|
|
|
48
46
|
it("works with relative path", () => {
|
|
49
|
-
const api = new API("/api"
|
|
47
|
+
const api = new API("/api");
|
|
50
48
|
expect(api._endpoint).toBe("http://localhost/api");
|
|
51
49
|
});
|
|
52
50
|
|
|
53
51
|
it("handles tiles overrides", () => {
|
|
54
|
-
|
|
55
|
-
global.fetch = jest.fn(() => Promise.resolve({
|
|
56
|
-
json: () => Promise.resolve(VALID_LANDING)
|
|
57
|
-
}));
|
|
58
|
-
|
|
52
|
+
const listener = jest.fn();
|
|
59
53
|
const api = new API(ENDPOINT, { tiles: "https://my.custom.tiles/" });
|
|
54
|
+
api.addEventListener("ready", listener);
|
|
60
55
|
return api.onceReady().then(() => {
|
|
61
56
|
expect(api._endpoint).toBe(ENDPOINT);
|
|
62
57
|
expect(api._endpoints.tiles).toBe("https://my.custom.tiles/");
|
|
58
|
+
expect(listener).toHaveBeenCalled();
|
|
63
59
|
});
|
|
64
60
|
});
|
|
65
61
|
|
|
@@ -71,8 +67,23 @@ describe("constructor", () => {
|
|
|
71
67
|
expect(() => new API()).toThrow("endpoint parameter is empty or not a valid string");
|
|
72
68
|
});
|
|
73
69
|
|
|
70
|
+
it("fails on fetch failure", async () => {
|
|
71
|
+
// Mock landing fetch
|
|
72
|
+
global.fetch = () => Promise.resolve({
|
|
73
|
+
json: () => new Promise((resolve, reject) => setTimeout(() => reject(new Error("brok")), 50))
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const listener = jest.fn();
|
|
77
|
+
const api = new API(ENDPOINT);
|
|
78
|
+
api.addEventListener("broken", listener);
|
|
79
|
+
return api.onceReady().catch(e => {
|
|
80
|
+
expect(e).toEqual("Viewer failed to communicate with API");
|
|
81
|
+
expect(listener.mock.calls).toMatchSnapshot();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
74
85
|
it("accepts fetch options", () => {
|
|
75
|
-
const api = new API("/api", {
|
|
86
|
+
const api = new API("/api", { fetch: { bla: "bla" } });
|
|
76
87
|
expect(api._getFetchOptions()).toEqual({ bla: "bla" });
|
|
77
88
|
});
|
|
78
89
|
});
|
|
@@ -96,7 +107,6 @@ describe("onceReady", () => {
|
|
|
96
107
|
it("handles API failures", async () => {
|
|
97
108
|
// Mock landing fetch
|
|
98
109
|
fetch.mockRejectedValueOnce();
|
|
99
|
-
global.console = { error: jest.fn() };
|
|
100
110
|
|
|
101
111
|
const api = new API(ENDPOINT);
|
|
102
112
|
await expect(api.onceReady()).rejects.toBe("Viewer failed to communicate with API");
|
|
@@ -107,8 +117,6 @@ describe("onceReady", () => {
|
|
|
107
117
|
});
|
|
108
118
|
|
|
109
119
|
describe("isReady", () => {
|
|
110
|
-
global.console = { warn: jest.fn(), error: jest.fn() };
|
|
111
|
-
|
|
112
120
|
// Randomly fails for no reason
|
|
113
121
|
it.skip("works if API is ready", async () => {
|
|
114
122
|
// Mock landing fetch
|
|
@@ -136,7 +144,6 @@ describe("isReady", () => {
|
|
|
136
144
|
|
|
137
145
|
describe("_parseLanding", () => {
|
|
138
146
|
it("handles overrides for tiles URL", () => {
|
|
139
|
-
global.console = { warn: jest.fn() };
|
|
140
147
|
const api = new API (ENDPOINT, { skipReadLanding: true });
|
|
141
148
|
api._parseLanding(VALID_LANDING, { tiles: "https://my.custom.tiles/" });
|
|
142
149
|
expect(api._endpoints.tiles).toBe("https://my.custom.tiles/");
|
|
@@ -203,7 +210,6 @@ describe("_loadMapStyles", () => {
|
|
|
203
210
|
it("works if no background style set", async() => {
|
|
204
211
|
const api = new API(ENDPOINT, { skipReadLanding: true });
|
|
205
212
|
api._parseLanding(VALID_LANDING);
|
|
206
|
-
global.console = { warn: jest.fn(), log: jest.fn(), error: jest.fn() };
|
|
207
213
|
await api._loadMapStyles();
|
|
208
214
|
expect(api.mapStyle).toMatchSnapshot();
|
|
209
215
|
});
|
|
@@ -211,7 +217,6 @@ describe("_loadMapStyles", () => {
|
|
|
211
217
|
it("loads background style from string", async () => {
|
|
212
218
|
const api = new API(ENDPOINT, { skipReadLanding: true });
|
|
213
219
|
api._parseLanding(LANDING_NO_PREVIEW);
|
|
214
|
-
global.console = { warn: jest.fn(), log: jest.fn(), error: jest.fn() };
|
|
215
220
|
global.fetch = () => Promise.resolve({ json: () => ({
|
|
216
221
|
name: "Provider",
|
|
217
222
|
sources: { provider: {} },
|
|
@@ -224,7 +229,6 @@ describe("_loadMapStyles", () => {
|
|
|
224
229
|
it("loads background style from json", async () => {
|
|
225
230
|
const api = new API(ENDPOINT, { skipReadLanding: true });
|
|
226
231
|
api._parseLanding(LANDING_NO_PREVIEW);
|
|
227
|
-
global.console = { warn: jest.fn(), log: jest.fn(), error: jest.fn() };
|
|
228
232
|
await api._loadMapStyles({
|
|
229
233
|
name: "Provider",
|
|
230
234
|
sources: { provider: {} },
|
|
@@ -236,7 +240,6 @@ describe("_loadMapStyles", () => {
|
|
|
236
240
|
it("handles default user", async () => {
|
|
237
241
|
const api = new API(ENDPOINT, { skipReadLanding: true });
|
|
238
242
|
api._parseLanding(VALID_LANDING);
|
|
239
|
-
global.console = { warn: jest.fn(), log: jest.fn(), error: jest.fn() };
|
|
240
243
|
await api._loadMapStyles(undefined, ["geovisio"]);
|
|
241
244
|
expect(api.mapStyle).toMatchSnapshot();
|
|
242
245
|
});
|
|
@@ -260,7 +263,6 @@ describe("_loadMapStyles", () => {
|
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
});
|
|
263
|
-
global.console = { warn: jest.fn(), log: jest.fn(), error: jest.fn() };
|
|
264
266
|
global.fetch = (url) => {
|
|
265
267
|
if(url.includes("/users") && url.includes("style.json")) {
|
|
266
268
|
let user = null;
|
|
@@ -415,7 +417,6 @@ describe("getMapStyle", () => {
|
|
|
415
417
|
it("fallbacks to /map route if any", async () => {
|
|
416
418
|
const api = new API(ENDPOINT, { skipReadLanding: true });
|
|
417
419
|
api._parseLanding(LANDING_NO_PREVIEW);
|
|
418
|
-
global.console = { warn: jest.fn(), log: jest.fn(), error: jest.fn() };
|
|
419
420
|
global.fetch = jest.fn(() => Promise.resolve());
|
|
420
421
|
const res = await api.getMapStyle();
|
|
421
422
|
expect(res).toStrictEqual({
|
|
@@ -434,7 +435,6 @@ describe("getMapStyle", () => {
|
|
|
434
435
|
it("fails if no fallback /map route", async () => {
|
|
435
436
|
const api = new API(ENDPOINT, { skipReadLanding: true });
|
|
436
437
|
api._parseLanding(LANDING_NO_PREVIEW);
|
|
437
|
-
global.console = { warn: jest.fn(), log: jest.fn(), error: jest.fn() };
|
|
438
438
|
global.fetch = jest.fn(() => Promise.reject());
|
|
439
439
|
await expect(async () => await api.getMapStyle()).rejects.toEqual(new Error("API doesn't offer a vector tiles endpoint"));
|
|
440
440
|
});
|
|
@@ -806,84 +806,84 @@ describe("sendReport", () => {
|
|
|
806
806
|
});
|
|
807
807
|
|
|
808
808
|
it("throws an error if API is not ready", () => {
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
809
|
+
api.isReady = () => false;
|
|
810
|
+
expect(() => api.sendReport({})).toThrow("API is not ready to use");
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
it("throws an error if report endpoint is not available", () => {
|
|
814
|
+
api._endpoints.report = null;
|
|
815
|
+
expect(() => api.sendReport({})).toThrow("Report sending is not available");
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
it("sends a report successfully", async () => {
|
|
819
|
+
// Mock fetch response
|
|
820
|
+
const mockResponse = {
|
|
821
|
+
status: 200,
|
|
822
|
+
json: jest.fn().mockResolvedValue({ id: "bla" })
|
|
823
|
+
};
|
|
824
|
+
global.fetch = jest.fn().mockResolvedValue(mockResponse);
|
|
825
|
+
|
|
826
|
+
const data = {
|
|
827
827
|
issue: "blur_missing",
|
|
828
828
|
picture_id: "bla1",
|
|
829
829
|
sequence_id: "bla2",
|
|
830
830
|
};
|
|
831
831
|
|
|
832
|
-
|
|
832
|
+
const response = await api.sendReport(data);
|
|
833
833
|
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
834
|
+
expect(fetch).toHaveBeenCalledWith(ENDPOINT+"/reports", {
|
|
835
|
+
method: "POST",
|
|
836
|
+
body: JSON.stringify(data),
|
|
837
|
+
headers: { "Content-Type": "application/json" }
|
|
838
|
+
});
|
|
839
|
+
expect(response).toEqual({ id: "bla" });
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
it("handles API errors and rejects with message", async () => {
|
|
843
|
+
// Mock fetch response with an error
|
|
844
|
+
const mockResponse = {
|
|
845
|
+
status: 400,
|
|
846
|
+
text: jest.fn().mockResolvedValue(JSON.stringify({ message: "Error occurred" }))
|
|
847
|
+
};
|
|
848
|
+
global.fetch = jest.fn().mockResolvedValue(mockResponse);
|
|
849
|
+
|
|
850
|
+
const data = {
|
|
851
851
|
issue: "blur_missing",
|
|
852
852
|
picture_id: "bla1",
|
|
853
853
|
sequence_id: "bla2",
|
|
854
854
|
};
|
|
855
855
|
|
|
856
|
-
|
|
856
|
+
await expect(api.sendReport(data)).rejects.toEqual("Error occurred");
|
|
857
857
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
858
|
+
expect(fetch).toHaveBeenCalledWith(ENDPOINT+"/reports", {
|
|
859
|
+
method: "POST",
|
|
860
|
+
body: JSON.stringify(data),
|
|
861
|
+
headers: { "Content-Type": "application/json" }
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
864
|
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
865
|
+
it("handles API errors and rejects with text if no message in JSON", async () => {
|
|
866
|
+
// Mock fetch response with an error and no "message" key
|
|
867
|
+
const mockResponse = {
|
|
868
|
+
status: 400,
|
|
869
|
+
text: jest.fn().mockResolvedValue("Some error text")
|
|
870
|
+
};
|
|
871
|
+
global.fetch = jest.fn().mockResolvedValue(mockResponse);
|
|
872
872
|
|
|
873
|
-
|
|
873
|
+
const data = {
|
|
874
874
|
issue: "blur_missing",
|
|
875
875
|
picture_id: "bla1",
|
|
876
876
|
sequence_id: "bla2",
|
|
877
877
|
};
|
|
878
878
|
|
|
879
|
-
|
|
879
|
+
await expect(api.sendReport(data)).rejects.toEqual("Some error text");
|
|
880
880
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
881
|
+
expect(fetch).toHaveBeenCalledWith(ENDPOINT+"/reports", {
|
|
882
|
+
method: "POST",
|
|
883
|
+
body: JSON.stringify(data),
|
|
884
|
+
headers: { "Content-Type": "application/json" }
|
|
885
|
+
});
|
|
886
|
+
});
|
|
887
887
|
});
|
|
888
888
|
|
|
889
889
|
describe("isValidHttpUrl", () => {
|