@startinblox/components-ds4go 2.3.0 → 3.0.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/.gitlab-ci.yml +8 -2
- package/AGENTS.md +516 -0
- 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 +1102 -1002
- 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/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,512 @@
|
|
|
1
|
+
import setupCacheInvalidation from "@helpers/components/setupCacheInvalidation";
|
|
2
|
+
|
|
3
|
+
describe("setupCacheInvalidation 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
|
+
dataSrc: "https://example.com/test/data",
|
|
22
|
+
requestUpdate: cy.stub(),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return mockComponent;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
cy.window().then((win) => {
|
|
30
|
+
(win as any).sibStore = {
|
|
31
|
+
clearCache: cy.stub(),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("Basic functionality", () => {
|
|
37
|
+
it("should set up cache listener on component", () => {
|
|
38
|
+
const mockComponent = createMockComponent();
|
|
39
|
+
|
|
40
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
41
|
+
|
|
42
|
+
expect(mockComponent._subscriptions.size).to.be.greaterThan(0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should subscribe to save event", () => {
|
|
46
|
+
const mockComponent = createMockComponent();
|
|
47
|
+
|
|
48
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
49
|
+
|
|
50
|
+
const subscriptions = Array.from(mockComponent._subscriptions);
|
|
51
|
+
expect(subscriptions.some((sub: any) => sub[0] === "save")).to.be.true;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should initialize caching property if undefined", () => {
|
|
55
|
+
const mockComponent: any = {
|
|
56
|
+
_subscriptions: new Set(),
|
|
57
|
+
_subscribe: cy.stub(),
|
|
58
|
+
dataSrc: "https://example.com/test/data",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
62
|
+
|
|
63
|
+
expect(mockComponent.caching).to.equal(0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should initialize hasCachedDatas property if undefined", () => {
|
|
67
|
+
const mockComponent: any = {
|
|
68
|
+
_subscriptions: new Set(),
|
|
69
|
+
_subscribe: cy.stub(),
|
|
70
|
+
caching: 0,
|
|
71
|
+
dataSrc: "https://example.com/test/data",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
75
|
+
|
|
76
|
+
expect(mockComponent.hasCachedDatas).to.be.false;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("Cache clearing on keyword match", () => {
|
|
81
|
+
it("should clear cache when keyword matches", () => {
|
|
82
|
+
const mockComponent = createMockComponent();
|
|
83
|
+
mockComponent.hasCachedDatas = true;
|
|
84
|
+
|
|
85
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
86
|
+
|
|
87
|
+
const saveEvent = new CustomEvent("save", {
|
|
88
|
+
detail: { id: "https://example.com/test/resource" },
|
|
89
|
+
});
|
|
90
|
+
document.dispatchEvent(saveEvent);
|
|
91
|
+
|
|
92
|
+
cy.window().then((win) => {
|
|
93
|
+
expect((win as any).sibStore.clearCache).to.be.calledOnceWith(
|
|
94
|
+
mockComponent.dataSrc,
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
mockComponent._unsubscribe();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should not clear cache when keyword doesn't match", () => {
|
|
102
|
+
const mockComponent = createMockComponent();
|
|
103
|
+
mockComponent.dataSrc = "https://example.com/other/data";
|
|
104
|
+
mockComponent.hasCachedDatas = true;
|
|
105
|
+
|
|
106
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
107
|
+
|
|
108
|
+
const saveEvent = new CustomEvent("save", {
|
|
109
|
+
detail: { id: "https://example.com/other/resource" },
|
|
110
|
+
});
|
|
111
|
+
document.dispatchEvent(saveEvent);
|
|
112
|
+
|
|
113
|
+
cy.window().then((win) => {
|
|
114
|
+
expect((win as any).sibStore.clearCache).to.not.be.called;
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
mockComponent._unsubscribe();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should request update when cache is cleared", () => {
|
|
121
|
+
const mockComponent = createMockComponent();
|
|
122
|
+
mockComponent.hasCachedDatas = true;
|
|
123
|
+
|
|
124
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
125
|
+
|
|
126
|
+
const saveEvent = new CustomEvent("save", {
|
|
127
|
+
detail: { id: "https://example.com/test/resource" },
|
|
128
|
+
});
|
|
129
|
+
document.dispatchEvent(saveEvent);
|
|
130
|
+
|
|
131
|
+
cy.wait(0).then(() => {
|
|
132
|
+
expect(mockComponent.requestUpdate).to.be.called;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
mockComponent._unsubscribe();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("Attribute configuration", () => {
|
|
140
|
+
it("should use default dataSrc attribute", () => {
|
|
141
|
+
const mockComponent = createMockComponent();
|
|
142
|
+
mockComponent.hasCachedDatas = true;
|
|
143
|
+
|
|
144
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
145
|
+
|
|
146
|
+
const saveEvent = new CustomEvent("save", {
|
|
147
|
+
detail: { id: "https://example.com/test/resource" },
|
|
148
|
+
});
|
|
149
|
+
document.dispatchEvent(saveEvent);
|
|
150
|
+
|
|
151
|
+
cy.window().then((win) => {
|
|
152
|
+
expect((win as any).sibStore.clearCache).to.be.calledWith(
|
|
153
|
+
mockComponent.dataSrc,
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
mockComponent._unsubscribe();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("should clear cache for custom attributes", () => {
|
|
161
|
+
const mockComponent: any = {
|
|
162
|
+
_subscriptions: new Set(),
|
|
163
|
+
_subscribe() {
|
|
164
|
+
for (const subscription of this._subscriptions) {
|
|
165
|
+
document.addEventListener(subscription[0], subscription[1]);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
_unsubscribe() {
|
|
169
|
+
for (const subscription of this._subscriptions) {
|
|
170
|
+
document.removeEventListener(subscription[0], subscription[1]);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
caching: 0,
|
|
174
|
+
hasCachedDatas: true,
|
|
175
|
+
customAttr: "https://example.com/test/data",
|
|
176
|
+
requestUpdate: cy.stub(),
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
setupCacheInvalidation(mockComponent, {
|
|
180
|
+
keywords: ["test"],
|
|
181
|
+
attributes: ["customAttr"],
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const saveEvent = new CustomEvent("save", {
|
|
185
|
+
detail: { id: "https://example.com/test/resource" },
|
|
186
|
+
});
|
|
187
|
+
document.dispatchEvent(saveEvent);
|
|
188
|
+
|
|
189
|
+
cy.window().then((win) => {
|
|
190
|
+
expect((win as any).sibStore.clearCache).to.be.calledWith(
|
|
191
|
+
mockComponent.customAttr,
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
mockComponent._unsubscribe();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should clear cache for multiple attributes", () => {
|
|
199
|
+
const mockComponent: any = {
|
|
200
|
+
_subscriptions: new Set(),
|
|
201
|
+
_subscribe() {
|
|
202
|
+
for (const subscription of this._subscriptions) {
|
|
203
|
+
document.addEventListener(subscription[0], subscription[1]);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
_unsubscribe() {
|
|
207
|
+
for (const subscription of this._subscriptions) {
|
|
208
|
+
document.removeEventListener(subscription[0], subscription[1]);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
caching: 0,
|
|
212
|
+
hasCachedDatas: true,
|
|
213
|
+
dataSrc: "https://example.com/test/data1",
|
|
214
|
+
src: "https://example.com/test/data2",
|
|
215
|
+
requestUpdate: cy.stub(),
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
setupCacheInvalidation(mockComponent, {
|
|
219
|
+
keywords: ["test"],
|
|
220
|
+
attributes: ["dataSrc", "src"],
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const saveEvent = new CustomEvent("save", {
|
|
224
|
+
detail: { id: "https://example.com/test/resource" },
|
|
225
|
+
});
|
|
226
|
+
document.dispatchEvent(saveEvent);
|
|
227
|
+
|
|
228
|
+
cy.window().then((win) => {
|
|
229
|
+
expect((win as any).sibStore.clearCache).to.be.calledTwice;
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
mockComponent._unsubscribe();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("should skip attributes that are undefined", () => {
|
|
236
|
+
const mockComponent = createMockComponent();
|
|
237
|
+
mockComponent.hasCachedDatas = true;
|
|
238
|
+
|
|
239
|
+
setupCacheInvalidation(mockComponent, {
|
|
240
|
+
keywords: ["test"],
|
|
241
|
+
attributes: ["dataSrc", "undefinedAttr"],
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const saveEvent = new CustomEvent("save", {
|
|
245
|
+
detail: { id: "https://example.com/test/resource" },
|
|
246
|
+
});
|
|
247
|
+
document.dispatchEvent(saveEvent);
|
|
248
|
+
|
|
249
|
+
cy.window().then((win) => {
|
|
250
|
+
expect((win as any).sibStore.clearCache).to.be.calledOnce;
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
mockComponent._unsubscribe();
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe("Same resource check", () => {
|
|
258
|
+
it("should not clear cache if saved resource is the same as dataSrc", () => {
|
|
259
|
+
const dataUrl = "https://example.com/test/data";
|
|
260
|
+
const mockComponent = createMockComponent();
|
|
261
|
+
mockComponent.dataSrc = dataUrl;
|
|
262
|
+
mockComponent.hasCachedDatas = true;
|
|
263
|
+
|
|
264
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
265
|
+
|
|
266
|
+
const saveEvent = new CustomEvent("save", {
|
|
267
|
+
detail: { id: dataUrl },
|
|
268
|
+
});
|
|
269
|
+
document.dispatchEvent(saveEvent);
|
|
270
|
+
|
|
271
|
+
cy.window().then((win) => {
|
|
272
|
+
expect((win as any).sibStore.clearCache).to.not.be.called;
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
mockComponent._unsubscribe();
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("should clear cache if saved resource differs from dataSrc", () => {
|
|
279
|
+
const mockComponent = createMockComponent();
|
|
280
|
+
mockComponent.dataSrc = "https://example.com/test/data1";
|
|
281
|
+
mockComponent.hasCachedDatas = true;
|
|
282
|
+
|
|
283
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
284
|
+
|
|
285
|
+
const saveEvent = new CustomEvent("save", {
|
|
286
|
+
detail: { id: "https://example.com/test/data2" },
|
|
287
|
+
});
|
|
288
|
+
document.dispatchEvent(saveEvent);
|
|
289
|
+
|
|
290
|
+
cy.window().then((win) => {
|
|
291
|
+
expect((win as any).sibStore.clearCache).to.be.calledOnce;
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
mockComponent._unsubscribe();
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe("Keyword matching behavior", () => {
|
|
299
|
+
it("should match keyword at start of URL", () => {
|
|
300
|
+
const mockComponent = createMockComponent();
|
|
301
|
+
mockComponent.dataSrc = "https://example.com/other/data";
|
|
302
|
+
mockComponent.hasCachedDatas = true;
|
|
303
|
+
|
|
304
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
305
|
+
|
|
306
|
+
const saveEvent = new CustomEvent("save", {
|
|
307
|
+
detail: { id: "https://test.com/resource" },
|
|
308
|
+
});
|
|
309
|
+
document.dispatchEvent(saveEvent);
|
|
310
|
+
|
|
311
|
+
cy.window().then((win) => {
|
|
312
|
+
expect((win as any).sibStore.clearCache).to.be.calledOnce;
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
mockComponent._unsubscribe();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("should match keyword after slash", () => {
|
|
319
|
+
const mockComponent = createMockComponent();
|
|
320
|
+
mockComponent.dataSrc = "https://example.com/other/data";
|
|
321
|
+
mockComponent.hasCachedDatas = true;
|
|
322
|
+
|
|
323
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
324
|
+
|
|
325
|
+
const saveEvent = new CustomEvent("save", {
|
|
326
|
+
detail: { id: "https://example.com/test/resource" },
|
|
327
|
+
});
|
|
328
|
+
document.dispatchEvent(saveEvent);
|
|
329
|
+
|
|
330
|
+
cy.window().then((win) => {
|
|
331
|
+
expect((win as any).sibStore.clearCache).to.be.calledOnce;
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
mockComponent._unsubscribe();
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("should handle multiple keywords", () => {
|
|
338
|
+
const mockComponent = createMockComponent();
|
|
339
|
+
mockComponent.dataSrc = "https://example.com/data";
|
|
340
|
+
mockComponent.hasCachedDatas = true;
|
|
341
|
+
|
|
342
|
+
setupCacheInvalidation(mockComponent, {
|
|
343
|
+
keywords: ["test", "project", "user"],
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const saveEvent1 = new CustomEvent("save", {
|
|
347
|
+
detail: { id: "https://example.com/test/resource" },
|
|
348
|
+
});
|
|
349
|
+
document.dispatchEvent(saveEvent1);
|
|
350
|
+
|
|
351
|
+
const saveEvent2 = new CustomEvent("save", {
|
|
352
|
+
detail: { id: "https://example.com/user/profile" },
|
|
353
|
+
});
|
|
354
|
+
document.dispatchEvent(saveEvent2);
|
|
355
|
+
|
|
356
|
+
cy.window().then((win) => {
|
|
357
|
+
expect((win as any).sibStore.clearCache).to.be.calledTwice;
|
|
358
|
+
expect(mockComponent.caching).to.equal(2);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
mockComponent._unsubscribe();
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
describe("Empty configuration handling", () => {
|
|
366
|
+
it("should not set up listener when keywords array is empty", () => {
|
|
367
|
+
const mockComponent = createMockComponent();
|
|
368
|
+
|
|
369
|
+
setupCacheInvalidation(mockComponent, { keywords: [] });
|
|
370
|
+
|
|
371
|
+
expect(mockComponent._subscriptions.size).to.equal(0);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("should not set up listener when keywords is undefined", () => {
|
|
375
|
+
const mockComponent = createMockComponent();
|
|
376
|
+
|
|
377
|
+
setupCacheInvalidation(mockComponent, {});
|
|
378
|
+
|
|
379
|
+
expect(mockComponent._subscriptions.size).to.equal(0);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("should not set up listener when attributes array is empty", () => {
|
|
383
|
+
const mockComponent = createMockComponent();
|
|
384
|
+
|
|
385
|
+
setupCacheInvalidation(mockComponent, {
|
|
386
|
+
keywords: ["test"],
|
|
387
|
+
attributes: [],
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
expect(mockComponent._subscriptions.size).to.equal(0);
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
describe("Multiple cache invalidations", () => {
|
|
395
|
+
it("should handle multiple save events", () => {
|
|
396
|
+
const mockComponent = createMockComponent();
|
|
397
|
+
mockComponent.hasCachedDatas = true;
|
|
398
|
+
|
|
399
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
400
|
+
|
|
401
|
+
for (let i = 0; i < 3; i++) {
|
|
402
|
+
const saveEvent = new CustomEvent("save", {
|
|
403
|
+
detail: { id: `https://example.com/test/resource${i}` },
|
|
404
|
+
});
|
|
405
|
+
document.dispatchEvent(saveEvent);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
cy.window().then((win) => {
|
|
409
|
+
expect((win as any).sibStore.clearCache).to.be.calledThrice;
|
|
410
|
+
expect(mockComponent.caching).to.equal(3);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
mockComponent._unsubscribe();
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it("should prevent duplicate updates via requestAnimationFrame", () => {
|
|
417
|
+
const mockComponent = createMockComponent();
|
|
418
|
+
mockComponent.hasCachedDatas = true;
|
|
419
|
+
|
|
420
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
421
|
+
|
|
422
|
+
const saveEvent1 = new CustomEvent("save", {
|
|
423
|
+
detail: { id: "https://example.com/test/resource1" },
|
|
424
|
+
});
|
|
425
|
+
const saveEvent2 = new CustomEvent("save", {
|
|
426
|
+
detail: { id: "https://example.com/test/resource2" },
|
|
427
|
+
});
|
|
428
|
+
const saveEvent3 = new CustomEvent("save", {
|
|
429
|
+
detail: { id: "https://example.com/test/resource3" },
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
document.dispatchEvent(saveEvent1);
|
|
433
|
+
document.dispatchEvent(saveEvent2);
|
|
434
|
+
document.dispatchEvent(saveEvent3);
|
|
435
|
+
|
|
436
|
+
cy.wait(20).then(() => {
|
|
437
|
+
expect(mockComponent.requestUpdate).to.be.calledOnce;
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
mockComponent._unsubscribe();
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
describe("Event detail resource handling", () => {
|
|
445
|
+
it("should handle resource with @id property", () => {
|
|
446
|
+
const mockComponent = createMockComponent();
|
|
447
|
+
mockComponent.dataSrc = "https://example.com/data";
|
|
448
|
+
mockComponent.hasCachedDatas = true;
|
|
449
|
+
|
|
450
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
451
|
+
|
|
452
|
+
const saveEvent = new CustomEvent("save", {
|
|
453
|
+
detail: {
|
|
454
|
+
resource: { "@id": "https://example.com/test/resource" },
|
|
455
|
+
},
|
|
456
|
+
});
|
|
457
|
+
document.dispatchEvent(saveEvent);
|
|
458
|
+
|
|
459
|
+
cy.window().then((win) => {
|
|
460
|
+
expect((win as any).sibStore.clearCache).to.be.calledOnce;
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
mockComponent._unsubscribe();
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it("should not clear cache when id is missing", () => {
|
|
467
|
+
const mockComponent = createMockComponent();
|
|
468
|
+
mockComponent.dataSrc = "https://example.com/data";
|
|
469
|
+
mockComponent.hasCachedDatas = true;
|
|
470
|
+
|
|
471
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
472
|
+
|
|
473
|
+
const saveEvent = new CustomEvent("save", {
|
|
474
|
+
detail: { resource: { name: "test" } },
|
|
475
|
+
});
|
|
476
|
+
document.dispatchEvent(saveEvent);
|
|
477
|
+
|
|
478
|
+
cy.window().then((win) => {
|
|
479
|
+
expect((win as any).sibStore.clearCache).to.not.be.called;
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
mockComponent._unsubscribe();
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
describe("Component property requirements", () => {
|
|
487
|
+
it("should require component to provide _subscriptions Set", () => {
|
|
488
|
+
const mockComponent: any = {
|
|
489
|
+
_subscriptions: new Set(),
|
|
490
|
+
_subscribe: cy.stub(),
|
|
491
|
+
caching: 0,
|
|
492
|
+
dataSrc: "https://example.com/test/data",
|
|
493
|
+
requestUpdate: cy.stub(),
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
497
|
+
|
|
498
|
+
expect(mockComponent._subscriptions).to.be.an.instanceOf(Set);
|
|
499
|
+
expect(mockComponent._subscriptions.size).to.be.greaterThan(0);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it("should create cacheListener property", () => {
|
|
503
|
+
const mockComponent = createMockComponent();
|
|
504
|
+
|
|
505
|
+
setupCacheInvalidation(mockComponent, { keywords: ["test"] });
|
|
506
|
+
|
|
507
|
+
expect(mockComponent.cacheListener).to.be.a("function");
|
|
508
|
+
|
|
509
|
+
mockComponent._unsubscribe();
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
});
|