@coveo/quantic 3.16.0 → 3.16.1-pre.9c01cf606f

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 (109) hide show
  1. package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +2 -2
  2. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recent-queries-list/headless-recent-queries-list.d.ts +5 -0
  3. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/recent-queries-list/headless-recent-queries-list.d.ts +5 -0
  4. package/force-app/main/default/staticresources/coveoheadless/headless.js +10 -10
  5. package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +2 -2
  6. package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +2 -2
  7. package/package.json +5 -3
  8. package/force-app/main/default/lwc/quanticBreadcrumbManager/__tests__/quanticBreadcrumbManager.test.js +0 -604
  9. package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/fixture.ts +0 -76
  10. package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/pageObject.ts +0 -282
  11. package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/quanticBreadcrumbManager.e2e.ts +0 -167
  12. package/force-app/main/default/lwc/quanticCarousel/__tests__/quanticCarousel.test.js +0 -262
  13. package/force-app/main/default/lwc/quanticCaseClassification/__tests__/quanticCaseClassification.test.js +0 -819
  14. package/force-app/main/default/lwc/quanticCaseClassification/e2e/data.ts +0 -23
  15. package/force-app/main/default/lwc/quanticCaseClassification/e2e/fixture.ts +0 -51
  16. package/force-app/main/default/lwc/quanticCaseClassification/e2e/pageObject.ts +0 -152
  17. package/force-app/main/default/lwc/quanticCaseClassification/e2e/quanticCaseClassification.e2e.ts +0 -269
  18. package/force-app/main/default/lwc/quanticCategoryFacet/__tests__/quanticCategoryFacet.test.js +0 -327
  19. package/force-app/main/default/lwc/quanticCitation/__tests__/quanticCitation.test.js +0 -269
  20. package/force-app/main/default/lwc/quanticColoredResultBadge/__tests__/quanticColoredResultBadge.test.js +0 -212
  21. package/force-app/main/default/lwc/quanticDateFacet/__tests__/quanticDateFacet.test.js +0 -321
  22. package/force-app/main/default/lwc/quanticDidYouMean/__tests__/quanticDidYouMean.test.js +0 -199
  23. package/force-app/main/default/lwc/quanticFacet/__tests__/quanticFacet.test.js +0 -341
  24. package/force-app/main/default/lwc/quanticFacetCaption/__tests__/quanticFacetCaption.test.js +0 -28
  25. package/force-app/main/default/lwc/quanticFacetManager/__tests__/quanticFacetManager.test.js +0 -178
  26. package/force-app/main/default/lwc/quanticFacetManager/e2e/fixture.ts +0 -63
  27. package/force-app/main/default/lwc/quanticFacetManager/e2e/pageObject.ts +0 -23
  28. package/force-app/main/default/lwc/quanticFacetManager/e2e/quanticFacetManager.e2e.ts +0 -82
  29. package/force-app/main/default/lwc/quanticFeedback/__tests__/quanticFeedback.test.js +0 -392
  30. package/force-app/main/default/lwc/quanticFeedbackModal/__tests__/quanticFeedbackModal.test.js +0 -448
  31. package/force-app/main/default/lwc/quanticFeedbackModalQna/__tests__/quanticFeedbackModalQna.test.js +0 -298
  32. package/force-app/main/default/lwc/quanticGeneratedAnswer/__tests__/quanticGeneratedAnswer.test.js +0 -814
  33. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/data.ts +0 -56
  34. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/fixture.ts +0 -87
  35. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/pageObject.ts +0 -283
  36. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/quanticGeneratedAnswer.e2e.ts +0 -199
  37. package/force-app/main/default/lwc/quanticGeneratedAnswerContent/__tests__/quanticGeneratedAnswerContent.test.js +0 -151
  38. package/force-app/main/default/lwc/quanticHeading/__tests__/quanticHeading.test.js +0 -71
  39. package/force-app/main/default/lwc/quanticHeadlessLoader/__tests__/quanticHeadlessLoader.test.js +0 -651
  40. package/force-app/main/default/lwc/quanticNotifications/__tests__/quanticNotifications.test.js +0 -335
  41. package/force-app/main/default/lwc/quanticNumericFacet/__tests__/quanticNumericFacet.test.js +0 -343
  42. package/force-app/main/default/lwc/quanticPager/e2e/fixture.ts +0 -63
  43. package/force-app/main/default/lwc/quanticPager/e2e/pageObject.ts +0 -69
  44. package/force-app/main/default/lwc/quanticPager/e2e/quanticPager.e2e.ts +0 -101
  45. package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/data/defaultTestCase.json +0 -13
  46. package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/data/youtubeTestCase.json +0 -14
  47. package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/quanticQuickviewContent.test.js +0 -82
  48. package/force-app/main/default/lwc/quanticRadioButtonsGroup/__tests__/quanticRadioButtonsGroup.test.js +0 -273
  49. package/force-app/main/default/lwc/quanticRefineModalContent/__tests__/quanticRefineModalContent.test.js +0 -501
  50. package/force-app/main/default/lwc/quanticResultAction/__tests__/quanticResultAction.test.js +0 -262
  51. package/force-app/main/default/lwc/quanticResultActionBar/__tests__/quanticResultActionBar.test.js +0 -141
  52. package/force-app/main/default/lwc/quanticResultChildren/__tests__/quanticResultChildren.test.js +0 -340
  53. package/force-app/main/default/lwc/quanticResultDate/__tests__/quanticResultDate.test.js +0 -144
  54. package/force-app/main/default/lwc/quanticResultField/__tests__/quanticResultField.test.js +0 -120
  55. package/force-app/main/default/lwc/quanticResultHighlightedTextField/__tests__/quanticResultHighlightedTextField.test.js +0 -209
  56. package/force-app/main/default/lwc/quanticResultLink/__tests__/quanticResultLink.test.js +0 -261
  57. package/force-app/main/default/lwc/quanticResultMultiValueText/__tests__/quanticResultMultiValueText.test.js +0 -235
  58. package/force-app/main/default/lwc/quanticResultNumber/__tests__/quanticResultNumber.test.js +0 -144
  59. package/force-app/main/default/lwc/quanticResultPrintableUri/__tests__/quanticResultPrintableUri.test.js +0 -324
  60. package/force-app/main/default/lwc/quanticResultQuickview/__tests__/quanticResultQuickview.test.js +0 -171
  61. package/force-app/main/default/lwc/quanticResultText/__tests__/quanticResultText.test.js +0 -155
  62. package/force-app/main/default/lwc/quanticResultsPerPage/__tests__/quanticResultsPerPage.test.js +0 -404
  63. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/fixture.ts +0 -74
  64. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/pageObject.ts +0 -85
  65. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/quanticResultsPerPage.e2e.ts +0 -97
  66. package/force-app/main/default/lwc/quanticSearchBox/__tests__/quanticSearchBox.test.js +0 -168
  67. package/force-app/main/default/lwc/quanticSearchBoxInput/__tests__/quanticSearchBoxInput.test.js +0 -823
  68. package/force-app/main/default/lwc/quanticSmartSnippet/__tests__/quanticSmartSnippet.test.js +0 -341
  69. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/data.ts +0 -21
  70. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/fixture.ts +0 -91
  71. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/pageObject.ts +0 -196
  72. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/quanticSmartSnippet.e2e.ts +0 -168
  73. package/force-app/main/default/lwc/quanticSmartSnippetAnswer/__tests__/quanticSmartSnippetAnswer.test.js +0 -126
  74. package/force-app/main/default/lwc/quanticSmartSnippetSource/__tests__/quanticSmartSnippetSource.test.js +0 -290
  75. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/__tests__/quanticSmartSnippetSuggestions.test.js +0 -329
  76. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/data.ts +0 -31
  77. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/fixture.ts +0 -93
  78. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/pageObject.ts +0 -160
  79. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/quanticSmartSnippetSuggestions.e2e.ts +0 -127
  80. package/force-app/main/default/lwc/quanticSort/__tests__/quanticSort.test.js +0 -416
  81. package/force-app/main/default/lwc/quanticSort/e2e/fixture.ts +0 -61
  82. package/force-app/main/default/lwc/quanticSort/e2e/pageObject.ts +0 -89
  83. package/force-app/main/default/lwc/quanticSort/e2e/quanticSort.e2e.ts +0 -91
  84. package/force-app/main/default/lwc/quanticSourceCitations/__tests__/quanticSourceCitations.test.js +0 -123
  85. package/force-app/main/default/lwc/quanticStandaloneSearchBox/__tests__/quanticStandaloneSearchBox.test.js +0 -186
  86. package/force-app/main/default/lwc/quanticStatefulButton/__tests__/quanticStatefulButton.test.js +0 -222
  87. package/force-app/main/default/lwc/quanticTab/__tests__/quanticTab.test.js +0 -287
  88. package/force-app/main/default/lwc/quanticTab/e2e/fixture.ts +0 -62
  89. package/force-app/main/default/lwc/quanticTab/e2e/pageObject.ts +0 -67
  90. package/force-app/main/default/lwc/quanticTab/e2e/quanticTab.e2e.ts +0 -77
  91. package/force-app/main/default/lwc/quanticTabBar/__tests__/quanticTabBar.test.js +0 -331
  92. package/force-app/main/default/lwc/quanticTabBar/e2e/fixture.ts +0 -61
  93. package/force-app/main/default/lwc/quanticTabBar/e2e/pageObject.ts +0 -80
  94. package/force-app/main/default/lwc/quanticTabBar/e2e/quanticTabBar.e2e.ts +0 -173
  95. package/force-app/main/default/lwc/quanticTimeframeFacet/__tests__/quanticTimeframeFacet.test.js +0 -339
  96. package/force-app/main/default/lwc/quanticTooltip/__tests__/quanticTooltip.test.js +0 -107
  97. package/force-app/main/default/lwc/quanticUserAction/__tests__/quanticUserAction.test.js +0 -427
  98. package/force-app/main/default/lwc/quanticUserActionsSession/__tests__/quanticUserActionsSession.test.js +0 -269
  99. package/force-app/main/default/lwc/quanticUserActionsTimeline/__tests__/data/userActionsState.json +0 -89
  100. package/force-app/main/default/lwc/quanticUserActionsTimeline/__tests__/quanticUserActionsTimeline.test.js +0 -511
  101. package/force-app/main/default/lwc/quanticUserActionsToggle/__tests__/quanticUserActionsToggle.test.js +0 -229
  102. package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/data.ts +0 -32
  103. package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/fixture.ts +0 -32
  104. package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/pageObject.ts +0 -71
  105. package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/quanticUserActionsToggle.e2e.ts +0 -39
  106. package/force-app/main/default/lwc/quanticUtils/__tests__/facetDependenciesUtils.test.js +0 -92
  107. package/force-app/main/default/lwc/quanticUtils/__tests__/markdownUtils.test.js +0 -71
  108. package/force-app/main/default/lwc/quanticUtils/__tests__/quanticUtils.test.js +0 -223
  109. package/force-app/main/default/lwc/quanticViewedByCustomerBadge/__tests__/quanticViewedByCustomerBadge.test.js +0 -131
@@ -1,340 +0,0 @@
1
- /* eslint-disable jest/expect-expect */
2
- // @ts-ignore
3
- import {createElement} from 'lwc';
4
- import QuanticResultChildren from '../quanticResultChildren';
5
-
6
- const loadRelatedItems = 'Load related items';
7
- const hideRelatedItems = 'Hide related items';
8
- jest.mock(
9
- '@salesforce/label/c.quantic_LoadRelatedItems',
10
- () => ({default: loadRelatedItems}),
11
- {
12
- virtual: true,
13
- }
14
- );
15
- jest.mock(
16
- '@salesforce/label/c.quantic_HideRelatedItems',
17
- () => ({default: hideRelatedItems}),
18
- {
19
- virtual: true,
20
- }
21
- );
22
-
23
- const functionsMocks = {
24
- loadCollection: jest.fn(() => {}),
25
- logShowLessFoldedResults: jest.fn(() => {}),
26
- logShowMoreFoldedResults: jest.fn(() => {}),
27
- };
28
-
29
- const mockedFoldedResultListController = {
30
- loadCollection: functionsMocks.loadCollection,
31
- logShowLessFoldedResults: functionsMocks.logShowLessFoldedResults,
32
- logShowMoreFoldedResults: functionsMocks.logShowMoreFoldedResults,
33
- };
34
-
35
- const selectors = {
36
- quanticResult: 'c-quantic-result',
37
- toggleButton: '.result-children__toggle-button lightning-button',
38
- placeholder: 'c-quantic-placeholder',
39
- noMoreChildrenMessage: '.result-children__no-more-children-message',
40
- };
41
-
42
- const exampleFoldedResultOne = {
43
- result: {
44
- uniqueId: '123',
45
- title: 'example result one',
46
- },
47
- children: [],
48
- };
49
- const exampleFoldedResultTwo = {
50
- result: {
51
- uniqueId: '456',
52
- title: 'example result two',
53
- },
54
- children: [],
55
- };
56
- const exampleEngineId = 'example engine id';
57
- const exampleTemplateId = 'example template id';
58
- const exampleCollection = {
59
- result: {
60
- uniqueId: '789',
61
- title: 'example parent result',
62
- },
63
- children: [exampleFoldedResultOne],
64
- isLoadingMoreResults: false,
65
- moreResultsAvailable: true,
66
- };
67
- const exampleCollectionWithAllResultsLoaded = {
68
- ...exampleCollection,
69
- children: [exampleFoldedResultOne, exampleFoldedResultTwo],
70
- isLoadingMoreResults: false,
71
- moreResultsAvailable: false,
72
- };
73
- const exampleCollectionWithAdditionalGrandChild = {
74
- ...exampleCollection,
75
- children: [
76
- {
77
- ...exampleFoldedResultOne,
78
- children: [...exampleFoldedResultOne.children, exampleFoldedResultTwo],
79
- },
80
- ],
81
- isLoadingMoreResults: false,
82
- moreResultsAvailable: false,
83
- };
84
- const exampleCollectionWithNoMoreResults = {
85
- ...exampleCollection,
86
- moreResultsAvailable: false,
87
- };
88
-
89
- const defaultOptions = {
90
- engineId: exampleEngineId,
91
- templateId: exampleTemplateId,
92
- foldedResultListController: mockedFoldedResultListController,
93
- collection: exampleCollection,
94
- };
95
-
96
- function createTestComponent(options = defaultOptions) {
97
- const element = createElement('c-quantic-result-children', {
98
- is: QuanticResultChildren,
99
- });
100
-
101
- Object.assign(element, options);
102
-
103
- document.body.appendChild(element);
104
- return element;
105
- }
106
-
107
- // Helper function to wait until the microtask queue is empty.
108
- function flushPromises() {
109
- return new Promise((resolve) => setTimeout(resolve, 0));
110
- }
111
-
112
- function cleanup() {
113
- jest.clearAllMocks();
114
- // The jsdom instance is shared across test cases in a single file so reset the DOM
115
- while (document.body.firstChild) {
116
- document.body.removeChild(document.body.firstChild);
117
- }
118
- }
119
-
120
- function expectProperChildResultsDisplay(element, collection) {
121
- const childResults = element.shadowRoot.querySelectorAll(
122
- selectors.quanticResult
123
- );
124
- expect(childResults.length).toBe(collection.children.length);
125
- collection.children.forEach((foldedResult, index) => {
126
- expect(childResults[index].engineId).toBe(exampleEngineId);
127
- expect(childResults[index].templateId).toBe(exampleTemplateId);
128
- expect(childResults[index].result).toEqual(foldedResult.result);
129
- expect(childResults[index].collection).toEqual(foldedResult);
130
- });
131
- }
132
-
133
- async function clickFoldedResultToggleButton(element, label) {
134
- const foldedResultToggleButton = element.shadowRoot.querySelector(
135
- selectors.toggleButton
136
- );
137
- expect(foldedResultToggleButton).not.toBeNull();
138
- expect(foldedResultToggleButton.label).toBe(label);
139
- foldedResultToggleButton.click();
140
- await flushPromises();
141
- }
142
-
143
- describe('c-quantic-result-children', () => {
144
- afterEach(() => {
145
- cleanup();
146
- });
147
-
148
- describe('when there are no child results available in the collection', () => {
149
- it('should not display any child results and the no more child results message', async () => {
150
- const element = createTestComponent({
151
- ...defaultOptions,
152
- collection: {
153
- ...exampleCollection,
154
- moreResultsAvailable: false,
155
- children: [],
156
- },
157
- });
158
- await flushPromises();
159
-
160
- const childResult = element.shadowRoot.querySelector(
161
- selectors.quanticResult
162
- );
163
-
164
- const noMoreChildrenMessage = element.shadowRoot.querySelector(
165
- selectors.noMoreChildrenMessage
166
- );
167
-
168
- expect(childResult).toBeNull();
169
- expect(noMoreChildrenMessage).toBeNull();
170
- });
171
- });
172
-
173
- describe('when there are more child results available in the collection', () => {
174
- it('should display the first partition of the child results', async () => {
175
- const element = createTestComponent();
176
- await flushPromises();
177
-
178
- expectProperChildResultsDisplay(element, exampleCollection);
179
- });
180
-
181
- describe('when more child results are expanded or collapsed', () => {
182
- describe('when the child results are being loaded', () => {
183
- it('should display the result placeholder', async () => {
184
- const element = createTestComponent();
185
- await flushPromises();
186
-
187
- await clickFoldedResultToggleButton(element, loadRelatedItems);
188
- element.collection = {
189
- ...exampleCollection,
190
- isLoadingMoreResults: true,
191
- };
192
- await flushPromises();
193
-
194
- const placeholder = element.shadowRoot.querySelector(
195
- selectors.placeholder
196
- );
197
- expect(placeholder.numberOfRows).toBe(
198
- exampleCollection.children.length
199
- );
200
- });
201
- });
202
-
203
- it('should call the right actions and properly display the child results', async () => {
204
- const element = createTestComponent();
205
- await flushPromises();
206
- const foldedResultToggleButton = element.shadowRoot.querySelector(
207
- selectors.toggleButton
208
- );
209
-
210
- await clickFoldedResultToggleButton(element, loadRelatedItems);
211
- expect(functionsMocks.loadCollection).toHaveBeenCalledTimes(1);
212
- element.collection = exampleCollectionWithAllResultsLoaded;
213
- await flushPromises();
214
- expectProperChildResultsDisplay(
215
- element,
216
- exampleCollectionWithAllResultsLoaded
217
- );
218
-
219
- await clickFoldedResultToggleButton(element, hideRelatedItems);
220
- expect(functionsMocks.logShowLessFoldedResults).toHaveBeenCalledTimes(
221
- 1
222
- );
223
- expectProperChildResultsDisplay(element, exampleCollection);
224
-
225
- await clickFoldedResultToggleButton(element, loadRelatedItems);
226
- expect(functionsMocks.logShowMoreFoldedResults).toHaveBeenCalledTimes(
227
- 1
228
- );
229
- expectProperChildResultsDisplay(
230
- element,
231
- exampleCollectionWithAllResultsLoaded
232
- );
233
- expect(foldedResultToggleButton.label).toBe(hideRelatedItems);
234
- });
235
-
236
- describe('when only grand children are available in the collection', () => {
237
- it('should properly display the expanded child results', async () => {
238
- const element = createTestComponent();
239
- await flushPromises();
240
- const foldedResultToggleButton = element.shadowRoot.querySelector(
241
- selectors.toggleButton
242
- );
243
-
244
- await clickFoldedResultToggleButton(element, loadRelatedItems);
245
- expect(functionsMocks.loadCollection).toHaveBeenCalledTimes(1);
246
- element.collection = exampleCollectionWithAdditionalGrandChild;
247
- await flushPromises();
248
- expectProperChildResultsDisplay(
249
- element,
250
- exampleCollectionWithAdditionalGrandChild
251
- );
252
-
253
- const noMoreChildrenMessage = element.shadowRoot.querySelector(
254
- selectors.noMoreChildrenMessage
255
- );
256
- expect(noMoreChildrenMessage).toBeNull();
257
- expect(foldedResultToggleButton.label).toBe(hideRelatedItems);
258
- });
259
- });
260
- });
261
- });
262
-
263
- describe('when there are no more child results available in the collection', () => {
264
- it('should display the first partition of the child results', async () => {
265
- const element = createTestComponent();
266
- await flushPromises();
267
-
268
- expectProperChildResultsDisplay(element, exampleCollection);
269
- });
270
-
271
- describe('when trying to load more child results', () => {
272
- it('should display the no more child results message', async () => {
273
- const element = createTestComponent();
274
- await flushPromises();
275
-
276
- await clickFoldedResultToggleButton(element, loadRelatedItems);
277
- element.collection = {
278
- ...exampleCollection,
279
- moreResultsAvailable: false,
280
- };
281
- await flushPromises();
282
-
283
- const foldedResultToggleButton = element.shadowRoot.querySelector(
284
- selectors.toggleButton
285
- );
286
- const noMoreChildrenMessage = element.shadowRoot.querySelector(
287
- selectors.noMoreChildrenMessage
288
- );
289
-
290
- expect(functionsMocks.loadCollection).toHaveBeenCalledTimes(1);
291
- expectProperChildResultsDisplay(element, exampleCollection);
292
- expect(foldedResultToggleButton).toBeNull();
293
- expect(noMoreChildrenMessage).not.toBeNull();
294
- });
295
- });
296
-
297
- describe('when executing a search query after loading the child results', () => {
298
- it('should no longer display the no more child results message and display the child results toggle', async () => {
299
- const element = createTestComponent();
300
- await flushPromises();
301
-
302
- await clickFoldedResultToggleButton(element, loadRelatedItems);
303
-
304
- expect(functionsMocks.loadCollection).toHaveBeenCalledTimes(1);
305
- element.collection = exampleCollectionWithNoMoreResults;
306
- await flushPromises();
307
-
308
- let foldedResultToggleButton = element.shadowRoot.querySelector(
309
- selectors.toggleButton
310
- );
311
- let noMoreChildrenMessage = element.shadowRoot.querySelector(
312
- selectors.noMoreChildrenMessage
313
- );
314
-
315
- expectProperChildResultsDisplay(
316
- element,
317
- exampleCollectionWithNoMoreResults
318
- );
319
- expect(foldedResultToggleButton).toBeNull();
320
- expect(noMoreChildrenMessage).not.toBeNull();
321
-
322
- // Simulates new search query
323
- element.collection = exampleCollection;
324
- await flushPromises();
325
-
326
- foldedResultToggleButton = element.shadowRoot.querySelector(
327
- selectors.toggleButton
328
- );
329
- noMoreChildrenMessage = element.shadowRoot.querySelector(
330
- selectors.noMoreChildrenMessage
331
- );
332
-
333
- expectProperChildResultsDisplay(element, exampleCollection);
334
- expect(foldedResultToggleButton).not.toBeNull();
335
- expect(noMoreChildrenMessage).toBeNull();
336
- expect(foldedResultToggleButton.label).toBe(loadRelatedItems);
337
- });
338
- });
339
- });
340
- });
@@ -1,144 +0,0 @@
1
- // @ts-ignore
2
- import {createElement} from 'lwc';
3
- import QuanticResultDate from '../quanticResultDate';
4
-
5
- const exampleField = 'exampledatefield';
6
- const exampleFieldValue = 1670118414000;
7
- const exampleResult = {
8
- raw: {
9
- [exampleField]: exampleFieldValue,
10
- },
11
- };
12
-
13
- const errorSelector = '.error-message';
14
-
15
- const defaultOptions = {
16
- result: exampleResult,
17
- field: exampleField,
18
- };
19
-
20
- function createTestComponent(options = defaultOptions) {
21
- const element = createElement('c-quantic-result-date', {
22
- is: QuanticResultDate,
23
- });
24
-
25
- for (const [key, value] of Object.entries(options)) {
26
- element[key] = value;
27
- }
28
-
29
- document.body.appendChild(element);
30
- return element;
31
- }
32
-
33
- // Helper function to wait until the microtask queue is empty.
34
- function flushPromises() {
35
- return new Promise((resolve) => setTimeout(resolve, 0));
36
- }
37
-
38
- describe('c-quantic-result-date', () => {
39
- function cleanup() {
40
- // The jsdom instance is shared across test cases in a single file so reset the DOM
41
- while (document.body.firstChild) {
42
- document.body.removeChild(document.body.firstChild);
43
- }
44
- jest.clearAllMocks();
45
- }
46
-
47
- beforeEach(() => {
48
- console.error = jest.fn();
49
- // @ts-ignore
50
- global.Bueno = {
51
- isString: jest
52
- .fn()
53
- .mockImplementation(
54
- (value) => Object.prototype.toString.call(value) === '[object String]'
55
- ),
56
- isNumber: jest
57
- .fn()
58
- .mockImplementation(
59
- (value) => typeof value === 'number' && !isNaN(value)
60
- ),
61
- };
62
- });
63
-
64
- afterEach(() => {
65
- cleanup();
66
- });
67
-
68
- describe('when no result is given', () => {
69
- it('should show an error', async () => {
70
- // @ts-ignore
71
- const element = createTestComponent({field: exampleField});
72
- await flushPromises();
73
- const errorMessage = element.shadowRoot.querySelector(errorSelector);
74
-
75
- expect(errorMessage).not.toBeNull();
76
- expect(console.error).toHaveBeenCalledWith(
77
- 'The c-quantic-result-date requires a result and a date field to be specified.'
78
- );
79
- expect(console.error).toHaveBeenCalledWith(
80
- 'The "exampledatefield" field value is not a valid timestamp.'
81
- );
82
- });
83
- });
84
-
85
- describe('when no field is given', () => {
86
- it('should show an error', async () => {
87
- // @ts-ignore
88
- const element = createTestComponent({result: exampleResult});
89
- await flushPromises();
90
-
91
- const errorMessage = element.shadowRoot.querySelector(errorSelector);
92
-
93
- expect(errorMessage).not.toBeNull();
94
- expect(console.error).toHaveBeenCalledWith(
95
- 'The c-quantic-result-date requires a result and a date field to be specified.'
96
- );
97
- expect(console.error).toHaveBeenCalledWith(
98
- 'The "undefined" field value is not a valid timestamp.'
99
- );
100
- });
101
- });
102
-
103
- describe('when the field value is not a valid timestamp', () => {
104
- const invalidValue = 'not-a-timestamp';
105
- const invalidOptions = {
106
- ...defaultOptions,
107
- result: {
108
- raw: {
109
- [exampleField]: invalidValue,
110
- },
111
- },
112
- };
113
-
114
- it('should show an error', async () => {
115
- // @ts-ignore
116
- const element = createTestComponent(invalidOptions);
117
- await flushPromises();
118
-
119
- const errorMessage = element.shadowRoot.querySelector(errorSelector);
120
-
121
- expect(errorMessage).not.toBeNull();
122
- });
123
- });
124
-
125
- describe('when a formatting function is given', () => {
126
- let formattingFunctionMock;
127
-
128
- beforeEach(() => {
129
- formattingFunctionMock = jest
130
- .fn()
131
- .mockImplementation((value) => `formatted ${value}`);
132
- });
133
-
134
- it('should render the formatted field value', async () => {
135
- createTestComponent({
136
- ...defaultOptions,
137
- formattingFunction: formattingFunctionMock,
138
- });
139
- await flushPromises();
140
-
141
- expect(formattingFunctionMock).toHaveBeenCalledWith(exampleFieldValue);
142
- });
143
- });
144
- });
@@ -1,120 +0,0 @@
1
- // @ts-ignore
2
- import {createElement} from 'lwc';
3
- import QuanticResultField from '../quanticResultField';
4
-
5
- const invalidType = 'invalid type';
6
-
7
- const fieldTypes = [
8
- {
9
- name: 'string',
10
- element: 'c-quantic-result-text',
11
- },
12
- {
13
- name: 'date',
14
- element: 'c-quantic-result-date',
15
- },
16
- {
17
- name: 'number',
18
- element: 'c-quantic-result-number',
19
- },
20
- {
21
- name: 'multi',
22
- element: 'c-quantic-result-multi-value-text',
23
- },
24
- ];
25
-
26
- const defaultOptions = {
27
- result: {
28
- raw: {
29
- testField: 'test value',
30
- },
31
- },
32
- field: 'testField',
33
- label: 'test label',
34
- type: 'string',
35
- };
36
-
37
- function createTestComponent(options = defaultOptions) {
38
- const element = createElement('c-quantic-result-field', {
39
- is: QuanticResultField,
40
- });
41
-
42
- for (const [key, value] of Object.entries(options)) {
43
- element[key] = value;
44
- }
45
-
46
- document.body.appendChild(element);
47
- return element;
48
- }
49
-
50
- // Helper function to wait until the microtask queue is empty.
51
- function flushPromises() {
52
- return new Promise((resolve) => setTimeout(resolve, 0));
53
- }
54
-
55
- function cleanup() {
56
- // The jsdom instance is shared across test cases in a single file so reset the DOM
57
- while (document.body.firstChild) {
58
- document.body.removeChild(document.body.firstChild);
59
- }
60
- }
61
-
62
- describe('c-quantic-result-field', () => {
63
- beforeEach(() => {
64
- console.error = jest.fn();
65
- // @ts-ignore
66
- global.Bueno = {
67
- isString: jest
68
- .fn()
69
- .mockImplementation(
70
- (value) => Object.prototype.toString.call(value) === '[object String]'
71
- ),
72
- isNumber: jest
73
- .fn()
74
- .mockImplementation(
75
- (value) => typeof value === 'number' && !isNaN(value)
76
- ),
77
- };
78
- });
79
-
80
- afterEach(() => {
81
- cleanup();
82
- });
83
-
84
- describe('when the field type is invalid', () => {
85
- it('should display an error', async () => {
86
- const element = createTestComponent({
87
- ...defaultOptions,
88
- type: invalidType,
89
- });
90
- await flushPromises();
91
-
92
- const error = element.shadowRoot.querySelector('.error-message');
93
-
94
- expect(error).not.toBeNull();
95
- expect(error.textContent).toBe('c-quantic-result-field Error');
96
- expect(console.error).toHaveBeenCalledWith(
97
- `The provided type "${invalidType}" is invalid. The type must be one of multi | number | date | string`
98
- );
99
- });
100
- });
101
-
102
- fieldTypes.forEach((fieldType) => {
103
- it(`should correctly display the result field of type ${fieldType.name} value`, async () => {
104
- const element = createTestComponent({
105
- ...defaultOptions,
106
- type: fieldType.name,
107
- });
108
- await flushPromises();
109
-
110
- const fieldComponent = element.shadowRoot.querySelector(
111
- fieldType.element
112
- );
113
- const {label, field} = fieldComponent;
114
-
115
- expect(fieldComponent).not.toBeNull();
116
- expect(label).toBe(defaultOptions.label);
117
- expect(field).toBe(defaultOptions.field);
118
- });
119
- });
120
- });