@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,327 +0,0 @@
1
- /* eslint-disable no-import-assign */
2
- // @ts-ignore
3
- import {createElement} from 'lwc';
4
- import QuanticCategoryFacet from 'c/quanticCategoryFacet';
5
- import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
6
- import {generateFacetDependencyConditions} from 'c/quanticUtils';
7
-
8
- jest.mock('c/quanticUtils', () => ({
9
- generateFacetDependencyConditions: jest.fn(),
10
- Store: {
11
- facetTypes: {
12
- FACETS: 'facets',
13
- NUMERICFACETS: 'numericFacets',
14
- DATEFACETS: 'dateFacets',
15
- CATEGORYFACETS: 'categoryFacets',
16
- },
17
- },
18
- I18nUtils: {
19
- format: jest.fn(),
20
- },
21
- }));
22
- jest.mock('c/quanticHeadlessLoader');
23
-
24
- const selectors = {
25
- facetContent: '[data-test="facet-content"]',
26
- componentError: 'c-quantic-component-error',
27
- };
28
-
29
- const exampleFacetId = 'example facet id';
30
- const exampleField = 'exampleField';
31
- const defaultOptions = {
32
- field: exampleField,
33
- };
34
- const categoryFacetControllerMock = {
35
- subscribe: jest.fn((callback) => callback()),
36
- state: {
37
- facetId: exampleFacetId,
38
- values: [],
39
- },
40
- };
41
- const parentFacetIdError = `The ${exampleField} c-quantic-category-facet requires dependsOn.parentFacetId to be a valid string.`;
42
- const expectedValueError = `The ${exampleField} c-quantic-category-facet requires dependsOn.expectedValue to be a valid string.`;
43
-
44
- function createTestComponent(options = defaultOptions) {
45
- prepareHeadlessState();
46
-
47
- const element = createElement('c-quantic-category-facet', {
48
- is: QuanticCategoryFacet,
49
- });
50
- for (const [key, value] of Object.entries(options)) {
51
- element[key] = value;
52
- }
53
-
54
- document.body.appendChild(element);
55
- return element;
56
- }
57
-
58
- const functionsMocks = {
59
- buildCategoryFacet: jest.fn(() => categoryFacetControllerMock),
60
- stopWatching: jest.fn(),
61
- buildFacetConditionsManager: jest.fn(() => ({
62
- stopWatching: functionsMocks.stopWatching,
63
- })),
64
- buildSearchStatus: jest.fn(() => ({
65
- subscribe: jest.fn((callback) => callback()),
66
- state: {},
67
- })),
68
- };
69
-
70
- function prepareHeadlessState() {
71
- // @ts-ignore
72
- mockHeadlessLoader.getHeadlessBundle = () => {
73
- return {
74
- buildCategoryFacet: functionsMocks.buildCategoryFacet,
75
- buildSearchStatus: functionsMocks.buildSearchStatus,
76
- buildFacetConditionsManager: functionsMocks.buildFacetConditionsManager,
77
- };
78
- };
79
- }
80
-
81
- // Helper function to wait until the microtask queue is empty.
82
- function flushPromises() {
83
- // eslint-disable-next-line @lwc/lwc/no-async-operation
84
- return new Promise((resolve) => setTimeout(resolve, 0));
85
- }
86
-
87
- const exampleEngine = {
88
- id: 'dummy engine',
89
- };
90
- let isInitialized = false;
91
-
92
- function mockBueno() {
93
- // @ts-ignore
94
- mockHeadlessLoader.getBueno = () => {
95
- // @ts-ignore
96
- global.Bueno = {
97
- isString: jest
98
- .fn()
99
- .mockImplementation(
100
- (value) => Object.prototype.toString.call(value) === '[object String]'
101
- ),
102
- };
103
- return new Promise((resolve) => resolve());
104
- };
105
- }
106
-
107
- function mockSuccessfulHeadlessInitialization() {
108
- // @ts-ignore
109
- mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => {
110
- if (element instanceof QuanticCategoryFacet && !isInitialized) {
111
- isInitialized = true;
112
- initialize(exampleEngine);
113
- }
114
- };
115
- }
116
-
117
- function cleanup() {
118
- // The jsdom instance is shared across test cases in a single file so reset the DOM
119
- while (document.body.firstChild) {
120
- document.body.removeChild(document.body.firstChild);
121
- }
122
- jest.clearAllMocks();
123
- isInitialized = false;
124
- }
125
-
126
- describe('c-quantic-category-facet', () => {
127
- beforeAll(() => {
128
- mockSuccessfulHeadlessInitialization();
129
- mockBueno();
130
- });
131
-
132
- afterEach(() => {
133
- cleanup();
134
- });
135
-
136
- describe('the facet conditions manager', () => {
137
- it('should build the controller when the dependsOn property is set', async () => {
138
- const exampleFacetDependency = {
139
- parentFacetId: 'filetype',
140
- expectedValue: 'txt',
141
- };
142
- createTestComponent({
143
- ...defaultOptions,
144
- dependsOn: exampleFacetDependency,
145
- });
146
- await flushPromises();
147
-
148
- expect(functionsMocks.buildCategoryFacet).toHaveBeenCalledTimes(1);
149
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
150
- 1
151
- );
152
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledWith(
153
- exampleEngine,
154
- {
155
- facetId: exampleFacetId,
156
- }
157
- );
158
-
159
- expect(generateFacetDependencyConditions).toHaveBeenCalledTimes(1);
160
- expect(generateFacetDependencyConditions).toHaveBeenCalledWith({
161
- [exampleFacetDependency.parentFacetId]:
162
- exampleFacetDependency.expectedValue,
163
- });
164
- });
165
-
166
- it('should not build the controller when the dependsOn property is not set', async () => {
167
- createTestComponent();
168
- await flushPromises();
169
-
170
- expect(functionsMocks.buildCategoryFacet).toHaveBeenCalledTimes(1);
171
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
172
- 0
173
- );
174
- expect(generateFacetDependencyConditions).toHaveBeenCalledTimes(0);
175
- });
176
- });
177
-
178
- describe('the facet enablement', () => {
179
- describe('when the facet is enabled', () => {
180
- beforeAll(() => {
181
- functionsMocks.buildCategoryFacet.mockReturnValue({
182
- ...categoryFacetControllerMock,
183
- state: {...categoryFacetControllerMock.state, enabled: true},
184
- });
185
- });
186
-
187
- it('should display the facet content', async () => {
188
- const element = createTestComponent();
189
- await flushPromises();
190
-
191
- const facetContent = element.shadowRoot.querySelector(
192
- selectors.facetContent
193
- );
194
- expect(facetContent).not.toBeNull();
195
- });
196
- });
197
-
198
- describe('when the facet is not enabled', () => {
199
- beforeAll(() => {
200
- functionsMocks.buildCategoryFacet.mockReturnValue({
201
- ...categoryFacetControllerMock,
202
- state: {...categoryFacetControllerMock.state, enabled: false},
203
- });
204
- });
205
-
206
- it('should not display the facet content', async () => {
207
- const element = createTestComponent();
208
- await flushPromises();
209
-
210
- const facetContent = element.shadowRoot.querySelector(
211
- selectors.facetContent
212
- );
213
- expect(facetContent).toBeNull();
214
- });
215
- });
216
-
217
- afterAll(() => {
218
- functionsMocks.buildCategoryFacet.mockReturnValue(
219
- categoryFacetControllerMock
220
- );
221
- });
222
- });
223
-
224
- describe('validation of the dependsOn property', () => {
225
- let consoleError;
226
- beforeAll(() => {
227
- consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
228
- });
229
-
230
- describe('when dependsOn.parentFacetId is not provided', () => {
231
- it('should display the error component', async () => {
232
- const invalidFacetDependency = {
233
- expectedValue: 'txt',
234
- };
235
- const element = createTestComponent({
236
- ...defaultOptions,
237
- dependsOn: invalidFacetDependency,
238
- });
239
- await flushPromises();
240
-
241
- const componentError = element.shadowRoot.querySelector(
242
- selectors.componentError
243
- );
244
- const facetContent = element.shadowRoot.querySelector(
245
- selectors.facetContent
246
- );
247
-
248
- expect(consoleError).toHaveBeenCalledTimes(1);
249
- expect(consoleError).toHaveBeenCalledWith(parentFacetIdError);
250
- expect(componentError).not.toBeNull();
251
- expect(facetContent).toBeNull();
252
- });
253
- });
254
-
255
- describe('when dependsOn.parentFacetId is not a string', () => {
256
- it('should display the error component', async () => {
257
- const invalidFacetDependency = {
258
- parentFacetId: 1,
259
- expectedValue: 'txt',
260
- };
261
- const element = createTestComponent({
262
- ...defaultOptions,
263
- dependsOn: invalidFacetDependency,
264
- });
265
- await flushPromises();
266
-
267
- const componentError = element.shadowRoot.querySelector(
268
- selectors.componentError
269
- );
270
- const facetContent = element.shadowRoot.querySelector(
271
- selectors.facetContent
272
- );
273
-
274
- expect(consoleError).toHaveBeenCalledTimes(1);
275
- expect(consoleError).toHaveBeenCalledWith(parentFacetIdError);
276
- expect(componentError).not.toBeNull();
277
- expect(facetContent).toBeNull();
278
- });
279
- });
280
-
281
- describe('when dependsOn.expectedValue is not a string', () => {
282
- it('should display the error component', async () => {
283
- const invalidFacetDependency = {
284
- parentFacetId: 'filetype',
285
- expectedValue: 2,
286
- };
287
- const element = createTestComponent({
288
- ...defaultOptions,
289
- dependsOn: invalidFacetDependency,
290
- });
291
- await flushPromises();
292
-
293
- const componentError = element.shadowRoot.querySelector(
294
- selectors.componentError
295
- );
296
- const facetContent = element.shadowRoot.querySelector(
297
- selectors.facetContent
298
- );
299
-
300
- expect(consoleError).toHaveBeenCalledTimes(1);
301
- expect(consoleError).toHaveBeenCalledWith(expectedValueError);
302
- expect(componentError).not.toBeNull();
303
- expect(facetContent).toBeNull();
304
- });
305
- });
306
- });
307
-
308
- describe('when the component is disconnected', () => {
309
- it('should make the condition manager stop watching the facet', async () => {
310
- const exampleFacetDependency = {
311
- parentFacetId: 'filetype',
312
- expectedValue: 'txt',
313
- };
314
- const element = createTestComponent({
315
- ...defaultOptions,
316
- dependsOn: exampleFacetDependency,
317
- });
318
- await flushPromises();
319
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
320
- 1
321
- );
322
-
323
- document.body.removeChild(element);
324
- expect(functionsMocks.stopWatching).toHaveBeenCalledTimes(1);
325
- });
326
- });
327
- });
@@ -1,269 +0,0 @@
1
- import {
2
- getNavigateCalledWith,
3
- getGenerateUrlCalledWith,
4
- } from 'lightning/navigation';
5
- // @ts-ignore
6
- import {createElement} from 'lwc';
7
- import QuanticCitation from '../quanticCitation';
8
-
9
- const functionsMocks = {
10
- eventHandler: jest.fn((event) => event),
11
- exampleSelect: jest.fn(() => {}),
12
- exampleBeginDelayedSelect: jest.fn(() => {}),
13
- exampleCancelPendingSelect: jest.fn(() => {}),
14
- };
15
-
16
- const exampleCitation = {
17
- index: '1',
18
- id: '123',
19
- title: 'Example title 1',
20
- uri: 'https://example.com/',
21
- clickUri: 'https://example.com/',
22
- permanentid: '1',
23
- text: 'text 01',
24
- };
25
-
26
- const exampleSalesforceCitation = {
27
- ...exampleCitation,
28
- fields: {
29
- sfid: '123',
30
- },
31
- };
32
- const exampleSalesforceKnowledgeArticleCitation = {
33
- ...exampleCitation,
34
- fields: {
35
- sfid: '123',
36
- sfkbid: 'foo',
37
- sfkavid: 'bar',
38
- },
39
- };
40
- const exampleSalesforceLink = 'https://www.example-salesforce.com';
41
-
42
- const defaultOptions = {
43
- citation: exampleCitation,
44
- interactiveCitation: {
45
- select: () => functionsMocks.exampleSelect(),
46
- beginDelayedSelect: () => functionsMocks.exampleBeginDelayedSelect(),
47
- cancelPendingSelect: () => functionsMocks.exampleCancelPendingSelect(),
48
- },
49
- };
50
-
51
- const selectors = {
52
- citation: '.citation',
53
- citationLink: '.citation__link',
54
- citationTitle: '.citation__title',
55
- citationTooltip: 'c-quantic-tooltip',
56
- citationTooltipUrl: '[data-testid="citation__tooltip-uri"]',
57
- };
58
-
59
- function createTestComponent(options = defaultOptions) {
60
- const element = createElement('c-quantic-citation', {
61
- is: QuanticCitation,
62
- });
63
-
64
- for (const [key, value] of Object.entries(options)) {
65
- element[key] = value;
66
- }
67
-
68
- document.body.appendChild(element);
69
- return element;
70
- }
71
-
72
- // Helper function to wait until the microtask queue is empty.
73
- async function flushPromises() {
74
- return Promise.resolve();
75
- }
76
-
77
- const bindingsMap = {
78
- contextmenu: functionsMocks.exampleSelect,
79
- click: functionsMocks.exampleSelect,
80
- mouseup: functionsMocks.exampleSelect,
81
- mousedown: functionsMocks.exampleSelect,
82
- touchstart: functionsMocks.exampleBeginDelayedSelect,
83
- touchend: functionsMocks.exampleCancelPendingSelect,
84
- };
85
-
86
- function setupEventDispatchTest(eventName) {
87
- const handler = (event) => {
88
- functionsMocks.eventHandler(event?.detail);
89
- document.removeEventListener(eventName, handler);
90
- };
91
- document.addEventListener(eventName, handler);
92
- }
93
-
94
- describe('c-quantic-citation', () => {
95
- function cleanup() {
96
- // The jsdom instance is shared across test cases in a single file so reset the DOM
97
- while (document.body.firstChild) {
98
- document.body.removeChild(document.body.firstChild);
99
- }
100
- jest.clearAllMocks();
101
- }
102
-
103
- afterEach(() => {
104
- cleanup();
105
- });
106
-
107
- it('should properly display the citation', async () => {
108
- const element = createTestComponent();
109
- await flushPromises();
110
-
111
- const citation = element.shadowRoot.querySelector(selectors.citation);
112
- const citationLink = element.shadowRoot.querySelector(
113
- selectors.citationLink
114
- );
115
- const citationTitle = element.shadowRoot.querySelector(
116
- selectors.citationTitle
117
- );
118
- const citationTooltip = element.shadowRoot.querySelector(
119
- selectors.citationTooltip
120
- );
121
-
122
- expect(citation).not.toBeNull();
123
- expect(citationLink).not.toBeNull();
124
- expect(citationTitle).not.toBeNull();
125
- expect(citationTooltip).not.toBeNull();
126
-
127
- expect(citationLink.href).toBe(exampleCitation.clickUri);
128
- expect(citationLink.target).toBe('_blank');
129
- expect(citationTitle.textContent).toBe(exampleCitation.title);
130
- });
131
-
132
- describe('the analytics bindings of the link within the citation', () => {
133
- for (const [eventName, action] of Object.entries(bindingsMap)) {
134
- it(`should execute the proper action when the ${eventName} is triggered on the link`, async () => {
135
- const element = createTestComponent();
136
- await flushPromises();
137
-
138
- const link = element.shadowRoot.querySelector(selectors.citationLink);
139
- link.dispatchEvent(new CustomEvent(eventName));
140
-
141
- expect(action).toHaveBeenCalledTimes(1);
142
- });
143
- }
144
- });
145
-
146
- describe('hovering over the citation', () => {
147
- beforeAll(() => {
148
- jest.useFakeTimers();
149
- });
150
-
151
- afterAll(() => {
152
- jest.useRealTimers();
153
- });
154
-
155
- it('should dispatch a citation hover event after hovering over the the citation for more than 1200ms, 200ms debounce duration before hover + 1000ms minimum hover duration', async () => {
156
- const element = createTestComponent();
157
- await flushPromises();
158
- setupEventDispatchTest('quantic__citationhover');
159
-
160
- const citationLink = element.shadowRoot.querySelector(
161
- selectors.citationLink
162
- );
163
- expect(citationLink).not.toBeNull();
164
-
165
- await citationLink.dispatchEvent(
166
- new CustomEvent('mouseenter', {bubbles: true})
167
- );
168
- jest.advanceTimersByTime(1200);
169
- await citationLink.dispatchEvent(
170
- new CustomEvent('mouseleave', {bubbles: true})
171
- );
172
-
173
- expect(functionsMocks.eventHandler).toHaveBeenCalledTimes(1);
174
- expect(functionsMocks.eventHandler).toHaveBeenCalledWith({
175
- citationHoverTimeMs: 1000,
176
- });
177
- });
178
-
179
- it('should not dispatch a citation hover event after hovering over the the citation for more than 1200ms', async () => {
180
- const element = createTestComponent();
181
- await flushPromises();
182
- setupEventDispatchTest('quantic__citationhover');
183
-
184
- const citationLink = element.shadowRoot.querySelector(
185
- selectors.citationLink
186
- );
187
- expect(citationLink).not.toBeNull();
188
-
189
- await citationLink.dispatchEvent(
190
- new CustomEvent('mouseenter', {bubbles: true})
191
- );
192
- jest.advanceTimersByTime(500);
193
- await citationLink.dispatchEvent(
194
- new CustomEvent('mouseleave', {bubbles: true})
195
- );
196
-
197
- expect(functionsMocks.eventHandler).toHaveBeenCalledTimes(0);
198
- });
199
- });
200
-
201
- describe('when the citation source is of type Salesforce', () => {
202
- it('should call the navigation mixin to get the Salesforce record URL', async () => {
203
- const element = createTestComponent({
204
- ...defaultOptions,
205
- citation: exampleSalesforceCitation,
206
- });
207
- await flushPromises();
208
-
209
- const link = element.shadowRoot.querySelector(selectors.citationLink);
210
- const {pageReference} = getGenerateUrlCalledWith();
211
-
212
- expect(pageReference.attributes.recordId).toBe(
213
- exampleSalesforceCitation.fields.sfid
214
- );
215
- expect(link.href).toBe(`${exampleSalesforceLink}/`);
216
- });
217
-
218
- it('should open the citation link inside Salesforce', async () => {
219
- const element = createTestComponent({
220
- ...defaultOptions,
221
- citation: exampleSalesforceCitation,
222
- });
223
- await flushPromises();
224
-
225
- const link = element.shadowRoot.querySelector(selectors.citationLink);
226
- link.click();
227
-
228
- const {pageReference} = getNavigateCalledWith();
229
-
230
- expect(pageReference.attributes.recordId).toBe(
231
- exampleSalesforceCitation.fields.sfid
232
- );
233
- });
234
-
235
- it('should display the salesforce link inside the tooltip url', async () => {
236
- const element = createTestComponent({
237
- ...defaultOptions,
238
- citation: exampleSalesforceCitation,
239
- });
240
- await flushPromises();
241
-
242
- const citationTooltipUrl = element.shadowRoot.querySelector(
243
- selectors.citationTooltipUrl
244
- );
245
- expect(citationTooltipUrl).not.toBeNull();
246
- expect(citationTooltipUrl.textContent).toBe(exampleSalesforceLink);
247
- });
248
-
249
- describe('when the result is a knowledge article', () => {
250
- it('should open the citation link inside Salesforce', async () => {
251
- const element = createTestComponent({
252
- ...defaultOptions,
253
- citation: exampleSalesforceKnowledgeArticleCitation,
254
- });
255
- await flushPromises();
256
-
257
- const link = element.shadowRoot.querySelector(selectors.citationLink);
258
- link.click();
259
-
260
- const {pageReference} = getNavigateCalledWith();
261
-
262
- expect(pageReference.attributes.recordId).toBe(
263
- exampleSalesforceKnowledgeArticleCitation.fields.sfkavid
264
- );
265
- expect(link.href).toBe(`${exampleSalesforceLink}/`);
266
- });
267
- });
268
- });
269
- });