@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,651 +0,0 @@
1
- /* eslint-disable jest/expect-expect */
2
- // @ts-ignore
3
- import LightningAlert from 'lightning/alert';
4
- import {Deferred} from '../../quanticUtils/quanticUtils';
5
- import {
6
- setInitializedCallback,
7
- setEngineOptions,
8
- registerComponentForInit,
9
- setComponentInitialized,
10
- getHeadlessEnginePromise,
11
- initializeWithHeadless,
12
- destroyEngine,
13
- registerToStore,
14
- getFromStore,
15
- registerSortOptionsToStore,
16
- getAllSortOptionsFromStore,
17
- } from '../quanticHeadlessLoader';
18
-
19
- jest.mock('lightning/alert');
20
-
21
- describe('c/quanticHeadlessLoader', () => {
22
- const CoveoHeadlessStub = {
23
- buildSearchEngine: function () {
24
- return {
25
- executeFirstSearch: jest.fn(() => {}),
26
- };
27
- },
28
- };
29
-
30
- const testOptions = {
31
- configuration: {
32
- organizationId: 'testOrganization',
33
- accessToken: 'bogus-token-xxxxx-xxxxx',
34
- search: {
35
- pipeline: 'default',
36
- searchHub: 'default',
37
- },
38
- },
39
- };
40
-
41
- let resolvedTestConfig;
42
- let mockedConsoleWarn;
43
- let mockedConsoleError;
44
- let initialize;
45
- let testId = 'search-page-1';
46
-
47
- let testElement;
48
-
49
- let mockEngineConstructor;
50
-
51
- const createComponentEntryWithInitStatus = (isInitialized) => ({
52
- element: document.createElement('div'),
53
- initialized: isInitialized,
54
- });
55
-
56
- const assertComponentIsSetInitialized = (element, engineId) => {
57
- expect(window.coveoHeadless[engineId].components).toContainEqual({
58
- element,
59
- initialized: true,
60
- });
61
- };
62
-
63
- /**
64
- * @param {string | number} id
65
- * @param {Record<String, unknown>} store
66
- */
67
- function initQuanticStoreTest(id, store) {
68
- window.coveoHeadless[id].bindings.store = store;
69
- }
70
-
71
- beforeEach(() => {
72
- jest.useFakeTimers();
73
- initialize = jest.fn();
74
- mockEngineConstructor = jest
75
- .fn()
76
- .mockReturnValue(CoveoHeadlessStub.buildSearchEngine());
77
- mockedConsoleWarn = jest.fn();
78
- mockedConsoleError = jest.fn();
79
- console.warn = mockedConsoleWarn;
80
- console.error = mockedConsoleError;
81
- global.CoveoHeadless = CoveoHeadlessStub;
82
- testElement = document.createElement('div');
83
- resolvedTestConfig = new Deferred();
84
- resolvedTestConfig.resolve(testOptions);
85
- });
86
-
87
- afterEach(() => {
88
- delete window.coveoHeadless;
89
- jest.clearAllMocks();
90
- jest.restoreAllMocks();
91
- });
92
-
93
- describe('setInitializedCallback', () => {
94
- beforeEach(() => {
95
- window.coveoHeadless = {
96
- [testId]: {},
97
- };
98
- });
99
-
100
- it('should define callback for specified engine', async () => {
101
- const testCallback = () => {};
102
- setInitializedCallback(testCallback, testId);
103
-
104
- expect(await window.coveoHeadless[testId].initializedCallback).toBe(
105
- testCallback
106
- );
107
- });
108
- });
109
-
110
- describe('setEngineOptions', () => {
111
- describe('when coveoHeadless is undefined', () => {
112
- it('should define coveoHeadless and set options', async () => {
113
- setEngineOptions(
114
- testOptions,
115
- mockEngineConstructor,
116
- testId,
117
- testElement
118
- );
119
-
120
- expect(await window.coveoHeadless[testId].options.promise).toBe(
121
- testOptions
122
- );
123
- });
124
- });
125
-
126
- describe('when coveoHeadless is defined', () => {
127
- beforeEach(() => {
128
- window.coveoHeadless = {};
129
- });
130
-
131
- it('should set options', async () => {
132
- setEngineOptions(
133
- testOptions,
134
- mockEngineConstructor,
135
- testId,
136
- testElement
137
- );
138
-
139
- expect(await window.coveoHeadless[testId].options.promise).toBe(
140
- testOptions
141
- );
142
- });
143
-
144
- describe('when options are already preset', () => {
145
- beforeEach(() => {
146
- window.coveoHeadless[testId] = {
147
- options: resolvedTestConfig,
148
- };
149
- });
150
-
151
- it('should log a warning', () => {
152
- const newOptions = {
153
- configuration: {
154
- organizationId: 'otherOrganization',
155
- accessToken: 'bogus-token-xxxxx-ooooo',
156
- },
157
- };
158
-
159
- setEngineOptions(
160
- newOptions,
161
- mockEngineConstructor,
162
- testId,
163
- testElement
164
- );
165
-
166
- expect(mockedConsoleWarn).toHaveBeenCalledWith(
167
- `Attempted to overwrite engine options for engine ID: ${testId}`
168
- );
169
- });
170
- });
171
- });
172
- });
173
-
174
- describe('registerComponentForInit', () => {
175
- const assertComponentIsRegistered = (element) => {
176
- expect(window.coveoHeadless[testId].components).toContainEqual({
177
- element,
178
- initialized: false,
179
- });
180
- };
181
-
182
- describe('when coveoHeadless is undefined', () => {
183
- it('should define coveoHeadless and register component', () => {
184
- registerComponentForInit(testElement, testId);
185
-
186
- assertComponentIsRegistered(testElement);
187
- });
188
- });
189
-
190
- describe('when coveoHeadless is defined', () => {
191
- beforeEach(() => {
192
- window.coveoHeadless = {
193
- [testId]: {
194
- components: [],
195
- engine: CoveoHeadlessStub.buildSearchEngine(),
196
- },
197
- };
198
- });
199
-
200
- describe('when no search is pending', () => {
201
- it('should register the component', () => {
202
- registerComponentForInit(testElement, testId);
203
-
204
- assertComponentIsRegistered(testElement);
205
- });
206
-
207
- it('should not register the component if it already is', () => {
208
- window.coveoHeadless[testId].components.push({
209
- element: testElement,
210
- initialized: false,
211
- });
212
- const mockedPush = jest.fn();
213
- window.coveoHeadless[testId].components.push = mockedPush;
214
-
215
- registerComponentForInit(testElement, testId);
216
-
217
- expect(mockedPush).not.toHaveBeenCalled();
218
- });
219
- });
220
- });
221
- });
222
-
223
- describe('setComponentInitialized', () => {
224
- describe('when coveoHeadless is undefined', () => {
225
- it('should log an error', () => {
226
- expect(() => setComponentInitialized(testElement, testId)).toThrow(
227
- 'Fatal Error: Component was not registered before initialization'
228
- );
229
- });
230
- });
231
-
232
- describe('when coveoHeadless is defined', () => {
233
- beforeEach(() => {
234
- window.coveoHeadless = {
235
- [testId]: {
236
- components: [],
237
- engine: Promise.resolve(CoveoHeadlessStub.buildSearchEngine()),
238
- options: new Deferred(),
239
- },
240
- };
241
- });
242
-
243
- describe('when other components are still uninitialized', () => {
244
- beforeEach(() => {
245
- window.coveoHeadless[testId].components = [
246
- {
247
- element: testElement,
248
- initialized: false,
249
- },
250
- createComponentEntryWithInitStatus(false),
251
- ];
252
- });
253
-
254
- it('should set the component to initialized', async () => {
255
- setComponentInitialized(testElement, testId);
256
-
257
- assertComponentIsSetInitialized(testElement, testId);
258
- });
259
-
260
- it('should not execute initialization callback', async () => {
261
- setComponentInitialized(testElement, testId);
262
-
263
- jest.runAllTimers();
264
- const engine = await window.coveoHeadless[testId].engine;
265
- expect(engine.executeFirstSearch).not.toHaveBeenCalled();
266
- });
267
- });
268
-
269
- describe('when other components are initialized', () => {
270
- beforeEach(() => {
271
- window.coveoHeadless[testId].components = [
272
- {
273
- element: testElement,
274
- initialized: false,
275
- },
276
- createComponentEntryWithInitStatus(true),
277
- ];
278
- });
279
-
280
- it('should set the component to initialized', async () => {
281
- setComponentInitialized(testElement, testId);
282
-
283
- assertComponentIsSetInitialized(testElement, testId);
284
- });
285
-
286
- describe('when initialized callback is set', () => {
287
- const callbackMock = jest.fn();
288
- beforeEach(() => {
289
- window.coveoHeadless[testId].initializedCallback = callbackMock;
290
- });
291
-
292
- it('should set the component to initialized and execute delayed initalized callback', async () => {
293
- setComponentInitialized(testElement, testId);
294
-
295
- assertComponentIsSetInitialized(testElement, testId);
296
- jest.runAllTimers();
297
- await window.coveoHeadless.engine;
298
- expect(callbackMock).toHaveBeenCalled();
299
- });
300
- });
301
- });
302
- });
303
- });
304
-
305
- describe('getHeadlessEnginePromise', () => {
306
- describe('when the engine is undefined with a set options', () => {
307
- beforeEach(() => {
308
- window.coveoHeadless = {
309
- [testId]: {
310
- components: [],
311
- options: resolvedTestConfig,
312
- engineConstructor: mockEngineConstructor,
313
- bindings: {},
314
- },
315
- };
316
- });
317
-
318
- it('should init the engine and return a promise', async () => {
319
- const engine = await getHeadlessEnginePromise(testId);
320
- expect(mockEngineConstructor).toHaveBeenCalled();
321
- expect(engine).toBeTruthy();
322
- });
323
- });
324
-
325
- describe('when the engine is undefined without a set options', () => {
326
- beforeEach(() => {
327
- window.coveoHeadless = {
328
- [testId]: {
329
- components: [],
330
- bindings: {},
331
- },
332
- };
333
- });
334
-
335
- it('should throw an error specifying options have not been set', async () => {
336
- let caughtError;
337
- try {
338
- await getHeadlessEnginePromise(testId);
339
- } catch (error) {
340
- caughtError = error.message;
341
- }
342
-
343
- expect(caughtError).toContain('Engine options have not been set.');
344
- });
345
- });
346
-
347
- describe('when the engine is defined', () => {
348
- const definedEngine = {
349
- isDefined: true,
350
- };
351
-
352
- beforeEach(() => {
353
- window.coveoHeadless = {
354
- [testId]: {
355
- components: [],
356
- enginePromise: Promise.resolve(definedEngine),
357
- engineConstructor: mockEngineConstructor,
358
- bindings: {},
359
- },
360
- };
361
- });
362
-
363
- it('should return a promise that resolves to an instance of the engine', async () => {
364
- const engine = await getHeadlessEnginePromise(testId);
365
-
366
- expect(engine).toEqual(definedEngine);
367
- });
368
- });
369
- });
370
-
371
- describe('initializeWithHeadless', () => {
372
- describe('when the engine is undefined', () => {
373
- beforeEach(() => {
374
- window.coveoHeadless = {
375
- [testId]: {
376
- components: [
377
- {
378
- element: testElement,
379
- initialized: false,
380
- },
381
- ],
382
- engineConstructor: mockEngineConstructor,
383
- options: resolvedTestConfig,
384
- bindings: {},
385
- },
386
- };
387
- });
388
-
389
- it('should init the engine and initialize', async () => {
390
- await initializeWithHeadless(testElement, testId, initialize);
391
- const engine = await window.coveoHeadless[testId].enginePromise;
392
-
393
- expect(engine).toBeTruthy();
394
- expect(initialize).toHaveBeenCalled();
395
- assertComponentIsSetInitialized(testElement, testId);
396
- });
397
-
398
- describe('when initializing the engine fails', () => {
399
- const errorMessage = 'simulating failure';
400
- beforeEach(() => {
401
- LightningAlert.open = jest.fn().mockResolvedValue();
402
- window.coveoHeadless[testId].options = new Deferred();
403
- window.coveoHeadless[testId].options.reject(errorMessage);
404
- });
405
-
406
- it('should throw an error and open the error dialog', async () => {
407
- let caughtError;
408
- initializeWithHeadless(testElement, testId, initialize);
409
- try {
410
- await window.coveoHeadless[testId].enginePromise;
411
- } catch (error) {
412
- caughtError = error.message;
413
- }
414
-
415
- expect(caughtError).toContain(errorMessage);
416
- expect(LightningAlert.open).toHaveBeenCalledTimes(1);
417
- });
418
- });
419
- });
420
-
421
- describe('when the engine is defined', () => {
422
- const definedEngine = {
423
- isDefined: true,
424
- };
425
- beforeEach(() => {
426
- window.coveoHeadless = {
427
- [testId]: {
428
- components: [
429
- {
430
- element: testElement,
431
- initialized: false,
432
- },
433
- ],
434
- options: resolvedTestConfig,
435
- enginePromise: Promise.resolve(definedEngine),
436
- engineConstructor: mockEngineConstructor,
437
- bindings: {},
438
- },
439
- };
440
- });
441
-
442
- it('should initialize the component using the defined engine', async () => {
443
- await initializeWithHeadless(testElement, testId, initialize);
444
- const engine = await window.coveoHeadless[testId].enginePromise;
445
-
446
- expect(engine).toEqual(definedEngine);
447
- expect(initialize).toHaveBeenCalled();
448
- assertComponentIsSetInitialized(testElement, testId);
449
- });
450
- });
451
- });
452
-
453
- describe('destroyEngine', () => {
454
- const otherId = 'other-id';
455
- beforeEach(() => {
456
- window.coveoHeadless = {
457
- [testId]: {},
458
- [otherId]: {},
459
- };
460
- });
461
- it('should clear the engine instance from window object', () => {
462
- destroyEngine(testId);
463
-
464
- expect(window.coveoHeadless[testId]).not.toBeDefined();
465
- });
466
-
467
- it('should not clear other engine instances than the one with specified ID', () => {
468
- destroyEngine(testId);
469
-
470
- expect(window.coveoHeadless[otherId]).toBeDefined();
471
- });
472
-
473
- it('should do nothing if the engine does not exist', () => {
474
- destroyEngine('non-existing-engine');
475
-
476
- expect(window.coveoHeadless[testId]).toEqual({});
477
- });
478
- });
479
-
480
- describe('registerToStore', () => {
481
- beforeEach(() => {
482
- window.coveoHeadless = {
483
- [testId]: {
484
- bindings: {},
485
- },
486
- };
487
- });
488
-
489
- it('should log an error when store is undefined', () => {
490
- initQuanticStoreTest(testId, undefined);
491
- registerToStore(testId, 'someFacets', {label: '', facetId: ''});
492
-
493
- expect(window.coveoHeadless[testId].bindings.store).not.toBeDefined();
494
- expect(mockedConsoleError.mock.calls.length).toBe(1);
495
- });
496
-
497
- it('should log an error when store is empty', () => {
498
- initQuanticStoreTest(testId, {});
499
- registerToStore(testId, 'someFacets', {label: '', facetId: ''});
500
-
501
- expect(window.coveoHeadless[testId].bindings.store).toStrictEqual({});
502
- expect(mockedConsoleError.mock.calls.length).toBe(1);
503
- });
504
-
505
- it('should register the facet data in the store', () => {
506
- initQuanticStoreTest(testId, {state: {someFacets: {}}});
507
- registerToStore(testId, 'someFacets', {label: '', facetId: ''});
508
-
509
- expect(
510
- window.coveoHeadless[testId].bindings.store.state.someFacets
511
- ).toBeDefined();
512
- expect(mockedConsoleError.mock.calls.length).toBe(0);
513
- });
514
-
515
- it('should not update store with same facetId with new data', () => {
516
- initQuanticStoreTest(testId, {state: {someFacets: {}}});
517
-
518
- registerToStore(testId, 'someFacets', {
519
- label: 'some label',
520
- facetId: 'facetId',
521
- });
522
- expect(
523
- window.coveoHeadless[testId].bindings.store.state.someFacets.facetId
524
- .label
525
- ).toBe('some label');
526
-
527
- registerToStore(testId, 'someFacets', {
528
- label: 'a new label',
529
- facetId: 'facetId',
530
- });
531
- expect(
532
- window.coveoHeadless[testId].bindings.store.state.someFacets.facetId
533
- .label
534
- ).toBe('some label');
535
- });
536
- });
537
-
538
- describe('getFromStore', () => {
539
- beforeEach(() => {
540
- window.coveoHeadless = {
541
- [testId]: {
542
- bindings: {},
543
- },
544
- };
545
- });
546
-
547
- it('should log an error and return undefined when store is empty', () => {
548
- initQuanticStoreTest(testId, {});
549
- const data = getFromStore(testId, 'someFacets');
550
-
551
- expect(data).not.toBeDefined();
552
- expect(mockedConsoleError.mock.calls.length).toBe(1);
553
- });
554
-
555
- it('should return undefined when facetType does not exist in store', () => {
556
- initQuanticStoreTest(testId, {
557
- state: {someOtherFacet: {label: 'label', facetId: 'facetId'}},
558
- });
559
- const data = getFromStore(testId, 'someFacets');
560
-
561
- expect(data).not.toBeDefined();
562
- expect(mockedConsoleError.mock.calls.length).toBe(0);
563
- });
564
-
565
- it('should return data from store', () => {
566
- initQuanticStoreTest(testId, {
567
- state: {someFacets: {label: 'label', facetId: 'facetId'}},
568
- });
569
- const data = getFromStore(testId, 'someFacets');
570
- expect(data).toBeDefined();
571
- expect(data.label).toBe('label');
572
- expect(data.facetId).toBe('facetId');
573
- });
574
- });
575
-
576
- describe('registerSortOptionsToStore', () => {
577
- beforeEach(() => {
578
- window.coveoHeadless = {
579
- [testId]: {
580
- bindings: {},
581
- },
582
- };
583
- });
584
-
585
- it('should register the sort options data in the store', () => {
586
- initQuanticStoreTest(testId, {state: {someSortOptions: []}});
587
- registerSortOptionsToStore(testId, [
588
- {label: 'sortLabel', value: 'sortValue', criterion: {by: 'relevancy'}},
589
- ]);
590
-
591
- const sortStore = window.coveoHeadless[testId].bindings.store.state.sort;
592
- expect(sortStore).toBeDefined();
593
- expect(sortStore[0].value).toBe('sortValue');
594
- expect(sortStore[0].label).toBe('sortLabel');
595
- expect(sortStore[0].criterion.by).toBe('relevancy');
596
- expect(mockedConsoleError.mock.calls.length).toBe(0);
597
- });
598
-
599
- it('should log an error when store is empty', () => {
600
- initQuanticStoreTest(testId, {});
601
- registerSortOptionsToStore(testId, [
602
- {label: '', value: '', criterion: {by: 'relevancy'}},
603
- ]);
604
-
605
- expect(window.coveoHeadless[testId].bindings.store).toStrictEqual({});
606
- expect(mockedConsoleError.mock.calls.length).toBe(1);
607
- });
608
- });
609
-
610
- describe('getAllSortOptionsFromStore', () => {
611
- beforeEach(() => {
612
- window.coveoHeadless = {
613
- [testId]: {
614
- bindings: {},
615
- },
616
- };
617
- });
618
-
619
- it('should log an error and return undefined when store is empty', () => {
620
- initQuanticStoreTest(testId, {});
621
- const data = getAllSortOptionsFromStore(testId);
622
-
623
- expect(data).not.toBeDefined();
624
- expect(mockedConsoleError.mock.calls.length).toBe(1);
625
- });
626
-
627
- it('should return sort options data from store', () => {
628
- const sortOptions = [
629
- {label: 'label', value: 'value', criterion: {by: 'relevancy'}},
630
- {
631
- label: 'label2',
632
- value: 'value2',
633
- criterion: {by: 'date', order: 'ascending'},
634
- },
635
- ];
636
- initQuanticStoreTest(testId, {state: {sort: sortOptions}});
637
- const data = getAllSortOptionsFromStore(testId);
638
-
639
- expect(data).toBeDefined();
640
- for (let i = 0; i < sortOptions.length; i++) {
641
- expect(data[i].label).toBe(sortOptions[i].label);
642
- expect(data[i].value).toBe(sortOptions[i].value);
643
- expect(data[i].criterion.by).toBe(sortOptions[i].criterion.by);
644
- if (data[i].criterion.order) {
645
- // eslint-disable-next-line jest/no-conditional-expect
646
- expect(data[i].criterion.order).toBe(sortOptions[i].criterion.order);
647
- }
648
- }
649
- });
650
- });
651
- });