@startinblox/components-ds4go 2.3.0 → 3.0.1
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 +8 -2
- package/AGENTS.md +516 -0
- package/biome.json +1 -1
- package/cypress/component/no-component-test.cy.ts +9 -0
- package/cypress/e2e/helpers/components/setupCacheInvalidation.cy.ts +512 -0
- package/cypress/e2e/helpers/components/setupCacheOnResourceReady.cy.ts +483 -0
- package/cypress/e2e/helpers/components/setupComponentSubscriptions.cy.ts +239 -0
- package/cypress/e2e/helpers/components/setupOnSaveReset.cy.ts +380 -0
- package/cypress/e2e/helpers/datas/checkValueInIntervalRecursive.cy.ts +563 -0
- package/cypress/e2e/helpers/datas/dataBuilder.cy.ts +508 -0
- package/cypress/e2e/helpers/datas/filterGenerator.cy.ts +285 -0
- package/cypress/e2e/helpers/datas/filterObjectByDateAfter.cy.ts +389 -0
- package/cypress/e2e/helpers/datas/filterObjectByDateInterval.cy.ts +613 -0
- package/cypress/e2e/helpers/datas/filterObjectById.cy.ts +276 -0
- package/cypress/e2e/helpers/datas/filterObjectByInterval.cy.ts +237 -0
- package/cypress/e2e/helpers/datas/filterObjectByNamedValue.cy.ts +299 -0
- package/cypress/e2e/helpers/datas/filterObjectByType.cy.ts +307 -0
- package/cypress/e2e/helpers/datas/filterObjectByValue.cy.ts +375 -0
- package/cypress/e2e/helpers/datas/sort.cy.ts +293 -0
- package/cypress/e2e/helpers/ui/formatDate.cy.ts +233 -0
- package/cypress/e2e/helpers/utils/requestNavigation.cy.ts +257 -0
- package/cypress/e2e/helpers/utils/uniq.cy.ts +160 -0
- package/cypress/support/e2e.ts +1 -0
- package/cypress.config.ts +2 -0
- package/dist/index.js +1113 -1004
- package/package.json +10 -10
- package/src/components/solid-boilerplate.ts +76 -0
- package/src/helpers/components/componentObjectHandler.ts +5 -7
- package/src/helpers/components/componentObjectsHandler.ts +8 -3
- package/src/helpers/components/orbitComponent.ts +87 -68
- package/src/helpers/components/orbitDspComponent.ts +14 -4
- package/src/helpers/components/setupCacheInvalidation.ts +50 -23
- package/src/helpers/components/setupCacheOnResourceReady.ts +42 -23
- package/src/helpers/components/setupComponentSubscriptions.ts +10 -9
- package/src/helpers/components/setupOnSaveReset.ts +27 -5
- package/src/helpers/datas/checkValueInIntervalRecursive.ts +66 -0
- package/src/helpers/datas/dataBuilder.ts +4 -4
- package/src/helpers/datas/filterGenerator.ts +13 -10
- package/src/helpers/datas/filterObjectByDateAfter.ts +3 -3
- package/src/helpers/datas/filterObjectByDateInterval.ts +44 -0
- package/src/helpers/datas/filterObjectById.ts +7 -6
- package/src/helpers/datas/filterObjectByInterval.ts +6 -110
- package/src/helpers/datas/filterObjectByNamedValue.ts +35 -33
- package/src/helpers/datas/filterObjectByType.ts +3 -3
- package/src/helpers/datas/filterObjectByValue.ts +17 -16
- package/src/helpers/datas/sort.ts +50 -23
- package/src/helpers/index.ts +2 -0
- package/src/helpers/ui/formatDate.ts +14 -1
- package/src/helpers/utils/requestNavigation.ts +5 -2
- package/src/helpers/utils/uniq.ts +1 -1
- package/cypress/component/solid-boilerplate.cy.ts +0 -9
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import setupCacheOnResourceReady from "@helpers/components/setupCacheOnResourceReady";
|
|
2
|
+
|
|
3
|
+
describe("setupCacheOnResourceReady helper function", () => {
|
|
4
|
+
const createMockComponent = () => {
|
|
5
|
+
const _subscriptions = new Set();
|
|
6
|
+
|
|
7
|
+
const mockComponent: any = {
|
|
8
|
+
_subscriptions,
|
|
9
|
+
_subscribe() {
|
|
10
|
+
for (const subscription of this._subscriptions) {
|
|
11
|
+
document.addEventListener(subscription[0], subscription[1]);
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
_unsubscribe() {
|
|
15
|
+
for (const subscription of this._subscriptions) {
|
|
16
|
+
document.removeEventListener(subscription[0], subscription[1]);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
caching: 0,
|
|
20
|
+
hasCachedDatas: false,
|
|
21
|
+
requestUpdate: cy.stub(),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return mockComponent;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe("Basic functionality", () => {
|
|
28
|
+
it("should set up resource cache listener on component", () => {
|
|
29
|
+
const mockComponent = createMockComponent();
|
|
30
|
+
|
|
31
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
32
|
+
|
|
33
|
+
expect(mockComponent._subscriptions.size).to.be.greaterThan(0);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should subscribe to resourceReady event", () => {
|
|
37
|
+
const mockComponent = createMockComponent();
|
|
38
|
+
|
|
39
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
40
|
+
|
|
41
|
+
const subscriptions = Array.from(mockComponent._subscriptions);
|
|
42
|
+
expect(
|
|
43
|
+
subscriptions.some((sub: any) => sub[0] === "resourceReady"),
|
|
44
|
+
).to.be.true;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should call _subscribe method", () => {
|
|
48
|
+
const mockComponent: any = {
|
|
49
|
+
_subscriptions: new Set(),
|
|
50
|
+
_subscribe: cy.stub(),
|
|
51
|
+
caching: 0,
|
|
52
|
+
hasCachedDatas: false,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
56
|
+
|
|
57
|
+
expect(mockComponent._subscribe).to.be.calledOnce;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should initialize caching property if undefined", () => {
|
|
61
|
+
const mockComponent: any = {
|
|
62
|
+
_subscriptions: new Set(),
|
|
63
|
+
_subscribe: cy.stub(),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
67
|
+
|
|
68
|
+
expect(mockComponent.caching).to.equal(0);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should initialize hasCachedDatas property if undefined", () => {
|
|
72
|
+
const mockComponent: any = {
|
|
73
|
+
_subscriptions: new Set(),
|
|
74
|
+
_subscribe: cy.stub(),
|
|
75
|
+
caching: 0,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
79
|
+
|
|
80
|
+
expect(mockComponent.hasCachedDatas).to.be.false;
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("Cache invalidation on keyword match", () => {
|
|
85
|
+
it("should increment caching when keyword matches", () => {
|
|
86
|
+
const mockComponent = createMockComponent();
|
|
87
|
+
mockComponent.hasCachedDatas = true;
|
|
88
|
+
|
|
89
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
90
|
+
|
|
91
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
92
|
+
detail: { id: "https://example.com/test/resource" },
|
|
93
|
+
});
|
|
94
|
+
document.dispatchEvent(resourceEvent);
|
|
95
|
+
|
|
96
|
+
expect(mockComponent.caching).to.equal(1);
|
|
97
|
+
|
|
98
|
+
mockComponent._unsubscribe();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should set hasCachedDatas to false when keyword matches", () => {
|
|
102
|
+
const mockComponent = createMockComponent();
|
|
103
|
+
mockComponent.hasCachedDatas = true;
|
|
104
|
+
|
|
105
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
106
|
+
|
|
107
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
108
|
+
detail: { id: "https://example.com/test/resource" },
|
|
109
|
+
});
|
|
110
|
+
document.dispatchEvent(resourceEvent);
|
|
111
|
+
|
|
112
|
+
expect(mockComponent.hasCachedDatas).to.be.false;
|
|
113
|
+
|
|
114
|
+
mockComponent._unsubscribe();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should request update when keyword matches", () => {
|
|
118
|
+
const mockComponent = createMockComponent();
|
|
119
|
+
mockComponent.hasCachedDatas = true;
|
|
120
|
+
|
|
121
|
+
cy.stub(window, "requestAnimationFrame").callsFake((cb: any) => cb());
|
|
122
|
+
|
|
123
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
124
|
+
|
|
125
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
126
|
+
detail: { id: "https://example.com/test/resource" },
|
|
127
|
+
});
|
|
128
|
+
document.dispatchEvent(resourceEvent);
|
|
129
|
+
|
|
130
|
+
expect(mockComponent.requestUpdate).to.be.called;
|
|
131
|
+
|
|
132
|
+
mockComponent._unsubscribe();
|
|
133
|
+
cy.wrap(null).then(() => (window.requestAnimationFrame as any).restore());
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("should not update cache when keyword doesn't match", () => {
|
|
137
|
+
const mockComponent = createMockComponent();
|
|
138
|
+
mockComponent.hasCachedDatas = true;
|
|
139
|
+
|
|
140
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
141
|
+
|
|
142
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
143
|
+
detail: { id: "https://example.com/other/resource" },
|
|
144
|
+
});
|
|
145
|
+
document.dispatchEvent(resourceEvent);
|
|
146
|
+
|
|
147
|
+
expect(mockComponent.caching).to.equal(0);
|
|
148
|
+
expect(mockComponent.hasCachedDatas).to.be.true;
|
|
149
|
+
expect(mockComponent.requestUpdate).to.not.be.called;
|
|
150
|
+
|
|
151
|
+
mockComponent._unsubscribe();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("Keyword matching", () => {
|
|
156
|
+
it("should match keyword at start of URL", () => {
|
|
157
|
+
const mockComponent = createMockComponent();
|
|
158
|
+
mockComponent.hasCachedDatas = true;
|
|
159
|
+
|
|
160
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
161
|
+
|
|
162
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
163
|
+
detail: { id: "https://test.com/resource" },
|
|
164
|
+
});
|
|
165
|
+
document.dispatchEvent(resourceEvent);
|
|
166
|
+
|
|
167
|
+
expect(mockComponent.caching).to.equal(1);
|
|
168
|
+
|
|
169
|
+
mockComponent._unsubscribe();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should match keyword after slash", () => {
|
|
173
|
+
const mockComponent = createMockComponent();
|
|
174
|
+
mockComponent.hasCachedDatas = true;
|
|
175
|
+
|
|
176
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
177
|
+
|
|
178
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
179
|
+
detail: { id: "https://example.com/test/resource" },
|
|
180
|
+
});
|
|
181
|
+
document.dispatchEvent(resourceEvent);
|
|
182
|
+
|
|
183
|
+
expect(mockComponent.caching).to.equal(1);
|
|
184
|
+
|
|
185
|
+
mockComponent._unsubscribe();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("should not match keyword in middle of path segment", () => {
|
|
189
|
+
const mockComponent = createMockComponent();
|
|
190
|
+
mockComponent.hasCachedDatas = true;
|
|
191
|
+
|
|
192
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
193
|
+
|
|
194
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
195
|
+
detail: { id: "https://example.com/atestresource" },
|
|
196
|
+
});
|
|
197
|
+
document.dispatchEvent(resourceEvent);
|
|
198
|
+
|
|
199
|
+
expect(mockComponent.caching).to.equal(0);
|
|
200
|
+
|
|
201
|
+
mockComponent._unsubscribe();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should match keyword in last segment", () => {
|
|
205
|
+
const mockComponent = createMockComponent();
|
|
206
|
+
mockComponent.hasCachedDatas = true;
|
|
207
|
+
|
|
208
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
209
|
+
|
|
210
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
211
|
+
detail: { id: "https://example.com/path/test" },
|
|
212
|
+
});
|
|
213
|
+
document.dispatchEvent(resourceEvent);
|
|
214
|
+
|
|
215
|
+
expect(mockComponent.caching).to.equal(1);
|
|
216
|
+
|
|
217
|
+
mockComponent._unsubscribe();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("should handle multiple keywords", () => {
|
|
221
|
+
const mockComponent = createMockComponent();
|
|
222
|
+
mockComponent.hasCachedDatas = true;
|
|
223
|
+
|
|
224
|
+
setupCacheOnResourceReady(mockComponent, {
|
|
225
|
+
keywords: ["test", "project", "user"],
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const resourceEvent1 = new CustomEvent("resourceReady", {
|
|
229
|
+
detail: { id: "https://example.com/test/resource" },
|
|
230
|
+
});
|
|
231
|
+
document.dispatchEvent(resourceEvent1);
|
|
232
|
+
|
|
233
|
+
const resourceEvent2 = new CustomEvent("resourceReady", {
|
|
234
|
+
detail: { id: "https://example.com/user/profile" },
|
|
235
|
+
});
|
|
236
|
+
document.dispatchEvent(resourceEvent2);
|
|
237
|
+
|
|
238
|
+
expect(mockComponent.caching).to.equal(2);
|
|
239
|
+
|
|
240
|
+
mockComponent._unsubscribe();
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe("Event detail resource handling", () => {
|
|
245
|
+
it("should handle resource with @id property", () => {
|
|
246
|
+
const mockComponent = createMockComponent();
|
|
247
|
+
mockComponent.hasCachedDatas = true;
|
|
248
|
+
|
|
249
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
250
|
+
|
|
251
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
252
|
+
detail: {
|
|
253
|
+
resource: { "@id": "https://example.com/test/resource" },
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
document.dispatchEvent(resourceEvent);
|
|
257
|
+
|
|
258
|
+
expect(mockComponent.caching).to.equal(1);
|
|
259
|
+
|
|
260
|
+
mockComponent._unsubscribe();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("should prioritize id over resource.@id", () => {
|
|
264
|
+
const mockComponent = createMockComponent();
|
|
265
|
+
mockComponent.hasCachedDatas = true;
|
|
266
|
+
|
|
267
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
268
|
+
|
|
269
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
270
|
+
detail: {
|
|
271
|
+
id: "https://example.com/test/id",
|
|
272
|
+
resource: { "@id": "https://example.com/test/resource" },
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
document.dispatchEvent(resourceEvent);
|
|
276
|
+
|
|
277
|
+
expect(mockComponent.caching).to.equal(1);
|
|
278
|
+
|
|
279
|
+
mockComponent._unsubscribe();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("should not update cache when id is missing", () => {
|
|
283
|
+
const mockComponent = createMockComponent();
|
|
284
|
+
mockComponent.hasCachedDatas = true;
|
|
285
|
+
|
|
286
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
287
|
+
|
|
288
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
289
|
+
detail: { resource: { name: "test" } },
|
|
290
|
+
});
|
|
291
|
+
document.dispatchEvent(resourceEvent);
|
|
292
|
+
|
|
293
|
+
expect(mockComponent.caching).to.equal(0);
|
|
294
|
+
|
|
295
|
+
mockComponent._unsubscribe();
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe("Empty keywords handling", () => {
|
|
300
|
+
it("should not set up listener when keywords array is empty", () => {
|
|
301
|
+
const mockComponent = createMockComponent();
|
|
302
|
+
|
|
303
|
+
setupCacheOnResourceReady(mockComponent, { keywords: [] });
|
|
304
|
+
|
|
305
|
+
expect(mockComponent._subscriptions.size).to.equal(0);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("should not set up listener when keywords is undefined", () => {
|
|
309
|
+
const mockComponent = createMockComponent();
|
|
310
|
+
|
|
311
|
+
setupCacheOnResourceReady(mockComponent, {});
|
|
312
|
+
|
|
313
|
+
expect(mockComponent._subscriptions.size).to.equal(0);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe("Multiple resourceReady events", () => {
|
|
318
|
+
it("should handle multiple resourceReady events", () => {
|
|
319
|
+
const mockComponent = createMockComponent();
|
|
320
|
+
mockComponent.hasCachedDatas = true;
|
|
321
|
+
|
|
322
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
323
|
+
|
|
324
|
+
for (let i = 0; i < 5; i++) {
|
|
325
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
326
|
+
detail: { id: `https://example.com/test/resource${i}` },
|
|
327
|
+
});
|
|
328
|
+
document.dispatchEvent(resourceEvent);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
expect(mockComponent.caching).to.equal(5);
|
|
332
|
+
|
|
333
|
+
mockComponent._unsubscribe();
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
describe("Component property requirements", () => {
|
|
338
|
+
it("should require component to provide _subscriptions Set", () => {
|
|
339
|
+
const mockComponent: any = {
|
|
340
|
+
_subscriptions: new Set(),
|
|
341
|
+
_subscribe: cy.stub(),
|
|
342
|
+
caching: 0,
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
346
|
+
|
|
347
|
+
expect(mockComponent._subscriptions).to.be.an.instanceOf(Set);
|
|
348
|
+
expect(mockComponent._subscriptions.size).to.be.greaterThan(0);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("should create resourceCacheListener property", () => {
|
|
352
|
+
const mockComponent = createMockComponent();
|
|
353
|
+
|
|
354
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
355
|
+
|
|
356
|
+
expect(mockComponent.resourceCacheListener).to.be.a("function");
|
|
357
|
+
|
|
358
|
+
mockComponent._unsubscribe();
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
describe("Edge cases", () => {
|
|
363
|
+
it("should handle URL with no path", () => {
|
|
364
|
+
const mockComponent = createMockComponent();
|
|
365
|
+
mockComponent.hasCachedDatas = true;
|
|
366
|
+
|
|
367
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["example.com"] });
|
|
368
|
+
|
|
369
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
370
|
+
detail: { id: "https://example.com" },
|
|
371
|
+
});
|
|
372
|
+
document.dispatchEvent(resourceEvent);
|
|
373
|
+
|
|
374
|
+
expect(mockComponent.caching).to.equal(1);
|
|
375
|
+
|
|
376
|
+
mockComponent._unsubscribe();
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("should handle duplicate keywords", () => {
|
|
380
|
+
const mockComponent = createMockComponent();
|
|
381
|
+
mockComponent.hasCachedDatas = true;
|
|
382
|
+
|
|
383
|
+
setupCacheOnResourceReady(mockComponent, {
|
|
384
|
+
keywords: ["test", "test", "test"],
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
388
|
+
detail: { id: "https://example.com/test/resource" },
|
|
389
|
+
});
|
|
390
|
+
document.dispatchEvent(resourceEvent);
|
|
391
|
+
|
|
392
|
+
expect(mockComponent.caching).to.equal(1);
|
|
393
|
+
|
|
394
|
+
mockComponent._unsubscribe();
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("should handle keyword with special characters", () => {
|
|
398
|
+
const mockComponent = createMockComponent();
|
|
399
|
+
mockComponent.hasCachedDatas = true;
|
|
400
|
+
|
|
401
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["@type"] });
|
|
402
|
+
|
|
403
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
404
|
+
detail: { id: "https://example.com/@type/resource" },
|
|
405
|
+
});
|
|
406
|
+
document.dispatchEvent(resourceEvent);
|
|
407
|
+
|
|
408
|
+
expect(mockComponent.caching).to.equal(1);
|
|
409
|
+
|
|
410
|
+
mockComponent._unsubscribe();
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
describe("Document ready state", () => {
|
|
415
|
+
it("should set up immediately when document is complete", () => {
|
|
416
|
+
const mockComponent: any = {
|
|
417
|
+
_subscriptions: new Set(),
|
|
418
|
+
_subscribe: cy.stub(),
|
|
419
|
+
caching: 0,
|
|
420
|
+
hasCachedDatas: false,
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
cy.document().then((doc) => {
|
|
424
|
+
const originalReadyState = Object.getOwnPropertyDescriptor(
|
|
425
|
+
Document.prototype,
|
|
426
|
+
"readyState",
|
|
427
|
+
);
|
|
428
|
+
Object.defineProperty(doc, "readyState", {
|
|
429
|
+
get: () => "complete",
|
|
430
|
+
configurable: true,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
434
|
+
|
|
435
|
+
expect(mockComponent._subscribe).to.be.calledOnce;
|
|
436
|
+
|
|
437
|
+
if (originalReadyState) {
|
|
438
|
+
Object.defineProperty(doc, "readyState", originalReadyState);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
describe("Comparison with setupCacheInvalidation", () => {
|
|
445
|
+
it("should listen to resourceReady instead of save event", () => {
|
|
446
|
+
const mockComponent = createMockComponent();
|
|
447
|
+
|
|
448
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
449
|
+
|
|
450
|
+
const subscriptions = Array.from(mockComponent._subscriptions);
|
|
451
|
+
expect(
|
|
452
|
+
subscriptions.some((sub: any) => sub[0] === "resourceReady"),
|
|
453
|
+
).to.be.true;
|
|
454
|
+
expect(subscriptions.some((sub: any) => sub[0] === "save")).to.be.false;
|
|
455
|
+
|
|
456
|
+
mockComponent._unsubscribe();
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it("should not call sibStore.clearCache", () => {
|
|
460
|
+
cy.window().then((win) => {
|
|
461
|
+
(win as any).sibStore = {
|
|
462
|
+
clearCache: cy.stub(),
|
|
463
|
+
};
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
const mockComponent = createMockComponent();
|
|
467
|
+
mockComponent.hasCachedDatas = true;
|
|
468
|
+
|
|
469
|
+
setupCacheOnResourceReady(mockComponent, { keywords: ["test"] });
|
|
470
|
+
|
|
471
|
+
const resourceEvent = new CustomEvent("resourceReady", {
|
|
472
|
+
detail: { id: "https://example.com/test/resource" },
|
|
473
|
+
});
|
|
474
|
+
document.dispatchEvent(resourceEvent);
|
|
475
|
+
|
|
476
|
+
cy.window().then((win) => {
|
|
477
|
+
expect((win as any).sibStore.clearCache).to.not.be.called;
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
mockComponent._unsubscribe();
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
});
|