@panoramax/web-viewer 3.2.3-develop-3ea5b063 → 3.2.3-develop-04898f19

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/build/index.js +2 -2
  3. package/build/index.js.map +1 -1
  4. package/config/jest/mocks.js +21 -2
  5. package/docs/reference/components/core/Basic.md +28 -0
  6. package/docs/reference/components/core/CoverageMap.md +28 -0
  7. package/docs/reference/components/core/Editor.md +28 -0
  8. package/docs/reference/components/core/PhotoViewer.md +29 -0
  9. package/docs/reference/components/core/Viewer.md +28 -0
  10. package/docs/tutorials/migrate_v4.md +14 -1
  11. package/docs/tutorials/synced_coverage.md +1 -0
  12. package/package.json +1 -1
  13. package/scripts/doc.js +3 -1
  14. package/src/components/core/Basic.js +55 -0
  15. package/src/components/core/CoverageMap.js +6 -0
  16. package/src/components/core/Editor.js +4 -0
  17. package/src/components/core/PhotoViewer.js +22 -1
  18. package/src/components/core/Viewer.js +5 -1
  19. package/src/utils/PhotoAdapter.js +1 -0
  20. package/src/utils/URLHandler.js +1 -5
  21. package/tests/components/core/Basic.test.js +130 -0
  22. package/tests/components/core/BasicMock.js +21 -0
  23. package/tests/components/core/CoverageMap.test.js +20 -0
  24. package/tests/components/core/Editor.test.js +20 -0
  25. package/tests/components/core/PhotoViewer.test.js +57 -0
  26. package/tests/components/core/Viewer.test.js +80 -0
  27. package/tests/components/core/__snapshots__/PhotoViewer.test.js.snap +91 -0
  28. package/tests/components/core/__snapshots__/Viewer.test.js.snap +163 -0
  29. package/tests/components/ui/CopyButton.test.js +1 -1
  30. package/tests/components/ui/Loader.test.js +1 -0
  31. package/tests/components/ui/Popup.test.js +2 -0
  32. package/tests/components/ui/QualityScore.test.js +1 -0
  33. package/tests/components/ui/SearchBar.test.js +3 -0
  34. package/tests/components/ui/__snapshots__/CopyButton.test.js.snap +3 -4
@@ -0,0 +1,21 @@
1
+ jest.mock("../../../src/components/core/Basic", () => (
2
+ class Basic extends EventTarget {
3
+ constructor() {
4
+ super();
5
+ this.loader = { setAttribute: jest.fn() };
6
+ this.api = {
7
+ getMapStyle: () => ({}),
8
+ _getMapRequestTransform: () => ({}),
9
+ _endpoints: {},
10
+ };
11
+ this._t = { maplibre: {}, psv: {} };
12
+ }
13
+ isWidthSmall() { return false; }
14
+ getSubComponentsNames() {
15
+ return ["loader", "api"];
16
+ }
17
+ onceAPIReady() {
18
+ return Promise.resolve();
19
+ }
20
+ }
21
+ ));
@@ -0,0 +1,20 @@
1
+ import CoverageMap from "../../../src/components/core/CoverageMap";
2
+ import "./BasicMock";
3
+
4
+ let cm;
5
+ global.console = { info: jest.fn(), error: jest.fn(), warn: jest.fn(), log: global.console.log };
6
+
7
+ beforeEach(() => cm = new CoverageMap());
8
+ afterEach(() => jest.clearAllMocks());
9
+
10
+ describe("getClassName", () => {
11
+ it("works", () => {
12
+ expect(cm.getClassName()).toBe("CoverageMap");
13
+ });
14
+ });
15
+
16
+ describe("getSubComponentsNames", () => {
17
+ it("works", () => {
18
+ expect(cm.getSubComponentsNames()).toEqual(["loader", "api", "map"]);
19
+ });
20
+ });
@@ -0,0 +1,20 @@
1
+ import Editor from "../../../src/components/core/Editor";
2
+ import "./BasicMock";
3
+
4
+ let comp;
5
+ global.console = { info: jest.fn(), error: jest.fn(), warn: jest.fn(), log: global.console.log };
6
+
7
+ beforeEach(() => comp = new Editor());
8
+ afterEach(() => jest.clearAllMocks());
9
+
10
+ describe("getClassName", () => {
11
+ it("works", () => {
12
+ expect(comp.getClassName()).toBe("Editor");
13
+ });
14
+ });
15
+
16
+ describe("getSubComponentsNames", () => {
17
+ it("works", () => {
18
+ expect(comp.getSubComponentsNames()).toEqual(["loader", "api", "map", "psv"]);
19
+ });
20
+ });
@@ -0,0 +1,57 @@
1
+ import PhotoViewer from "../../../src/components/core/PhotoViewer";
2
+ import "./BasicMock";
3
+
4
+ let comp;
5
+ global.console = { info: jest.fn(), error: jest.fn(), warn: jest.fn(), log: global.console.log };
6
+
7
+ beforeEach(() => comp = new PhotoViewer());
8
+ afterEach(() => jest.clearAllMocks());
9
+
10
+
11
+ describe("_initWidgets", () => {
12
+ let initParamsMock;
13
+
14
+ beforeEach(() => {
15
+ comp.grid.appendChild = jest.fn();
16
+
17
+ // Mock the return value of getParentPostInit
18
+ initParamsMock = {
19
+ widgets: "true",
20
+ focus: "pic",
21
+ picture: "somePicture",
22
+ };
23
+ comp._createInitParamsHandler();
24
+ comp._initParams.getParentPostInit = jest.fn();
25
+ comp._initParams.getParentPostInit.mockReturnValue(initParamsMock);
26
+ });
27
+
28
+ it("should not add widgets if widgets is false", () => {
29
+ initParamsMock.widgets = "false";
30
+ comp._initWidgets();
31
+ expect(comp.grid.appendChild).not.toHaveBeenCalled();
32
+ });
33
+
34
+ it("should handle widgets if width is not small", () => {
35
+ comp.isWidthSmall = () => false;
36
+ comp._initWidgets();
37
+ expect(comp.grid.appendChild).toMatchSnapshot();
38
+ });
39
+
40
+ it("should handle widgets if width is small", () => {
41
+ comp.isWidthSmall = () => true;
42
+ comp._initWidgets();
43
+ expect(comp.grid.appendChild).toMatchSnapshot();
44
+ });
45
+ });
46
+
47
+ describe("getClassName", () => {
48
+ it("works", () => {
49
+ expect(comp.getClassName()).toBe("PhotoViewer");
50
+ });
51
+ });
52
+
53
+ describe("getSubComponentsNames", () => {
54
+ it("works", () => {
55
+ expect(comp.getSubComponentsNames()).toEqual(["loader", "api", "psv", "grid", "popup", "urlHandler"]);
56
+ });
57
+ });
@@ -0,0 +1,80 @@
1
+ import Viewer from "../../../src/components/core/Viewer";
2
+ import "./BasicMock";
3
+
4
+ jest.mock("../../../src/components/core/PhotoViewer", () => (
5
+ class PhotoViewer extends EventTarget {
6
+ constructor() {
7
+ super();
8
+ this.loader = { setAttribute: jest.fn() };
9
+ this.api = {
10
+ getMapStyle: () => ({}),
11
+ _getMapRequestTransform: () => ({}),
12
+ _endpoints: {},
13
+ };
14
+ this._t = { maplibre: {}, psv: {} };
15
+ this.grid = { appendChild: jest.fn() };
16
+ }
17
+ getAttribute() { return null; }
18
+ isWidthSmall() { return false; }
19
+ getSubComponentsNames() {
20
+ return ["loader", "api", "psv", "grid", "popup", "urlHandler"];
21
+ }
22
+ onceAPIReady() {
23
+ return Promise.resolve();
24
+ }
25
+ }
26
+ ));
27
+
28
+ let comp;
29
+ global.console = { info: jest.fn(), error: jest.fn(), warn: jest.fn(), log: global.console.log };
30
+
31
+ beforeEach(() => comp = new Viewer());
32
+ afterEach(() => jest.clearAllMocks());
33
+
34
+ describe("_initWidgets", () => {
35
+ let initParamsMock;
36
+
37
+ beforeEach(() => {
38
+ comp.grid.appendChild = jest.fn();
39
+
40
+ // Mock the return value of getParentPostInit
41
+ initParamsMock = {
42
+ widgets: "true",
43
+ focus: "pic",
44
+ picture: "somePicture",
45
+ };
46
+ comp._createInitParamsHandler();
47
+ comp._initParams.getParentPostInit = jest.fn();
48
+ comp._initParams.getParentPostInit.mockReturnValue(initParamsMock);
49
+ });
50
+
51
+ it("should not add widgets if widgets is false", () => {
52
+ initParamsMock.widgets = "false";
53
+ comp._initWidgets();
54
+ expect(comp.grid.appendChild).not.toHaveBeenCalled();
55
+ });
56
+
57
+ it("should handle widgets if width is not small", () => {
58
+ comp.isWidthSmall = () => false;
59
+ comp._initWidgets();
60
+ expect(comp.grid.appendChild).toMatchSnapshot();
61
+ });
62
+
63
+ it("should handle widgets if width is small", () => {
64
+ comp.isWidthSmall = () => true;
65
+ comp._initWidgets();
66
+ expect(comp.grid.appendChild).toMatchSnapshot();
67
+ });
68
+ });
69
+
70
+ describe("getClassName", () => {
71
+ it("works", () => {
72
+ expect(comp.getClassName()).toBe("Viewer");
73
+ });
74
+ });
75
+
76
+ describe("getSubComponentsNames", () => {
77
+ it("works", () => {
78
+ expect(comp.getSubComponentsNames()).toEqual(["loader", "api", "psv", "grid", "popup", "urlHandler", "mini", "map"]);
79
+ });
80
+ });
@@ -0,0 +1,91 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`_initWidgets should handle widgets if width is not small 1`] = `
4
+ [MockFunction] {
5
+ "calls": Array [
6
+ Array [
7
+ <pnx-widget-zoom
8
+ class="pnx-print-hidden"
9
+ slot="bottom-right"
10
+ />,
11
+ ],
12
+ Array [
13
+ <pnx-widget-share
14
+ class="pnx-print-hidden"
15
+ slot="bottom-right"
16
+ />,
17
+ ],
18
+ Array [
19
+ <pnx-widget-legend
20
+ focus="pic"
21
+ picture="somePicture"
22
+ slot="top-left"
23
+ />,
24
+ ],
25
+ Array [
26
+ <pnx-widget-player
27
+ class="pnx-only-psv pnx-print-hidden"
28
+ slot="top"
29
+ />,
30
+ ],
31
+ ],
32
+ "results": Array [
33
+ Object {
34
+ "type": "return",
35
+ "value": undefined,
36
+ },
37
+ Object {
38
+ "type": "return",
39
+ "value": undefined,
40
+ },
41
+ Object {
42
+ "type": "return",
43
+ "value": undefined,
44
+ },
45
+ Object {
46
+ "type": "return",
47
+ "value": undefined,
48
+ },
49
+ ],
50
+ }
51
+ `;
52
+
53
+ exports[`_initWidgets should handle widgets if width is small 1`] = `
54
+ [MockFunction] {
55
+ "calls": Array [
56
+ Array [
57
+ <pnx-widget-share
58
+ class="pnx-print-hidden"
59
+ slot="bottom-right"
60
+ />,
61
+ ],
62
+ Array [
63
+ <pnx-widget-legend
64
+ focus="pic"
65
+ picture="somePicture"
66
+ slot="top"
67
+ />,
68
+ ],
69
+ Array [
70
+ <pnx-widget-player
71
+ class="pnx-only-psv pnx-print-hidden"
72
+ slot="top"
73
+ />,
74
+ ],
75
+ ],
76
+ "results": Array [
77
+ Object {
78
+ "type": "return",
79
+ "value": undefined,
80
+ },
81
+ Object {
82
+ "type": "return",
83
+ "value": undefined,
84
+ },
85
+ Object {
86
+ "type": "return",
87
+ "value": undefined,
88
+ },
89
+ ],
90
+ }
91
+ `;
@@ -0,0 +1,163 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`_initWidgets should handle widgets if width is not small 1`] = `
4
+ [MockFunction] {
5
+ "calls": Array [
6
+ Array [
7
+ <pnx-widget-zoom
8
+ class="pnx-print-hidden"
9
+ slot="bottom-right"
10
+ />,
11
+ ],
12
+ Array [
13
+ <pnx-widget-share
14
+ class="pnx-print-hidden"
15
+ slot="bottom-right"
16
+ />,
17
+ ],
18
+ Array [
19
+ <pnx-widget-legend
20
+ focus="pic"
21
+ picture="somePicture"
22
+ slot="top-left"
23
+ />,
24
+ ],
25
+ Array [
26
+ <pnx-widget-player
27
+ class="pnx-only-psv pnx-print-hidden"
28
+ slot="top"
29
+ />,
30
+ ],
31
+ Array [
32
+ <pnx-widget-geosearch
33
+ class="pnx-only-map pnx-print-hidden"
34
+ slot="top-left"
35
+ />,
36
+ ],
37
+ Array [
38
+ <pnx-widget-mapfilters
39
+ class="pnx-only-map pnx-print-hidden"
40
+ slot="top-left"
41
+ user-search="true"
42
+ />,
43
+ ],
44
+ Array [
45
+ <pnx-widget-maplayers
46
+ class="pnx-only-map pnx-print-hidden"
47
+ slot="top-right"
48
+ />,
49
+ ],
50
+ ],
51
+ "results": Array [
52
+ Object {
53
+ "type": "return",
54
+ "value": undefined,
55
+ },
56
+ Object {
57
+ "type": "return",
58
+ "value": undefined,
59
+ },
60
+ Object {
61
+ "type": "return",
62
+ "value": undefined,
63
+ },
64
+ Object {
65
+ "type": "return",
66
+ "value": undefined,
67
+ },
68
+ Object {
69
+ "type": "return",
70
+ "value": undefined,
71
+ },
72
+ Object {
73
+ "type": "return",
74
+ "value": undefined,
75
+ },
76
+ Object {
77
+ "type": "return",
78
+ "value": undefined,
79
+ },
80
+ ],
81
+ }
82
+ `;
83
+
84
+ exports[`_initWidgets should handle widgets if width is small 1`] = `
85
+ [MockFunction] {
86
+ "calls": Array [
87
+ Array [
88
+ <pnx-widget-zoom
89
+ class="pnx-only-map pnx-print-hidden"
90
+ slot="top-left"
91
+ />,
92
+ ],
93
+ Array [
94
+ <pnx-widget-share
95
+ class="pnx-print-hidden"
96
+ slot="bottom-right"
97
+ />,
98
+ ],
99
+ Array [
100
+ <pnx-widget-legend
101
+ focus="pic"
102
+ picture="somePicture"
103
+ slot="top"
104
+ />,
105
+ ],
106
+ Array [
107
+ <pnx-widget-player
108
+ class="pnx-only-psv pnx-print-hidden"
109
+ slot="top"
110
+ />,
111
+ ],
112
+ Array [
113
+ <pnx-widget-geosearch
114
+ class="pnx-only-map pnx-print-hidden"
115
+ slot="top-right"
116
+ />,
117
+ ],
118
+ Array [
119
+ <pnx-widget-mapfilters
120
+ class="pnx-only-map pnx-print-hidden"
121
+ slot="top-right"
122
+ user-search="true"
123
+ />,
124
+ ],
125
+ Array [
126
+ <pnx-widget-maplayers
127
+ class="pnx-only-map pnx-print-hidden"
128
+ slot="top-right"
129
+ />,
130
+ ],
131
+ ],
132
+ "results": Array [
133
+ Object {
134
+ "type": "return",
135
+ "value": undefined,
136
+ },
137
+ Object {
138
+ "type": "return",
139
+ "value": undefined,
140
+ },
141
+ Object {
142
+ "type": "return",
143
+ "value": undefined,
144
+ },
145
+ Object {
146
+ "type": "return",
147
+ "value": undefined,
148
+ },
149
+ Object {
150
+ "type": "return",
151
+ "value": undefined,
152
+ },
153
+ Object {
154
+ "type": "return",
155
+ "value": undefined,
156
+ },
157
+ Object {
158
+ "type": "return",
159
+ "value": undefined,
160
+ },
161
+ ],
162
+ }
163
+ `;
@@ -5,7 +5,7 @@ window.navigator.clipboard = { writeText: jest.fn() };
5
5
  describe("constructor", () => {
6
6
  it("listens to click", () => {
7
7
  const cb = new CopyButton();
8
- expect(cb.addEventListener.mock.calls).toMatchSnapshot();
8
+ expect(cb._handlers).toMatchSnapshot();
9
9
  });
10
10
  });
11
11
 
@@ -44,6 +44,7 @@ describe("dismiss", () => {
44
44
  const p = { dispatchEvent: jest.fn(), _t: { pnx: {} } };
45
45
  const n = jest.fn();
46
46
  const l = new Loader();
47
+ l.addEventListener = jest.fn();
47
48
  l._parent = p;
48
49
  expect(() => l.dismiss(true, "an error", n)).toThrow(new Error("an error"))
49
50
 
@@ -4,6 +4,7 @@ describe("constructor", () => {
4
4
  it("works", () => {
5
5
  document.addEventListener = jest.fn();
6
6
  const p = new Popup();
7
+ p.addEventListener = jest.fn();
7
8
  expect(p.visible).toBe(false);
8
9
 
9
10
  p.connectedCallback();
@@ -15,6 +16,7 @@ describe("constructor", () => {
15
16
  describe("close", () => {
16
17
  it("works", () => {
17
18
  const p = new Popup();
19
+ p.dispatchEvent = jest.fn();
18
20
  p.visible = true;
19
21
  p.close();
20
22
 
@@ -3,6 +3,7 @@ import QualityScore from "../../../src/components/ui/QualityScore";
3
3
  describe("_onInput", () => {
4
4
  it("works", () => {
5
5
  const qs = new QualityScore();
6
+ qs.dispatchEvent = jest.fn();
6
7
  qs.renderRoot.querySelectorAll.mockReturnValueOnce([
7
8
  { value: 5, checked: false },
8
9
  { value: 4, checked: true },
@@ -37,6 +37,7 @@ describe("_onIconClick", () => {
37
37
  describe("_onResultClick", () => {
38
38
  it("works on classic", () => {
39
39
  const sb = new SearchBar();
40
+ sb.dispatchEvent = jest.fn();
40
41
  sb._onResultClick({title: "res1", subtitle: "sub1", data: "coucou"});
41
42
  expect(sb.dispatchEvent.mock.calls).toMatchSnapshot();
42
43
  expect(sb.value).toEqual("res1");
@@ -46,6 +47,7 @@ describe("_onResultClick", () => {
46
47
 
47
48
  it("works on reduced", () => {
48
49
  const sb = new SearchBar();
50
+ sb.dispatchEvent = jest.fn();
49
51
  sb.reduceable = true;
50
52
  sb._onResultClick({title: "res1", subtitle: "sub1", data: "coucou"});
51
53
  expect(sb.dispatchEvent.mock.calls).toMatchSnapshot();
@@ -57,6 +59,7 @@ describe("_onResultClick", () => {
57
59
 
58
60
  it("resets on null value", () => {
59
61
  const sb = new SearchBar();
62
+ sb.dispatchEvent = jest.fn();
60
63
  sb._onResultClick(null);
61
64
  expect(sb.dispatchEvent.mock.calls).toMatchSnapshot();
62
65
  expect(sb.value).toEqual("");
@@ -25,10 +25,9 @@ Array [
25
25
  `;
26
26
 
27
27
  exports[`constructor listens to click 1`] = `
28
- Array [
29
- Array [
30
- "click",
28
+ Object {
29
+ "click": Array [
31
30
  [Function],
32
31
  ],
33
- ]
32
+ }
34
33
  `;