@pod-os/elements 0.13.1-9efc307.0 → 0.13.1-cd22eb8.0
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/dist/cjs/elements.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +2 -3
- package/dist/elements/elements.esm.js +1 -1
- package/dist/elements/elements.esm.js.map +1 -1
- package/dist/esm/elements.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/types/components.d.ts +0 -13
- package/package.json +1 -1
- package/dist/cjs/test-component.cjs.entry.js +0 -15
- package/dist/cjs/test-component.cjs.entry.js.map +0 -1
- package/dist/collection/apps/pos-app-document-viewer/pos-app-document-viewer.spec.js +0 -29
- package/dist/collection/apps/pos-app-document-viewer/pos-app-document-viewer.spec.js.map +0 -1
- package/dist/collection/apps/pos-app-image-viewer/pos-app-image-viewer.spec.js +0 -29
- package/dist/collection/apps/pos-app-image-viewer/pos-app-image-viewer.spec.js.map +0 -1
- package/dist/collection/components/broken-file/BrokenFile.spec.js +0 -45
- package/dist/collection/components/broken-file/BrokenFile.spec.js.map +0 -1
- package/dist/collection/components/pos-add-literal-value/test/pos-add-literal-value.spec.js +0 -185
- package/dist/collection/components/pos-add-literal-value/test/pos-add-literal-value.spec.js.map +0 -1
- package/dist/collection/components/pos-add-new-thing/test/pos-add-new-thing.spec.js +0 -59
- package/dist/collection/components/pos-add-new-thing/test/pos-add-new-thing.spec.js.map +0 -1
- package/dist/collection/components/pos-container-contents/pos-container-contents.spec.js +0 -132
- package/dist/collection/components/pos-container-contents/pos-container-contents.spec.js.map +0 -1
- package/dist/collection/components/pos-container-contents/pos-container-item.spec.js +0 -64
- package/dist/collection/components/pos-container-contents/pos-container-item.spec.js.map +0 -1
- package/dist/collection/components/pos-container-contents/selectIconForTypes.spec.js +0 -30
- package/dist/collection/components/pos-container-contents/selectIconForTypes.spec.js.map +0 -1
- package/dist/collection/components/pos-description/pos-description.spec.js +0 -31
- package/dist/collection/components/pos-description/pos-description.spec.js.map +0 -1
- package/dist/collection/components/pos-document/pos-document.spec.js +0 -219
- package/dist/collection/components/pos-document/pos-document.spec.js.map +0 -1
- package/dist/collection/components/pos-error-toast/test/pos-error-toast.spec.js +0 -18
- package/dist/collection/components/pos-error-toast/test/pos-error-toast.spec.js.map +0 -1
- package/dist/collection/components/pos-image/pos-image.integration.spec.js +0 -124
- package/dist/collection/components/pos-image/pos-image.integration.spec.js.map +0 -1
- package/dist/collection/components/pos-image/pos-image.spec.js +0 -219
- package/dist/collection/components/pos-image/pos-image.spec.js.map +0 -1
- package/dist/collection/components/pos-label/pos-label.integration.spec.js +0 -101
- package/dist/collection/components/pos-label/pos-label.integration.spec.js.map +0 -1
- package/dist/collection/components/pos-label/pos-label.spec.js +0 -31
- package/dist/collection/components/pos-label/pos-label.spec.js.map +0 -1
- package/dist/collection/components/pos-literals/pos-literals.spec.js +0 -118
- package/dist/collection/components/pos-literals/pos-literals.spec.js.map +0 -1
- package/dist/collection/components/pos-login/pos-login.integration.spec.js +0 -35
- package/dist/collection/components/pos-login/pos-login.integration.spec.js.map +0 -1
- package/dist/collection/components/pos-login/pos-login.spec.js +0 -46
- package/dist/collection/components/pos-login/pos-login.spec.js.map +0 -1
- package/dist/collection/components/pos-navigation-bar/pos-navigation-bar.spec.js +0 -41
- package/dist/collection/components/pos-navigation-bar/pos-navigation-bar.spec.js.map +0 -1
- package/dist/collection/components/pos-new-thing-form/test/pos-new-thing-form.spec.js +0 -239
- package/dist/collection/components/pos-new-thing-form/test/pos-new-thing-form.spec.js.map +0 -1
- package/dist/collection/components/pos-picture/pos-picture.integration.spec.js +0 -79
- package/dist/collection/components/pos-picture/pos-picture.integration.spec.js.map +0 -1
- package/dist/collection/components/pos-picture/pos-picture.spec.js +0 -49
- package/dist/collection/components/pos-picture/pos-picture.spec.js.map +0 -1
- package/dist/collection/components/pos-relations/pos-relations.spec.js +0 -64
- package/dist/collection/components/pos-relations/pos-relations.spec.js.map +0 -1
- package/dist/collection/components/pos-resource/pos-resource.integration.spec.js +0 -355
- package/dist/collection/components/pos-resource/pos-resource.integration.spec.js.map +0 -1
- package/dist/collection/components/pos-resource/pos-resource.spec.js +0 -237
- package/dist/collection/components/pos-resource/pos-resource.spec.js.map +0 -1
- package/dist/collection/components/pos-reverse-relations/pos-reverse-relations.spec.js +0 -64
- package/dist/collection/components/pos-reverse-relations/pos-reverse-relations.spec.js.map +0 -1
- package/dist/collection/components/pos-rich-link/pos-rich-link.spec.js +0 -37
- package/dist/collection/components/pos-rich-link/pos-rich-link.spec.js.map +0 -1
- package/dist/collection/components/pos-select-term/test/pos-select-term.spec.js +0 -75
- package/dist/collection/components/pos-select-term/test/pos-select-term.spec.js.map +0 -1
- package/dist/collection/components/pos-subjects/pos-subjects.spec.js +0 -58
- package/dist/collection/components/pos-subjects/pos-subjects.spec.js.map +0 -1
- package/dist/collection/components/pos-type-badges/pos-type-badges.spec.js +0 -119
- package/dist/collection/components/pos-type-badges/pos-type-badges.spec.js.map +0 -1
- package/dist/collection/components/pos-type-router/pos-type-router.spec.js +0 -105
- package/dist/collection/components/pos-type-router/pos-type-router.spec.js.map +0 -1
- package/dist/collection/components/pos-type-router/selectAppForTypes.spec.js +0 -85
- package/dist/collection/components/pos-type-router/selectAppForTypes.spec.js.map +0 -1
- package/dist/collection/components/pos-value/pos-value.spec.js +0 -31
- package/dist/collection/components/pos-value/pos-value.spec.js.map +0 -1
- package/dist/collection/test/TestComponent.js +0 -4
- package/dist/collection/test/TestComponent.js.map +0 -1
- package/dist/collection/test/mockPodOS.js +0 -38
- package/dist/collection/test/mockPodOS.js.map +0 -1
- package/dist/collection/test/renderFunctionalComponent.js +0 -9
- package/dist/collection/test/renderFunctionalComponent.js.map +0 -1
- package/dist/components/test-component.d.ts +0 -11
- package/dist/components/test-component.js +0 -9
- package/dist/components/test-component.js.map +0 -1
- package/dist/elements/p-c5bcab34.entry.js +0 -2
- package/dist/elements/p-c5bcab34.entry.js.map +0 -1
- package/dist/esm/test-component.entry.js +0 -11
- package/dist/esm/test-component.entry.js.map +0 -1
- package/dist/types/test/TestComponent.d.ts +0 -2
- package/dist/types/test/mockPodOS.d.ts +0 -13
- package/dist/types/test/renderFunctionalComponent.d.ts +0 -1
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import { newSpecPage } from "@stencil/core/testing";
|
|
2
|
-
import { mockPodOS } from "../../test/mockPodOS";
|
|
3
|
-
import { PosApp } from "../pos-app/pos-app";
|
|
4
|
-
import { PosResource } from "./pos-resource";
|
|
5
|
-
import { PosLabel } from "../pos-label/pos-label";
|
|
6
|
-
import { when } from "jest-when";
|
|
7
|
-
describe('pos-resource with a pos-label child', () => {
|
|
8
|
-
it('renders label for successfully loaded resource', async () => {
|
|
9
|
-
const os = mockPodOS();
|
|
10
|
-
when(os.fetch).calledWith('https://resource.test').mockReturnValue(Promise.resolve());
|
|
11
|
-
when(os.store.get)
|
|
12
|
-
.calledWith('https://resource.test')
|
|
13
|
-
.mockReturnValue({
|
|
14
|
-
label: () => 'Test Resource',
|
|
15
|
-
});
|
|
16
|
-
const page = await newSpecPage({
|
|
17
|
-
components: [PosApp, PosResource, PosLabel],
|
|
18
|
-
html: `<pos-app>
|
|
19
|
-
<pos-resource uri="https://resource.test">
|
|
20
|
-
<pos-label />
|
|
21
|
-
</pos-resource>
|
|
22
|
-
</pos-app>`,
|
|
23
|
-
});
|
|
24
|
-
expect(page.root).toEqualHtml(`
|
|
25
|
-
<pos-app>
|
|
26
|
-
<pos-resource uri="https://resource.test">
|
|
27
|
-
<mock:shadow-root>
|
|
28
|
-
<slot></slot>
|
|
29
|
-
</mock:shadow-root>
|
|
30
|
-
<pos-label>
|
|
31
|
-
<mock:shadow-root>
|
|
32
|
-
Test Resource
|
|
33
|
-
</mock:shadow-root>
|
|
34
|
-
</pos-label>
|
|
35
|
-
</pos-resource>
|
|
36
|
-
</pos-app>
|
|
37
|
-
`);
|
|
38
|
-
});
|
|
39
|
-
it('renders label after successfully loading resource', async () => {
|
|
40
|
-
const loadingPromise = new Promise(resolve => setTimeout(resolve, 1));
|
|
41
|
-
const os = mockPodOS();
|
|
42
|
-
when(os.fetch).calledWith('https://resource.test').mockReturnValue(loadingPromise);
|
|
43
|
-
when(os.store.get)
|
|
44
|
-
.calledWith('https://resource.test')
|
|
45
|
-
.mockReturnValue({
|
|
46
|
-
label: () => 'Test Resource',
|
|
47
|
-
});
|
|
48
|
-
const page = await newSpecPage({
|
|
49
|
-
components: [PosApp, PosResource, PosLabel],
|
|
50
|
-
html: `<pos-app>
|
|
51
|
-
<pos-resource uri="https://resource.test">
|
|
52
|
-
<pos-label />
|
|
53
|
-
</pos-resource>
|
|
54
|
-
</pos-app>`,
|
|
55
|
-
});
|
|
56
|
-
await loadingPromise;
|
|
57
|
-
await page.waitForChanges();
|
|
58
|
-
expect(page.root).toEqualHtml(`
|
|
59
|
-
<pos-app>
|
|
60
|
-
<pos-resource uri="https://resource.test">
|
|
61
|
-
<mock:shadow-root>
|
|
62
|
-
<slot></slot>
|
|
63
|
-
</mock:shadow-root>
|
|
64
|
-
<pos-label>
|
|
65
|
-
<mock:shadow-root>
|
|
66
|
-
Test Resource
|
|
67
|
-
</mock:shadow-root>
|
|
68
|
-
</pos-label>
|
|
69
|
-
</pos-resource>
|
|
70
|
-
</pos-app>
|
|
71
|
-
`);
|
|
72
|
-
});
|
|
73
|
-
it('renders loading indicator, but empty label while loading resource', async () => {
|
|
74
|
-
const loadingPromise = new Promise(resolve => setTimeout(resolve, 1));
|
|
75
|
-
const os = mockPodOS();
|
|
76
|
-
when(os.fetch).calledWith('https://resource.test').mockReturnValue(loadingPromise);
|
|
77
|
-
const page = await newSpecPage({
|
|
78
|
-
components: [PosApp, PosResource, PosLabel],
|
|
79
|
-
html: `<pos-app>
|
|
80
|
-
<pos-resource uri="https://resource.test">
|
|
81
|
-
<pos-label />
|
|
82
|
-
</pos-resource>
|
|
83
|
-
</pos-app>`,
|
|
84
|
-
});
|
|
85
|
-
expect(page.root).toEqualHtml(`
|
|
86
|
-
<pos-app>
|
|
87
|
-
<pos-resource uri="https://resource.test">
|
|
88
|
-
<mock:shadow-root>
|
|
89
|
-
<ion-progress-bar type="indeterminate"></ion-progress-bar>
|
|
90
|
-
</mock:shadow-root>
|
|
91
|
-
<pos-label>
|
|
92
|
-
<mock:shadow-root>
|
|
93
|
-
</mock:shadow-root>
|
|
94
|
-
</pos-label>
|
|
95
|
-
</pos-resource>
|
|
96
|
-
</pos-app>
|
|
97
|
-
`);
|
|
98
|
-
await loadingPromise;
|
|
99
|
-
});
|
|
100
|
-
it('renders error, but no label when resource loading failed', async () => {
|
|
101
|
-
const os = mockPodOS();
|
|
102
|
-
when(os.fetch).calledWith('https://resource.test').mockRejectedValue(new Error('not found'));
|
|
103
|
-
const page = await newSpecPage({
|
|
104
|
-
components: [PosApp, PosResource, PosLabel],
|
|
105
|
-
html: `<pos-app>
|
|
106
|
-
<pos-resource uri="https://resource.test">
|
|
107
|
-
<pos-label />
|
|
108
|
-
</pos-resource>
|
|
109
|
-
</pos-app>`,
|
|
110
|
-
});
|
|
111
|
-
expect(page.root).toEqualHtml(`
|
|
112
|
-
<pos-app>
|
|
113
|
-
<pos-resource uri="https://resource.test">
|
|
114
|
-
<mock:shadow-root>
|
|
115
|
-
<ion-card>
|
|
116
|
-
<ion-card-header>
|
|
117
|
-
<p>
|
|
118
|
-
Sorry, something went wrong
|
|
119
|
-
</p>
|
|
120
|
-
<p>
|
|
121
|
-
Status:
|
|
122
|
-
</p>
|
|
123
|
-
<details>
|
|
124
|
-
not found
|
|
125
|
-
</details>
|
|
126
|
-
</ion-card-header>
|
|
127
|
-
<ion-card-content>
|
|
128
|
-
<p>
|
|
129
|
-
You can try to open the link outside PodOS:
|
|
130
|
-
</p>
|
|
131
|
-
<a href="https://resource.test">
|
|
132
|
-
https://resource.test
|
|
133
|
-
</a>
|
|
134
|
-
</ion-card-content>
|
|
135
|
-
</ion-card>
|
|
136
|
-
</mock:shadow-root>
|
|
137
|
-
<pos-label>
|
|
138
|
-
<mock:shadow-root>
|
|
139
|
-
</mock:shadow-root>
|
|
140
|
-
</pos-label>
|
|
141
|
-
</pos-resource>
|
|
142
|
-
</pos-app>
|
|
143
|
-
`);
|
|
144
|
-
});
|
|
145
|
-
it('renders multiple labels for successfully loaded resource', async () => {
|
|
146
|
-
const os = mockPodOS();
|
|
147
|
-
when(os.fetch).calledWith('https://resource.test').mockReturnValue(Promise.resolve());
|
|
148
|
-
when(os.store.get)
|
|
149
|
-
.calledWith('https://resource.test')
|
|
150
|
-
.mockReturnValue({
|
|
151
|
-
label: () => 'Test Resource',
|
|
152
|
-
});
|
|
153
|
-
const page = await newSpecPage({
|
|
154
|
-
components: [PosApp, PosResource, PosLabel],
|
|
155
|
-
html: `<pos-app>
|
|
156
|
-
<pos-resource uri="https://resource.test">
|
|
157
|
-
<pos-label />
|
|
158
|
-
<pos-label />
|
|
159
|
-
<pos-label />
|
|
160
|
-
</pos-resource>
|
|
161
|
-
</pos-app>`,
|
|
162
|
-
});
|
|
163
|
-
expect(page.root).toEqualHtml(`
|
|
164
|
-
<pos-app>
|
|
165
|
-
<pos-resource uri="https://resource.test">
|
|
166
|
-
<mock:shadow-root>
|
|
167
|
-
<slot></slot>
|
|
168
|
-
</mock:shadow-root>
|
|
169
|
-
<pos-label>
|
|
170
|
-
<mock:shadow-root>
|
|
171
|
-
Test Resource
|
|
172
|
-
</mock:shadow-root>
|
|
173
|
-
<pos-label>
|
|
174
|
-
<mock:shadow-root>
|
|
175
|
-
Test Resource
|
|
176
|
-
</mock:shadow-root>
|
|
177
|
-
<pos-label>
|
|
178
|
-
<mock:shadow-root>
|
|
179
|
-
Test Resource
|
|
180
|
-
</mock:shadow-root>
|
|
181
|
-
</pos-label>
|
|
182
|
-
</pos-label>
|
|
183
|
-
</pos-label>
|
|
184
|
-
</pos-resource>
|
|
185
|
-
</pos-app>
|
|
186
|
-
`);
|
|
187
|
-
});
|
|
188
|
-
it('renders multiple label after successfully loading resource', async () => {
|
|
189
|
-
const loadingPromise = new Promise(resolve => setTimeout(resolve, 1));
|
|
190
|
-
const os = mockPodOS();
|
|
191
|
-
when(os.fetch).calledWith('https://resource.test').mockReturnValue(loadingPromise);
|
|
192
|
-
when(os.store.get)
|
|
193
|
-
.calledWith('https://resource.test')
|
|
194
|
-
.mockReturnValue({
|
|
195
|
-
label: () => 'Test Resource',
|
|
196
|
-
});
|
|
197
|
-
const page = await newSpecPage({
|
|
198
|
-
components: [PosApp, PosResource, PosLabel],
|
|
199
|
-
html: `<pos-app>
|
|
200
|
-
<pos-resource uri="https://resource.test">
|
|
201
|
-
<pos-label />
|
|
202
|
-
<pos-label />
|
|
203
|
-
<pos-label />
|
|
204
|
-
</pos-resource>
|
|
205
|
-
</pos-app>`,
|
|
206
|
-
});
|
|
207
|
-
await loadingPromise;
|
|
208
|
-
await page.waitForChanges();
|
|
209
|
-
expect(page.root).toEqualHtml(`
|
|
210
|
-
<pos-app>
|
|
211
|
-
<pos-resource uri="https://resource.test">
|
|
212
|
-
<mock:shadow-root>
|
|
213
|
-
<slot></slot>
|
|
214
|
-
</mock:shadow-root>
|
|
215
|
-
<pos-label>
|
|
216
|
-
<mock:shadow-root>
|
|
217
|
-
Test Resource
|
|
218
|
-
</mock:shadow-root>
|
|
219
|
-
<pos-label>
|
|
220
|
-
<mock:shadow-root>
|
|
221
|
-
Test Resource
|
|
222
|
-
</mock:shadow-root>
|
|
223
|
-
<pos-label>
|
|
224
|
-
<mock:shadow-root>
|
|
225
|
-
Test Resource
|
|
226
|
-
</mock:shadow-root>
|
|
227
|
-
</pos-label>
|
|
228
|
-
</pos-label>
|
|
229
|
-
</pos-label>
|
|
230
|
-
</pos-resource>
|
|
231
|
-
</pos-app>
|
|
232
|
-
`);
|
|
233
|
-
});
|
|
234
|
-
it('renders label for lazy resource that would fetch to fail', async () => {
|
|
235
|
-
const os = mockPodOS();
|
|
236
|
-
when(os.fetch).calledWith('https://resource.test').mockRejectedValue(new Error('not found'));
|
|
237
|
-
when(os.store.get)
|
|
238
|
-
.calledWith('https://resource.test')
|
|
239
|
-
.mockReturnValue({
|
|
240
|
-
label: () => 'Test Resource',
|
|
241
|
-
});
|
|
242
|
-
const page = await newSpecPage({
|
|
243
|
-
components: [PosApp, PosResource, PosLabel],
|
|
244
|
-
html: `<pos-app>
|
|
245
|
-
<pos-resource lazy uri="https://resource.test">
|
|
246
|
-
<pos-label />
|
|
247
|
-
</pos-resource>
|
|
248
|
-
</pos-app>`,
|
|
249
|
-
});
|
|
250
|
-
expect(page.root).toEqualHtml(`
|
|
251
|
-
<pos-app>
|
|
252
|
-
<pos-resource lazy uri="https://resource.test">
|
|
253
|
-
<mock:shadow-root>
|
|
254
|
-
<slot></slot>
|
|
255
|
-
</mock:shadow-root>
|
|
256
|
-
<pos-label>
|
|
257
|
-
<mock:shadow-root>
|
|
258
|
-
Test Resource
|
|
259
|
-
</mock:shadow-root>
|
|
260
|
-
</pos-label>
|
|
261
|
-
</pos-resource>
|
|
262
|
-
</pos-app>
|
|
263
|
-
`);
|
|
264
|
-
});
|
|
265
|
-
it('renders error for lazy resource fails when fetched', async () => {
|
|
266
|
-
const os = mockPodOS();
|
|
267
|
-
when(os.fetch).calledWith('https://resource.test').mockRejectedValue(new Error('not found'));
|
|
268
|
-
when(os.store.get)
|
|
269
|
-
.calledWith('https://resource.test')
|
|
270
|
-
.mockReturnValueOnce({
|
|
271
|
-
label: () => 'Test Resource',
|
|
272
|
-
});
|
|
273
|
-
const page = await newSpecPage({
|
|
274
|
-
components: [PosApp, PosResource, PosLabel],
|
|
275
|
-
html: `<pos-app>
|
|
276
|
-
<pos-resource lazy uri="https://resource.test">
|
|
277
|
-
<pos-label />
|
|
278
|
-
</pos-resource>
|
|
279
|
-
</pos-app>`,
|
|
280
|
-
});
|
|
281
|
-
await page.root.querySelector('pos-resource').fetch();
|
|
282
|
-
await page.waitForChanges();
|
|
283
|
-
expect(page.root).toEqualHtml(`
|
|
284
|
-
<pos-app>
|
|
285
|
-
<pos-resource lazy uri="https://resource.test">
|
|
286
|
-
<mock:shadow-root>
|
|
287
|
-
<ion-card>
|
|
288
|
-
<ion-card-header>
|
|
289
|
-
<p>
|
|
290
|
-
Sorry, something went wrong
|
|
291
|
-
</p>
|
|
292
|
-
<p>
|
|
293
|
-
Status:
|
|
294
|
-
</p>
|
|
295
|
-
<details>
|
|
296
|
-
not found
|
|
297
|
-
</details>
|
|
298
|
-
</ion-card-header>
|
|
299
|
-
<ion-card-content>
|
|
300
|
-
<p>
|
|
301
|
-
You can try to open the link outside PodOS:
|
|
302
|
-
</p>
|
|
303
|
-
<a href="https://resource.test">
|
|
304
|
-
https://resource.test
|
|
305
|
-
</a>
|
|
306
|
-
</ion-card-content>
|
|
307
|
-
</ion-card>
|
|
308
|
-
</mock:shadow-root>
|
|
309
|
-
<pos-label>
|
|
310
|
-
<mock:shadow-root>
|
|
311
|
-
Test Resource
|
|
312
|
-
</mock:shadow-root>
|
|
313
|
-
</pos-label>
|
|
314
|
-
</pos-resource>
|
|
315
|
-
</pos-app>
|
|
316
|
-
`);
|
|
317
|
-
});
|
|
318
|
-
it('rerenders child after lazy resource was fetched', async () => {
|
|
319
|
-
const os = mockPodOS();
|
|
320
|
-
when(os.fetch).calledWith('https://resource.test').mockResolvedValue(null);
|
|
321
|
-
when(os.store.get)
|
|
322
|
-
.calledWith('https://resource.test')
|
|
323
|
-
.mockReturnValueOnce({
|
|
324
|
-
label: () => 'Test Resource',
|
|
325
|
-
})
|
|
326
|
-
.mockReturnValueOnce({
|
|
327
|
-
label: () => 'Updated Test Resource',
|
|
328
|
-
});
|
|
329
|
-
const page = await newSpecPage({
|
|
330
|
-
components: [PosApp, PosResource, PosLabel],
|
|
331
|
-
html: `<pos-app>
|
|
332
|
-
<pos-resource lazy uri="https://resource.test">
|
|
333
|
-
<pos-label />
|
|
334
|
-
</pos-resource>
|
|
335
|
-
</pos-app>`,
|
|
336
|
-
});
|
|
337
|
-
await page.root.querySelector('pos-resource').fetch();
|
|
338
|
-
await page.waitForChanges();
|
|
339
|
-
expect(page.root).toEqualHtml(`
|
|
340
|
-
<pos-app>
|
|
341
|
-
<pos-resource lazy uri="https://resource.test">
|
|
342
|
-
<mock:shadow-root>
|
|
343
|
-
<slot></slot>
|
|
344
|
-
</mock:shadow-root>
|
|
345
|
-
<pos-label>
|
|
346
|
-
<mock:shadow-root>
|
|
347
|
-
Updated Test Resource
|
|
348
|
-
</mock:shadow-root>
|
|
349
|
-
</pos-label>
|
|
350
|
-
</pos-resource>
|
|
351
|
-
</pos-app>
|
|
352
|
-
`);
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
//# sourceMappingURL=pos-resource.integration.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pos-resource.integration.spec.js","sourceRoot":"","sources":["../../../../src/components/pos-resource/pos-resource.integration.spec.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;EACnD,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;IAC9D,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACtF,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;OACf,UAAU,CAAC,uBAAuB,CAAC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} from '@stencil/core/internal';\nimport { newSpecPage } from '@stencil/core/testing';\nimport { mockPodOS } from '../../test/mockPodOS';\nimport { PosApp } from '../pos-app/pos-app';\nimport { PosResource } from './pos-resource';\nimport { PosLabel } from '../pos-label/pos-label';\nimport { when } from 'jest-when';\n\ndescribe('pos-resource with a pos-label child', () => {\n it('renders label for successfully loaded resource', async () => {\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockReturnValue(Promise.resolve());\n when(os.store.get)\n .calledWith('https://resource.test')\n .mockReturnValue({\n label: () => 'Test Resource',\n });\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource uri=\"https://resource.test\">\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n expect(page.root).toEqualHtml(`\n <pos-app>\n <pos-resource uri=\"https://resource.test\">\n <mock:shadow-root>\n <slot></slot>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n </pos-label>\n </pos-resource>\n </pos-app>\n `);\n });\n\n it('renders label after successfully loading resource', async () => {\n const loadingPromise = new Promise(resolve => setTimeout(resolve, 1));\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockReturnValue(loadingPromise);\n when(os.store.get)\n .calledWith('https://resource.test')\n .mockReturnValue({\n label: () => 'Test Resource',\n });\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource uri=\"https://resource.test\">\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n await loadingPromise;\n await page.waitForChanges();\n expect(page.root).toEqualHtml(`\n <pos-app>\n <pos-resource uri=\"https://resource.test\">\n <mock:shadow-root>\n <slot></slot>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n </pos-label>\n </pos-resource>\n </pos-app>\n `);\n });\n\n it('renders loading indicator, but empty label while loading resource', async () => {\n const loadingPromise = new Promise(resolve => setTimeout(resolve, 1));\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockReturnValue(loadingPromise);\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource uri=\"https://resource.test\">\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n expect(page.root).toEqualHtml(`\n <pos-app>\n <pos-resource uri=\"https://resource.test\">\n <mock:shadow-root>\n <ion-progress-bar type=\"indeterminate\"></ion-progress-bar>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n </mock:shadow-root>\n </pos-label>\n </pos-resource>\n </pos-app>\n `);\n await loadingPromise;\n });\n\n it('renders error, but no label when resource loading failed', async () => {\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockRejectedValue(new Error('not found'));\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource uri=\"https://resource.test\">\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n expect(page.root).toEqualHtml(`\n<pos-app>\n <pos-resource uri=\"https://resource.test\">\n <mock:shadow-root>\n <ion-card>\n <ion-card-header>\n <p>\n Sorry, something went wrong\n </p>\n <p>\n Status:\n </p>\n <details>\n not found\n </details>\n </ion-card-header>\n <ion-card-content>\n <p>\n You can try to open the link outside PodOS:\n </p>\n <a href=\"https://resource.test\">\n https://resource.test\n </a>\n </ion-card-content>\n </ion-card>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n </mock:shadow-root>\n </pos-label>\n </pos-resource>\n</pos-app>\n `);\n });\n\n it('renders multiple labels for successfully loaded resource', async () => {\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockReturnValue(Promise.resolve());\n when(os.store.get)\n .calledWith('https://resource.test')\n .mockReturnValue({\n label: () => 'Test Resource',\n });\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource uri=\"https://resource.test\">\n <pos-label />\n <pos-label />\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n expect(page.root).toEqualHtml(`\n <pos-app>\n <pos-resource uri=\"https://resource.test\">\n <mock:shadow-root>\n <slot></slot>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n </pos-label>\n </pos-label>\n </pos-label>\n </pos-resource>\n </pos-app>\n `);\n });\n\n it('renders multiple label after successfully loading resource', async () => {\n const loadingPromise = new Promise(resolve => setTimeout(resolve, 1));\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockReturnValue(loadingPromise);\n when(os.store.get)\n .calledWith('https://resource.test')\n .mockReturnValue({\n label: () => 'Test Resource',\n });\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource uri=\"https://resource.test\">\n <pos-label />\n <pos-label />\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n await loadingPromise;\n await page.waitForChanges();\n expect(page.root).toEqualHtml(`\n <pos-app>\n <pos-resource uri=\"https://resource.test\">\n <mock:shadow-root>\n <slot></slot>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n </pos-label>\n </pos-label>\n </pos-label>\n </pos-resource>\n </pos-app>\n `);\n });\n\n it('renders label for lazy resource that would fetch to fail', async () => {\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockRejectedValue(new Error('not found'));\n when(os.store.get)\n .calledWith('https://resource.test')\n .mockReturnValue({\n label: () => 'Test Resource',\n });\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource lazy uri=\"https://resource.test\">\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n expect(page.root).toEqualHtml(`\n <pos-app>\n <pos-resource lazy uri=\"https://resource.test\">\n <mock:shadow-root>\n <slot></slot>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n </pos-label>\n </pos-resource>\n </pos-app>\n `);\n });\n\n it('renders error for lazy resource fails when fetched', async () => {\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockRejectedValue(new Error('not found'));\n when(os.store.get)\n .calledWith('https://resource.test')\n .mockReturnValueOnce({\n label: () => 'Test Resource',\n });\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource lazy uri=\"https://resource.test\">\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n await (page.root.querySelector('pos-resource') as AnyHTMLElement).fetch();\n await page.waitForChanges();\n expect(page.root).toEqualHtml(`\n <pos-app>\n <pos-resource lazy uri=\"https://resource.test\">\n <mock:shadow-root>\n <ion-card>\n <ion-card-header>\n <p>\n Sorry, something went wrong\n </p>\n <p>\n Status:\n </p>\n <details>\n not found\n </details>\n </ion-card-header>\n <ion-card-content>\n <p>\n You can try to open the link outside PodOS:\n </p>\n <a href=\"https://resource.test\">\n https://resource.test\n </a>\n </ion-card-content>\n </ion-card>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Test Resource\n </mock:shadow-root>\n </pos-label>\n </pos-resource>\n </pos-app>\n `);\n });\n\n it('rerenders child after lazy resource was fetched', async () => {\n const os = mockPodOS();\n when(os.fetch).calledWith('https://resource.test').mockResolvedValue(null);\n when(os.store.get)\n .calledWith('https://resource.test')\n .mockReturnValueOnce({\n label: () => 'Test Resource',\n })\n .mockReturnValueOnce({\n label: () => 'Updated Test Resource',\n });\n const page = await newSpecPage({\n components: [PosApp, PosResource, PosLabel],\n html: `<pos-app>\n <pos-resource lazy uri=\"https://resource.test\">\n <pos-label />\n </pos-resource>\n </pos-app>`,\n });\n await (page.root.querySelector('pos-resource') as AnyHTMLElement).fetch();\n await page.waitForChanges();\n expect(page.root).toEqualHtml(`\n <pos-app>\n <pos-resource lazy uri=\"https://resource.test\">\n <mock:shadow-root>\n <slot></slot>\n </mock:shadow-root>\n <pos-label>\n <mock:shadow-root>\n Updated Test Resource\n </mock:shadow-root>\n </pos-label>\n </pos-resource>\n </pos-app>\n `);\n });\n});\n"]}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
jest.mock('../../store/session');
|
|
2
|
-
import { newSpecPage } from "@stencil/core/testing";
|
|
3
|
-
import { when } from "jest-when";
|
|
4
|
-
import session from "../../store/session";
|
|
5
|
-
import { mockPodOS } from "../../test/mockPodOS";
|
|
6
|
-
import { PosResource } from "./pos-resource";
|
|
7
|
-
describe('pos-resource', () => {
|
|
8
|
-
it('renders loading indicator initially', async () => {
|
|
9
|
-
const page = await newSpecPage({
|
|
10
|
-
components: [PosResource],
|
|
11
|
-
html: `<pos-resource uri="https://resource.test/" />`,
|
|
12
|
-
});
|
|
13
|
-
expect(page.root).toEqualHtml(`
|
|
14
|
-
<pos-resource uri="https://resource.test/">
|
|
15
|
-
<mock:shadow-root>
|
|
16
|
-
<ion-progress-bar type="indeterminate"></ion-progress-bar>
|
|
17
|
-
</mock:shadow-root>
|
|
18
|
-
</pos-resource>
|
|
19
|
-
`);
|
|
20
|
-
});
|
|
21
|
-
it('renders loading indicator while fetching', async () => {
|
|
22
|
-
const page = await newSpecPage({
|
|
23
|
-
components: [PosResource],
|
|
24
|
-
html: `<pos-resource uri="https://resource.test/" />`,
|
|
25
|
-
});
|
|
26
|
-
const os = mockPodOS();
|
|
27
|
-
when(os.fetch)
|
|
28
|
-
.calledWith('https://resource.test/')
|
|
29
|
-
.mockReturnValue(new Promise(() => null));
|
|
30
|
-
await page.rootInstance.receivePodOs(os);
|
|
31
|
-
await page.waitForChanges();
|
|
32
|
-
expect(page.root).toEqualHtml(`
|
|
33
|
-
<pos-resource uri="https://resource.test/">
|
|
34
|
-
<mock:shadow-root>
|
|
35
|
-
<ion-progress-bar type="indeterminate"></ion-progress-bar>
|
|
36
|
-
</mock:shadow-root>
|
|
37
|
-
</pos-resource>
|
|
38
|
-
`);
|
|
39
|
-
});
|
|
40
|
-
it('renders slot after loading', async () => {
|
|
41
|
-
const page = await newSpecPage({
|
|
42
|
-
components: [PosResource],
|
|
43
|
-
html: `<pos-resource uri="https://resource.test/" />`,
|
|
44
|
-
});
|
|
45
|
-
const os = mockPodOS();
|
|
46
|
-
when(os.fetch).calledWith('https://resource.test/').mockResolvedValue(null);
|
|
47
|
-
await page.rootInstance.receivePodOs(os);
|
|
48
|
-
await page.waitForChanges();
|
|
49
|
-
expect(page.root).toEqualHtml(`
|
|
50
|
-
<pos-resource uri="https://resource.test/">
|
|
51
|
-
<mock:shadow-root>
|
|
52
|
-
<slot></slot>
|
|
53
|
-
</mock:shadow-root>
|
|
54
|
-
</pos-resource>
|
|
55
|
-
`);
|
|
56
|
-
});
|
|
57
|
-
it('emits event after loading resource', async () => {
|
|
58
|
-
const onResourceLoaded = jest.fn();
|
|
59
|
-
const page = await newSpecPage({
|
|
60
|
-
components: [PosResource],
|
|
61
|
-
html: `<pos-resource uri="https://resource.test/" />`,
|
|
62
|
-
});
|
|
63
|
-
page.root.addEventListener('pod-os:resource-loaded', onResourceLoaded);
|
|
64
|
-
const os = mockPodOS();
|
|
65
|
-
when(os.fetch).calledWith('https://resource.test/').mockResolvedValue(null);
|
|
66
|
-
await page.rootInstance.receivePodOs(os);
|
|
67
|
-
await page.waitForChanges();
|
|
68
|
-
expect(onResourceLoaded).toHaveBeenCalled();
|
|
69
|
-
expect(onResourceLoaded.mock.calls[0][0].detail).toEqual('https://resource.test/');
|
|
70
|
-
});
|
|
71
|
-
it('renders error when fetch failed', async () => {
|
|
72
|
-
const page = await newSpecPage({
|
|
73
|
-
components: [PosResource],
|
|
74
|
-
html: `<pos-resource uri="https://resource.test/" />`,
|
|
75
|
-
});
|
|
76
|
-
const os = mockPodOS();
|
|
77
|
-
when(os.fetch).calledWith('https://resource.test/').mockRejectedValue(new Error('not found'));
|
|
78
|
-
await page.rootInstance.receivePodOs(os);
|
|
79
|
-
await page.waitForChanges();
|
|
80
|
-
const errorDetails = page.root.shadowRoot.querySelector('details');
|
|
81
|
-
expect(errorDetails).toEqualHtml(`<details>not found</details>`);
|
|
82
|
-
});
|
|
83
|
-
it('updates and loads resource when uri changes', async () => {
|
|
84
|
-
const page = await newSpecPage({
|
|
85
|
-
components: [PosResource],
|
|
86
|
-
html: `<pos-resource uri="https://resource.test/" />`,
|
|
87
|
-
});
|
|
88
|
-
const os = mockPodOS();
|
|
89
|
-
when(os.fetch).calledWith('https://resource.test/').mockResolvedValue(null);
|
|
90
|
-
when(os.fetch)
|
|
91
|
-
.calledWith('https://other-resource.test')
|
|
92
|
-
.mockReturnValue(new Promise(() => null));
|
|
93
|
-
await page.rootInstance.receivePodOs(os);
|
|
94
|
-
page.root.setAttribute('uri', 'https://other-resource.test');
|
|
95
|
-
await page.waitForChanges();
|
|
96
|
-
expect(page.root).toEqualHtml(`
|
|
97
|
-
<pos-resource uri="https://other-resource.test">
|
|
98
|
-
<mock:shadow-root>
|
|
99
|
-
<ion-progress-bar type="indeterminate"></ion-progress-bar>
|
|
100
|
-
</mock:shadow-root>
|
|
101
|
-
</pos-resource>
|
|
102
|
-
`);
|
|
103
|
-
});
|
|
104
|
-
it('re-fetches resource when session state changes', async () => {
|
|
105
|
-
let sessionChanged;
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
session.onChange = (prop, callback) => {
|
|
108
|
-
if (prop === 'isLoggedIn') {
|
|
109
|
-
sessionChanged = callback;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
const page = await newSpecPage({
|
|
113
|
-
components: [PosResource],
|
|
114
|
-
html: `<pos-resource uri="https://resource.test/" />`,
|
|
115
|
-
});
|
|
116
|
-
const os = mockPodOS();
|
|
117
|
-
when(os.fetch).calledWith('https://resource.test/').mockResolvedValueOnce(null);
|
|
118
|
-
when(os.fetch)
|
|
119
|
-
.calledWith('https://resource.test/')
|
|
120
|
-
.mockReturnValueOnce(new Promise(() => null));
|
|
121
|
-
await page.rootInstance.receivePodOs(os);
|
|
122
|
-
expect(sessionChanged).toBeDefined();
|
|
123
|
-
sessionChanged();
|
|
124
|
-
await page.waitForChanges();
|
|
125
|
-
expect(page.root).toEqualHtml(`
|
|
126
|
-
<pos-resource uri="https://resource.test/">
|
|
127
|
-
<mock:shadow-root>
|
|
128
|
-
<ion-progress-bar type="indeterminate"></ion-progress-bar>
|
|
129
|
-
</mock:shadow-root>
|
|
130
|
-
</pos-resource>
|
|
131
|
-
`);
|
|
132
|
-
});
|
|
133
|
-
it('removes error message after successful loading', async () => {
|
|
134
|
-
let sessionChanged;
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
session.onChange = (prop, callback) => {
|
|
137
|
-
if (prop === 'isLoggedIn') {
|
|
138
|
-
sessionChanged = callback;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const page = await newSpecPage({
|
|
142
|
-
components: [PosResource],
|
|
143
|
-
html: `<pos-resource uri="https://resource.test/" />`,
|
|
144
|
-
});
|
|
145
|
-
const os = mockPodOS();
|
|
146
|
-
when(os.fetch).calledWith('https://resource.test/').mockRejectedValueOnce(new Error('unauthorized'));
|
|
147
|
-
when(os.fetch).calledWith('https://resource.test/').mockResolvedValueOnce(null);
|
|
148
|
-
await page.rootInstance.receivePodOs(os);
|
|
149
|
-
expect(sessionChanged).toBeDefined();
|
|
150
|
-
sessionChanged();
|
|
151
|
-
await page.waitForChanges();
|
|
152
|
-
expect(page.root).toEqualHtml(`
|
|
153
|
-
<pos-resource uri="https://resource.test/">
|
|
154
|
-
<mock:shadow-root>
|
|
155
|
-
<slot></slot>
|
|
156
|
-
</mock:shadow-root>
|
|
157
|
-
</pos-resource>
|
|
158
|
-
`);
|
|
159
|
-
});
|
|
160
|
-
describe('when lazy', () => {
|
|
161
|
-
let page;
|
|
162
|
-
beforeEach(async () => {
|
|
163
|
-
page = await newSpecPage({
|
|
164
|
-
components: [PosResource],
|
|
165
|
-
html: `<pos-resource lazy uri="https://resource.test/" />`,
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
it('renders loading indicator before PodOS is ready', async () => {
|
|
169
|
-
expect(page.root).toEqualHtml(`
|
|
170
|
-
<pos-resource lazy uri="https://resource.test/">
|
|
171
|
-
<mock:shadow-root>
|
|
172
|
-
<ion-progress-bar type="indeterminate"></ion-progress-bar>
|
|
173
|
-
</mock:shadow-root>
|
|
174
|
-
</pos-resource>
|
|
175
|
-
`);
|
|
176
|
-
});
|
|
177
|
-
it('renders slot without fetching first', async () => {
|
|
178
|
-
const os = mockPodOS();
|
|
179
|
-
os.fetch.mockRejectedValue(new Error('should not fetch'));
|
|
180
|
-
await page.rootInstance.receivePodOs(os);
|
|
181
|
-
await page.waitForChanges();
|
|
182
|
-
expect(page.root).toEqualHtml(`
|
|
183
|
-
<pos-resource lazy uri="https://resource.test/">
|
|
184
|
-
<mock:shadow-root>
|
|
185
|
-
<slot />
|
|
186
|
-
</mock:shadow-root>
|
|
187
|
-
</pos-resource>
|
|
188
|
-
`);
|
|
189
|
-
});
|
|
190
|
-
describe('after fetch is explicitly requested', function () {
|
|
191
|
-
it('renders loading indicator while fetching', async () => {
|
|
192
|
-
const os = mockPodOS();
|
|
193
|
-
when(os.fetch)
|
|
194
|
-
.calledWith('https://resource.test/')
|
|
195
|
-
.mockReturnValue(new Promise(() => null));
|
|
196
|
-
await page.rootInstance.receivePodOs(os);
|
|
197
|
-
page.root.fetch();
|
|
198
|
-
await page.waitForChanges();
|
|
199
|
-
expect(page.root).toEqualHtml(`
|
|
200
|
-
<pos-resource lazy uri="https://resource.test/">
|
|
201
|
-
<mock:shadow-root>
|
|
202
|
-
<ion-progress-bar type="indeterminate"></ion-progress-bar>
|
|
203
|
-
</mock:shadow-root>
|
|
204
|
-
</pos-resource>
|
|
205
|
-
`);
|
|
206
|
-
});
|
|
207
|
-
it('renders slot after loading', async () => {
|
|
208
|
-
const os = mockPodOS();
|
|
209
|
-
when(os.fetch).calledWith('https://resource.test/').mockResolvedValue(null);
|
|
210
|
-
await page.rootInstance.receivePodOs(os);
|
|
211
|
-
await page.root.fetch();
|
|
212
|
-
await page.waitForChanges();
|
|
213
|
-
expect(page.root).toEqualHtml(`
|
|
214
|
-
<pos-resource lazy uri="https://resource.test/">
|
|
215
|
-
<mock:shadow-root>
|
|
216
|
-
<slot></slot>
|
|
217
|
-
</mock:shadow-root>
|
|
218
|
-
</pos-resource>
|
|
219
|
-
`);
|
|
220
|
-
});
|
|
221
|
-
it('renders error when fetch failed', async () => {
|
|
222
|
-
const os = mockPodOS();
|
|
223
|
-
when(os.fetch).calledWith('https://resource.test/').mockRejectedValue(new Error('not found'));
|
|
224
|
-
await page.rootInstance.receivePodOs(os);
|
|
225
|
-
page.root.fetch();
|
|
226
|
-
await page.waitForChanges();
|
|
227
|
-
const errorDetails = page.root.shadowRoot.querySelector('details');
|
|
228
|
-
expect(errorDetails).toEqualHtml(`
|
|
229
|
-
<details>
|
|
230
|
-
not found
|
|
231
|
-
</details>
|
|
232
|
-
`);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
//# sourceMappingURL=pos-resource.spec.js.map
|