@panoramax/web-viewer 3.2.3-develop-dfee2adc → 3.2.3-develop-357c83ca
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/CHANGELOG.md +2 -1
- package/build/index.js +262 -262
- package/build/index.js.map +1 -1
- package/config/jest/mocks.js +10 -0
- package/docs/reference/components/core/Basic.md +17 -2
- package/docs/reference/components/core/CoverageMap.md +17 -2
- package/docs/reference/components/core/Editor.md +17 -2
- package/docs/reference/components/core/PhotoViewer.md +17 -2
- package/docs/reference/components/core/Viewer.md +17 -2
- package/docs/reference/components/ui/Map.md +25 -1
- package/docs/reference/components/ui/MapMore.md +23 -0
- package/docs/reference/components/ui/Photo.md +9 -1
- package/docs/reference/utils/API.md +23 -0
- package/package.json +2 -2
- package/src/components/core/Basic.js +17 -15
- package/src/components/core/Viewer.js +2 -2
- package/src/components/ui/Loader.js +17 -2
- package/src/components/ui/Map.js +24 -1
- package/src/components/ui/Photo.js +9 -0
- package/src/utils/API.js +30 -3
- package/tests/components/core/Basic.test.js +1 -10
- package/tests/components/ui/Map.test.js +54 -0
- package/tests/utils/API.test.js +82 -69
- package/tests/utils/__snapshots__/API.test.js.snap +10 -0
|
@@ -103,7 +103,7 @@ describe("addEventListener", () => {
|
|
|
103
103
|
expect(listener).toHaveBeenCalledTimes(1);
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
it("should wait for
|
|
106
|
+
it("should wait for sub-component to be available", () => {
|
|
107
107
|
const listener = jest.fn();
|
|
108
108
|
global.setTimeout = jest.fn();
|
|
109
109
|
basic.getSubComponentsNames = () => ["loader", "api", "map"];
|
|
@@ -112,15 +112,6 @@ describe("addEventListener", () => {
|
|
|
112
112
|
expect(global.setTimeout).toHaveBeenCalled();
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
it("should add event listener with once option for map", () => {
|
|
116
|
-
const listener = jest.fn();
|
|
117
|
-
basic.getSubComponentsNames = () => ["loader", "api", "map"];
|
|
118
|
-
basic.map = { on: jest.fn(), once: jest.fn() };
|
|
119
|
-
basic.addEventListener("map:move", listener, { once: true });
|
|
120
|
-
expect(basic.map.on).toHaveBeenCalledTimes(0);
|
|
121
|
-
expect(basic.map.once).toHaveBeenCalledWith("move", listener);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
115
|
it("adds listener to basic if no sub-component matches prefix", () => {
|
|
125
116
|
const listener = jest.fn();
|
|
126
117
|
basic.addEventListener("unknown:event", listener);
|
|
@@ -20,6 +20,20 @@ const createParent = () => ({
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
|
|
23
|
+
describe("_postLoad", () => {
|
|
24
|
+
it("send ready event", async () => {
|
|
25
|
+
const p = createParent();
|
|
26
|
+
const c = document.createElement("div");
|
|
27
|
+
const m = new Map(p, c);
|
|
28
|
+
const listener = jest.fn();
|
|
29
|
+
m.addEventListener("ready", listener, { once: true });
|
|
30
|
+
|
|
31
|
+
await m._postLoad();
|
|
32
|
+
|
|
33
|
+
expect(listener).toHaveBeenCalledTimes(1);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
23
37
|
describe("reloadVectorTiles", () => {
|
|
24
38
|
it("works", () => {
|
|
25
39
|
const p = createParent();
|
|
@@ -188,3 +202,43 @@ describe("reloadLayersStyles", () => {
|
|
|
188
202
|
expect(m.setPaintProperty.mock.calls).toMatchSnapshot();
|
|
189
203
|
});
|
|
190
204
|
});
|
|
205
|
+
|
|
206
|
+
describe("addEventListener", () => {
|
|
207
|
+
let map;
|
|
208
|
+
beforeEach(() => {
|
|
209
|
+
const p = createParent();
|
|
210
|
+
const c = document.createElement("div");
|
|
211
|
+
map = new Map(p, c);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should add an event listener", () => {
|
|
215
|
+
const listener = jest.fn();
|
|
216
|
+
map.addEventListener("ready", listener);
|
|
217
|
+
map.fire("ready");
|
|
218
|
+
expect(listener).toHaveBeenCalled();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("should add an event listener that only fires once", () => {
|
|
222
|
+
const listener = jest.fn();
|
|
223
|
+
map.addEventListener("ready", listener, { once: true });
|
|
224
|
+
map.fire("ready");
|
|
225
|
+
map.fire("ready");
|
|
226
|
+
expect(listener).toHaveBeenCalledTimes(1);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should not add an event listener if options.once is false", () => {
|
|
230
|
+
const listener = jest.fn();
|
|
231
|
+
map.addEventListener("ready", listener, { once: false });
|
|
232
|
+
map.fire("ready");
|
|
233
|
+
map.fire("ready");
|
|
234
|
+
expect(listener).toHaveBeenCalledTimes(2);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("should default options.once to false if not provided", () => {
|
|
238
|
+
const listener = jest.fn();
|
|
239
|
+
map.addEventListener("ready", listener);
|
|
240
|
+
map.fire("ready");
|
|
241
|
+
map.fire("ready");
|
|
242
|
+
expect(listener).toHaveBeenCalledTimes(2);
|
|
243
|
+
});
|
|
244
|
+
});
|
package/tests/utils/API.test.js
CHANGED
|
@@ -34,30 +34,28 @@ const LANDING_NO_PREVIEW = {
|
|
|
34
34
|
|
|
35
35
|
describe("constructor", () => {
|
|
36
36
|
// Mock landing fetch
|
|
37
|
-
global.fetch =
|
|
38
|
-
json: () => Promise
|
|
39
|
-
})
|
|
37
|
+
global.fetch = () => Promise.resolve({
|
|
38
|
+
json: () => new Promise(resolve => setTimeout(() => resolve(VALID_LANDING), 50))
|
|
39
|
+
});
|
|
40
40
|
|
|
41
41
|
it("works with valid endpoint", () => {
|
|
42
|
-
const api = new API(ENDPOINT
|
|
42
|
+
const api = new API(ENDPOINT);
|
|
43
43
|
expect(api._endpoint).toBe(ENDPOINT);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
it("works with relative path", () => {
|
|
47
|
-
const api = new API("/api"
|
|
47
|
+
const api = new API("/api");
|
|
48
48
|
expect(api._endpoint).toBe("http://localhost/api");
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
it("handles tiles overrides", () => {
|
|
52
|
-
|
|
53
|
-
global.fetch = jest.fn(() => Promise.resolve({
|
|
54
|
-
json: () => Promise.resolve(VALID_LANDING)
|
|
55
|
-
}));
|
|
56
|
-
|
|
52
|
+
const listener = jest.fn();
|
|
57
53
|
const api = new API(ENDPOINT, { tiles: "https://my.custom.tiles/" });
|
|
54
|
+
api.addEventListener("ready", listener);
|
|
58
55
|
return api.onceReady().then(() => {
|
|
59
56
|
expect(api._endpoint).toBe(ENDPOINT);
|
|
60
57
|
expect(api._endpoints.tiles).toBe("https://my.custom.tiles/");
|
|
58
|
+
expect(listener).toHaveBeenCalled();
|
|
61
59
|
});
|
|
62
60
|
});
|
|
63
61
|
|
|
@@ -69,8 +67,23 @@ describe("constructor", () => {
|
|
|
69
67
|
expect(() => new API()).toThrow("endpoint parameter is empty or not a valid string");
|
|
70
68
|
});
|
|
71
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
|
+
|
|
72
85
|
it("accepts fetch options", () => {
|
|
73
|
-
const api = new API("/api", {
|
|
86
|
+
const api = new API("/api", { fetch: { bla: "bla" } });
|
|
74
87
|
expect(api._getFetchOptions()).toEqual({ bla: "bla" });
|
|
75
88
|
});
|
|
76
89
|
});
|
|
@@ -793,84 +806,84 @@ describe("sendReport", () => {
|
|
|
793
806
|
});
|
|
794
807
|
|
|
795
808
|
it("throws an error if API is not ready", () => {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
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 = {
|
|
814
827
|
issue: "blur_missing",
|
|
815
828
|
picture_id: "bla1",
|
|
816
829
|
sequence_id: "bla2",
|
|
817
830
|
};
|
|
818
831
|
|
|
819
|
-
|
|
832
|
+
const response = await api.sendReport(data);
|
|
820
833
|
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
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 = {
|
|
838
851
|
issue: "blur_missing",
|
|
839
852
|
picture_id: "bla1",
|
|
840
853
|
sequence_id: "bla2",
|
|
841
854
|
};
|
|
842
855
|
|
|
843
|
-
|
|
856
|
+
await expect(api.sendReport(data)).rejects.toEqual("Error occurred");
|
|
844
857
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
858
|
+
expect(fetch).toHaveBeenCalledWith(ENDPOINT+"/reports", {
|
|
859
|
+
method: "POST",
|
|
860
|
+
body: JSON.stringify(data),
|
|
861
|
+
headers: { "Content-Type": "application/json" }
|
|
862
|
+
});
|
|
863
|
+
});
|
|
851
864
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
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);
|
|
859
872
|
|
|
860
|
-
|
|
873
|
+
const data = {
|
|
861
874
|
issue: "blur_missing",
|
|
862
875
|
picture_id: "bla1",
|
|
863
876
|
sequence_id: "bla2",
|
|
864
877
|
};
|
|
865
878
|
|
|
866
|
-
|
|
879
|
+
await expect(api.sendReport(data)).rejects.toEqual("Some error text");
|
|
867
880
|
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
881
|
+
expect(fetch).toHaveBeenCalledWith(ENDPOINT+"/reports", {
|
|
882
|
+
method: "POST",
|
|
883
|
+
body: JSON.stringify(data),
|
|
884
|
+
headers: { "Content-Type": "application/json" }
|
|
885
|
+
});
|
|
886
|
+
});
|
|
874
887
|
});
|
|
875
888
|
|
|
876
889
|
describe("isValidHttpUrl", () => {
|
|
@@ -135,3 +135,13 @@ No direct access to pictures metadata.
|
|
|
135
135
|
API doesn't offer a 'data' (application/json) endpoint in its links
|
|
136
136
|
No way for viewer to access sequences."
|
|
137
137
|
`;
|
|
138
|
+
|
|
139
|
+
exports[`constructor fails on fetch failure 1`] = `
|
|
140
|
+
Array [
|
|
141
|
+
Array [
|
|
142
|
+
CustomEvent {
|
|
143
|
+
"isTrusted": false,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
]
|
|
147
|
+
`;
|