@coveo/quantic 3.16.0 → 3.16.1-pre.1a6fc4649f

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 (116) hide show
  1. package/docs/out/quantic-docs.json +2 -2
  2. package/force-app/main/default/lwc/quanticNumberButton/quanticNumberButton.html +1 -1
  3. package/force-app/main/default/lwc/quanticResultsPerPage/quanticResultsPerPage.js +27 -17
  4. package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +6 -6
  5. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recent-queries-list/headless-recent-queries-list.d.ts +5 -0
  6. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/core/search-parameter-manager/headless-core-search-parameter-manager.d.ts +0 -1
  7. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/recent-queries-list/headless-recent-queries-list.d.ts +5 -0
  8. package/force-app/main/default/staticresources/coveoheadless/definitions/features/parameter-manager/parameter-manager-selectors.d.ts +5 -0
  9. package/force-app/main/default/staticresources/coveoheadless/definitions/features/search-parameters/search-parameter-actions-loader.d.ts +36 -0
  10. package/force-app/main/default/staticresources/coveoheadless/definitions/features/search-parameters/search-parameter-actions.d.ts +6 -0
  11. package/force-app/main/default/staticresources/coveoheadless/headless.js +10 -10
  12. package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +9 -9
  13. package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +5 -5
  14. package/package.json +6 -4
  15. package/force-app/main/default/lwc/quanticBreadcrumbManager/__tests__/quanticBreadcrumbManager.test.js +0 -604
  16. package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/fixture.ts +0 -76
  17. package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/pageObject.ts +0 -282
  18. package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/quanticBreadcrumbManager.e2e.ts +0 -167
  19. package/force-app/main/default/lwc/quanticCarousel/__tests__/quanticCarousel.test.js +0 -262
  20. package/force-app/main/default/lwc/quanticCaseClassification/__tests__/quanticCaseClassification.test.js +0 -819
  21. package/force-app/main/default/lwc/quanticCaseClassification/e2e/data.ts +0 -23
  22. package/force-app/main/default/lwc/quanticCaseClassification/e2e/fixture.ts +0 -51
  23. package/force-app/main/default/lwc/quanticCaseClassification/e2e/pageObject.ts +0 -152
  24. package/force-app/main/default/lwc/quanticCaseClassification/e2e/quanticCaseClassification.e2e.ts +0 -269
  25. package/force-app/main/default/lwc/quanticCategoryFacet/__tests__/quanticCategoryFacet.test.js +0 -327
  26. package/force-app/main/default/lwc/quanticCitation/__tests__/quanticCitation.test.js +0 -269
  27. package/force-app/main/default/lwc/quanticColoredResultBadge/__tests__/quanticColoredResultBadge.test.js +0 -212
  28. package/force-app/main/default/lwc/quanticDateFacet/__tests__/quanticDateFacet.test.js +0 -321
  29. package/force-app/main/default/lwc/quanticDidYouMean/__tests__/quanticDidYouMean.test.js +0 -199
  30. package/force-app/main/default/lwc/quanticFacet/__tests__/quanticFacet.test.js +0 -341
  31. package/force-app/main/default/lwc/quanticFacetCaption/__tests__/quanticFacetCaption.test.js +0 -28
  32. package/force-app/main/default/lwc/quanticFacetManager/__tests__/quanticFacetManager.test.js +0 -178
  33. package/force-app/main/default/lwc/quanticFacetManager/e2e/fixture.ts +0 -63
  34. package/force-app/main/default/lwc/quanticFacetManager/e2e/pageObject.ts +0 -23
  35. package/force-app/main/default/lwc/quanticFacetManager/e2e/quanticFacetManager.e2e.ts +0 -82
  36. package/force-app/main/default/lwc/quanticFeedback/__tests__/quanticFeedback.test.js +0 -392
  37. package/force-app/main/default/lwc/quanticFeedbackModal/__tests__/quanticFeedbackModal.test.js +0 -448
  38. package/force-app/main/default/lwc/quanticFeedbackModalQna/__tests__/quanticFeedbackModalQna.test.js +0 -298
  39. package/force-app/main/default/lwc/quanticGeneratedAnswer/__tests__/quanticGeneratedAnswer.test.js +0 -814
  40. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/data.ts +0 -56
  41. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/fixture.ts +0 -87
  42. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/pageObject.ts +0 -283
  43. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/quanticGeneratedAnswer.e2e.ts +0 -199
  44. package/force-app/main/default/lwc/quanticGeneratedAnswerContent/__tests__/quanticGeneratedAnswerContent.test.js +0 -151
  45. package/force-app/main/default/lwc/quanticHeading/__tests__/quanticHeading.test.js +0 -71
  46. package/force-app/main/default/lwc/quanticHeadlessLoader/__tests__/quanticHeadlessLoader.test.js +0 -651
  47. package/force-app/main/default/lwc/quanticNotifications/__tests__/quanticNotifications.test.js +0 -335
  48. package/force-app/main/default/lwc/quanticNumericFacet/__tests__/quanticNumericFacet.test.js +0 -343
  49. package/force-app/main/default/lwc/quanticPager/e2e/fixture.ts +0 -63
  50. package/force-app/main/default/lwc/quanticPager/e2e/pageObject.ts +0 -69
  51. package/force-app/main/default/lwc/quanticPager/e2e/quanticPager.e2e.ts +0 -101
  52. package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/data/defaultTestCase.json +0 -13
  53. package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/data/youtubeTestCase.json +0 -14
  54. package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/quanticQuickviewContent.test.js +0 -82
  55. package/force-app/main/default/lwc/quanticRadioButtonsGroup/__tests__/quanticRadioButtonsGroup.test.js +0 -273
  56. package/force-app/main/default/lwc/quanticRefineModalContent/__tests__/quanticRefineModalContent.test.js +0 -501
  57. package/force-app/main/default/lwc/quanticResultAction/__tests__/quanticResultAction.test.js +0 -262
  58. package/force-app/main/default/lwc/quanticResultActionBar/__tests__/quanticResultActionBar.test.js +0 -141
  59. package/force-app/main/default/lwc/quanticResultChildren/__tests__/quanticResultChildren.test.js +0 -340
  60. package/force-app/main/default/lwc/quanticResultDate/__tests__/quanticResultDate.test.js +0 -144
  61. package/force-app/main/default/lwc/quanticResultField/__tests__/quanticResultField.test.js +0 -120
  62. package/force-app/main/default/lwc/quanticResultHighlightedTextField/__tests__/quanticResultHighlightedTextField.test.js +0 -209
  63. package/force-app/main/default/lwc/quanticResultLink/__tests__/quanticResultLink.test.js +0 -261
  64. package/force-app/main/default/lwc/quanticResultMultiValueText/__tests__/quanticResultMultiValueText.test.js +0 -235
  65. package/force-app/main/default/lwc/quanticResultNumber/__tests__/quanticResultNumber.test.js +0 -144
  66. package/force-app/main/default/lwc/quanticResultPrintableUri/__tests__/quanticResultPrintableUri.test.js +0 -324
  67. package/force-app/main/default/lwc/quanticResultQuickview/__tests__/quanticResultQuickview.test.js +0 -171
  68. package/force-app/main/default/lwc/quanticResultText/__tests__/quanticResultText.test.js +0 -155
  69. package/force-app/main/default/lwc/quanticResultsPerPage/__tests__/quanticResultsPerPage.test.js +0 -404
  70. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/fixture.ts +0 -74
  71. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/pageObject.ts +0 -85
  72. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/quanticResultsPerPage.e2e.ts +0 -97
  73. package/force-app/main/default/lwc/quanticSearchBox/__tests__/quanticSearchBox.test.js +0 -168
  74. package/force-app/main/default/lwc/quanticSearchBoxInput/__tests__/quanticSearchBoxInput.test.js +0 -823
  75. package/force-app/main/default/lwc/quanticSmartSnippet/__tests__/quanticSmartSnippet.test.js +0 -341
  76. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/data.ts +0 -21
  77. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/fixture.ts +0 -91
  78. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/pageObject.ts +0 -196
  79. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/quanticSmartSnippet.e2e.ts +0 -168
  80. package/force-app/main/default/lwc/quanticSmartSnippetAnswer/__tests__/quanticSmartSnippetAnswer.test.js +0 -126
  81. package/force-app/main/default/lwc/quanticSmartSnippetSource/__tests__/quanticSmartSnippetSource.test.js +0 -290
  82. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/__tests__/quanticSmartSnippetSuggestions.test.js +0 -329
  83. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/data.ts +0 -31
  84. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/fixture.ts +0 -93
  85. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/pageObject.ts +0 -160
  86. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/quanticSmartSnippetSuggestions.e2e.ts +0 -127
  87. package/force-app/main/default/lwc/quanticSort/__tests__/quanticSort.test.js +0 -416
  88. package/force-app/main/default/lwc/quanticSort/e2e/fixture.ts +0 -61
  89. package/force-app/main/default/lwc/quanticSort/e2e/pageObject.ts +0 -89
  90. package/force-app/main/default/lwc/quanticSort/e2e/quanticSort.e2e.ts +0 -91
  91. package/force-app/main/default/lwc/quanticSourceCitations/__tests__/quanticSourceCitations.test.js +0 -123
  92. package/force-app/main/default/lwc/quanticStandaloneSearchBox/__tests__/quanticStandaloneSearchBox.test.js +0 -186
  93. package/force-app/main/default/lwc/quanticStatefulButton/__tests__/quanticStatefulButton.test.js +0 -222
  94. package/force-app/main/default/lwc/quanticTab/__tests__/quanticTab.test.js +0 -287
  95. package/force-app/main/default/lwc/quanticTab/e2e/fixture.ts +0 -62
  96. package/force-app/main/default/lwc/quanticTab/e2e/pageObject.ts +0 -67
  97. package/force-app/main/default/lwc/quanticTab/e2e/quanticTab.e2e.ts +0 -77
  98. package/force-app/main/default/lwc/quanticTabBar/__tests__/quanticTabBar.test.js +0 -331
  99. package/force-app/main/default/lwc/quanticTabBar/e2e/fixture.ts +0 -61
  100. package/force-app/main/default/lwc/quanticTabBar/e2e/pageObject.ts +0 -80
  101. package/force-app/main/default/lwc/quanticTabBar/e2e/quanticTabBar.e2e.ts +0 -173
  102. package/force-app/main/default/lwc/quanticTimeframeFacet/__tests__/quanticTimeframeFacet.test.js +0 -339
  103. package/force-app/main/default/lwc/quanticTooltip/__tests__/quanticTooltip.test.js +0 -107
  104. package/force-app/main/default/lwc/quanticUserAction/__tests__/quanticUserAction.test.js +0 -427
  105. package/force-app/main/default/lwc/quanticUserActionsSession/__tests__/quanticUserActionsSession.test.js +0 -269
  106. package/force-app/main/default/lwc/quanticUserActionsTimeline/__tests__/data/userActionsState.json +0 -89
  107. package/force-app/main/default/lwc/quanticUserActionsTimeline/__tests__/quanticUserActionsTimeline.test.js +0 -511
  108. package/force-app/main/default/lwc/quanticUserActionsToggle/__tests__/quanticUserActionsToggle.test.js +0 -229
  109. package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/data.ts +0 -32
  110. package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/fixture.ts +0 -32
  111. package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/pageObject.ts +0 -71
  112. package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/quanticUserActionsToggle.e2e.ts +0 -39
  113. package/force-app/main/default/lwc/quanticUtils/__tests__/facetDependenciesUtils.test.js +0 -92
  114. package/force-app/main/default/lwc/quanticUtils/__tests__/markdownUtils.test.js +0 -71
  115. package/force-app/main/default/lwc/quanticUtils/__tests__/quanticUtils.test.js +0 -223
  116. package/force-app/main/default/lwc/quanticViewedByCustomerBadge/__tests__/quanticViewedByCustomerBadge.test.js +0 -131
@@ -1,144 +0,0 @@
1
- // @ts-ignore
2
- import {createElement} from 'lwc';
3
- import QuanticResultNumber from '../quanticResultNumber';
4
-
5
- const exampleField = 'examplenumberfield';
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-number', {
22
- is: QuanticResultNumber,
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-number', () => {
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-number requires a result and a number field to be specified.'
78
- );
79
- expect(console.error).toHaveBeenCalledWith(
80
- 'The "examplenumberfield" field value is not a valid number.'
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-number requires a result and a number field to be specified.'
96
- );
97
- expect(console.error).toHaveBeenCalledWith(
98
- 'The "undefined" field value is not a valid number.'
99
- );
100
- });
101
- });
102
-
103
- describe('when the field value is not a valid number', () => {
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,324 +0,0 @@
1
- // @ts-ignore
2
- import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
3
- // @ts-ignore
4
- import {createElement} from 'lwc';
5
- import QuanticResultPrintableUri from '../quanticResultPrintableUri';
6
-
7
- const MIN_MAX_NUMBER_OF_PARTS = 3;
8
-
9
- jest.mock('c/quanticHeadlessLoader');
10
-
11
- // Helper function to mock Headless and Bueno for this suite of tests.
12
- function mockHeadlessAndBueno() {
13
- jest.spyOn(mockHeadlessLoader, 'getHeadlessEnginePromise').mockReturnValue(
14
- new Promise((resolve) => {
15
- resolve();
16
- })
17
- );
18
-
19
- jest.spyOn(mockHeadlessLoader, 'getBueno').mockReturnValue(
20
- new Promise(() => {
21
- // @ts-ignore
22
- global.Bueno = {
23
- isString: jest
24
- .fn()
25
- .mockImplementation(
26
- (value) =>
27
- Object.prototype.toString.call(value) === '[object String]'
28
- ),
29
- };
30
- })
31
- );
32
- }
33
-
34
- const selectors = {
35
- link: 'c-quantic-result-link',
36
- pathItem: '[data-test="path__item"]',
37
- pathExpandButton: '[data-test="path__expand-button"]',
38
- errorMessage: '[data-test="error"]',
39
- };
40
- const exampleEngineId = 'example engine id';
41
-
42
- function createTestComponent(options) {
43
- const element = createElement('c-quantic-result-printable-uri', {
44
- is: QuanticResultPrintableUri,
45
- });
46
-
47
- for (const [key, value] of Object.entries(options)) {
48
- element[key] = value;
49
- }
50
-
51
- document.body.appendChild(element);
52
- return element;
53
- }
54
-
55
- // Helper function to wait until the microtask queue is empty.
56
- function flushPromises() {
57
- return new Promise((resolve) => setTimeout(resolve, 0));
58
- }
59
-
60
- function generateExampleUri(id) {
61
- return `https://uri${id}.com/`;
62
- }
63
-
64
- function generateResultParents(numberOfParents) {
65
- let parents = '';
66
- for (let i = 1; i <= numberOfParents; i++) {
67
- parents += `<parent name="parent${i}" uri="${generateExampleUri(i)}" />`;
68
- }
69
- return `<parents>${parents}</parents>`;
70
- }
71
-
72
- function shouldProperlyDisplayAllPathItems(pathItems) {
73
- pathItems.forEach((item, index) => {
74
- expect(item.textContent).toBe(`parent${index + 1}`);
75
- expect(item.href).toBe(`${generateExampleUri(index + 1)}`);
76
- });
77
- }
78
-
79
- describe('c-quantic-result-printable-uri', () => {
80
- function cleanup() {
81
- // The jsdom instance is shared across test cases in a single file so reset the DOM
82
- while (document.body.firstChild) {
83
- document.body.removeChild(document.body.firstChild);
84
- }
85
- jest.clearAllMocks();
86
- }
87
-
88
- beforeEach(() => {
89
- console.error = jest.fn();
90
- mockHeadlessAndBueno();
91
- });
92
-
93
- afterEach(() => {
94
- cleanup();
95
- });
96
-
97
- describe('when displaying the result path', () => {
98
- describe('when the number of parents is lower than the maxNumberOfParts property', () => {
99
- const numberOfParents = 2;
100
- const exampleResultWithParents = {
101
- raw: {
102
- parents: generateResultParents(numberOfParents),
103
- },
104
- };
105
- it('should properly display all the result path', async () => {
106
- const element = createTestComponent({
107
- result: exampleResultWithParents,
108
- engineId: exampleEngineId,
109
- maxNumberOfParts: 3,
110
- });
111
- await flushPromises();
112
-
113
- const pathItems = element.shadowRoot.querySelectorAll(
114
- selectors.pathItem
115
- );
116
- expect(pathItems).not.toBeNull();
117
- expect(pathItems.length).toBe(numberOfParents);
118
- shouldProperlyDisplayAllPathItems(pathItems);
119
- });
120
- });
121
-
122
- describe('when the number of parents is greater than the maxNumberOfParts property', () => {
123
- const numberOfParents = 8;
124
- const exampleResultWithParents = {
125
- raw: {
126
- parents: generateResultParents(numberOfParents),
127
- },
128
- };
129
-
130
- describe('when the default value of the maxNumberOfParts property is used', () => {
131
- it('should properly display the result collapsed path', async () => {
132
- const defaultMaxNumberOfParts = 5;
133
- const element = createTestComponent({
134
- result: exampleResultWithParents,
135
- engineId: exampleEngineId,
136
- });
137
- await flushPromises();
138
-
139
- const pathItems = Array.from(
140
- element.shadowRoot.querySelectorAll(selectors.pathItem)
141
- );
142
- const expandButton = element.shadowRoot.querySelector(
143
- selectors.pathExpandButton
144
- );
145
- expect(pathItems).not.toBeNull();
146
- expect(pathItems.length).toBe(defaultMaxNumberOfParts);
147
- pathItems
148
- .slice(0, defaultMaxNumberOfParts - 1)
149
- .forEach((item, index) => {
150
- expect(item.textContent).toBe(`parent${index + 1}`);
151
- expect(item.href).toBe(`${generateExampleUri(index + 1)}`);
152
- });
153
-
154
- expect(expandButton).not.toBeNull();
155
-
156
- expect(pathItems[defaultMaxNumberOfParts - 1].textContent).toBe(
157
- `parent${numberOfParents}`
158
- );
159
- expect(pathItems[defaultMaxNumberOfParts - 1].href).toBe(
160
- `${generateExampleUri(numberOfParents)}`
161
- );
162
- });
163
-
164
- describe('when expanding the result collapsed path', () => {
165
- it('should properly display the result expanded path', async () => {
166
- const element = createTestComponent({
167
- result: exampleResultWithParents,
168
- engineId: exampleEngineId,
169
- });
170
- await flushPromises();
171
-
172
- let expandButton = element.shadowRoot.querySelector(
173
- selectors.pathExpandButton
174
- );
175
-
176
- expect(expandButton).not.toBeNull();
177
-
178
- await expandButton.click();
179
-
180
- const pathItems = element.shadowRoot.querySelectorAll(
181
- selectors.pathItem
182
- );
183
- expandButton = element.shadowRoot.querySelector(
184
- selectors.pathExpandButton
185
- );
186
-
187
- expect(expandButton).toBeNull();
188
- expect(pathItems).not.toBeNull();
189
- expect(pathItems.length).toBe(numberOfParents);
190
- shouldProperlyDisplayAllPathItems(pathItems);
191
- });
192
- });
193
- });
194
-
195
- describe('when a custom value of the maxNumberOfParts property is used', () => {
196
- const customMaxNumberOfParts = 3;
197
-
198
- it('should properly display the result collapsed path', async () => {
199
- const element = createTestComponent({
200
- result: exampleResultWithParents,
201
- engineId: exampleEngineId,
202
- maxNumberOfParts: customMaxNumberOfParts,
203
- });
204
- await flushPromises();
205
-
206
- const pathItems = Array.from(
207
- element.shadowRoot.querySelectorAll(selectors.pathItem)
208
- );
209
- const expandButton = element.shadowRoot.querySelector(
210
- selectors.pathExpandButton
211
- );
212
- expect(pathItems).not.toBeNull();
213
- expect(pathItems.length).toBe(customMaxNumberOfParts);
214
- pathItems
215
- .slice(0, customMaxNumberOfParts - 1)
216
- .forEach((item, index) => {
217
- expect(item.textContent).toBe(`parent${index + 1}`);
218
- expect(item.href).toBe(`${generateExampleUri(index + 1)}`);
219
- });
220
-
221
- expect(expandButton).not.toBeNull();
222
-
223
- expect(pathItems[customMaxNumberOfParts - 1].textContent).toBe(
224
- `parent${numberOfParents}`
225
- );
226
- expect(pathItems[customMaxNumberOfParts - 1].href).toBe(
227
- `${generateExampleUri(numberOfParents)}`
228
- );
229
- });
230
-
231
- describe('when expanding the result collapsed path', () => {
232
- it('should properly display the result expanded path', async () => {
233
- const element = createTestComponent({
234
- result: exampleResultWithParents,
235
- engineId: exampleEngineId,
236
- maxNumberOfParts: customMaxNumberOfParts,
237
- });
238
- await flushPromises();
239
-
240
- let expandButton = element.shadowRoot.querySelector(
241
- selectors.pathExpandButton
242
- );
243
-
244
- expect(expandButton).not.toBeNull();
245
-
246
- await expandButton.click();
247
-
248
- const pathItems = element.shadowRoot.querySelectorAll(
249
- selectors.pathItem
250
- );
251
- expandButton = element.shadowRoot.querySelector(
252
- selectors.pathExpandButton
253
- );
254
-
255
- expect(expandButton).toBeNull();
256
- expect(pathItems).not.toBeNull();
257
- expect(pathItems.length).toBe(numberOfParents);
258
- shouldProperlyDisplayAllPathItems(pathItems);
259
- });
260
- });
261
- });
262
- });
263
- });
264
-
265
- describe('when displaying the result url', () => {
266
- const exampleResult = {
267
- title: 'example title',
268
- clickUri: 'https://coveo.com/',
269
- raw: {
270
- parents: '',
271
- },
272
- };
273
-
274
- it('should display the printable uri using the quantic result link component', async () => {
275
- const customTarget = '_blank';
276
- const element = createTestComponent({
277
- result: exampleResult,
278
- target: customTarget,
279
- engineId: exampleEngineId,
280
- });
281
- await flushPromises();
282
-
283
- const link = element.shadowRoot.querySelector(selectors.link);
284
-
285
- expect(link).not.toBeNull();
286
- expect(link.engineId).toBe(exampleEngineId);
287
- expect(link.result).toEqual(exampleResult);
288
- expect(link.displayedField).toBe('printableUri');
289
- expect(link.target).toBe(customTarget);
290
- });
291
- });
292
-
293
- describe('when given invalid value of the property maxNumberOfParts', () => {
294
- const exampleResult = {
295
- title: 'example title',
296
- clickUri: 'https://coveo.com/',
297
- raw: {
298
- parents: '',
299
- },
300
- };
301
- const invalidMaxNumberOfParts = 1;
302
-
303
- it('should display an error message', async () => {
304
- const element = createTestComponent({
305
- engineId: exampleEngineId,
306
- result: exampleResult,
307
- maxNumberOfParts: invalidMaxNumberOfParts,
308
- });
309
- await flushPromises();
310
-
311
- const errorMessage = element.shadowRoot.querySelector(
312
- selectors.errorMessage
313
- );
314
-
315
- expect(errorMessage).not.toBeNull();
316
- expect(errorMessage.textContent).toBe(
317
- 'c-quantic-result-printable-uri Error'
318
- );
319
- expect(console.error).toHaveBeenCalledWith(
320
- `The provided value of ${invalidMaxNumberOfParts} for the maxNumberOfParts option is inadequate. The provided value must be at least ${MIN_MAX_NUMBER_OF_PARTS}.`
321
- );
322
- });
323
- });
324
- });
@@ -1,171 +0,0 @@
1
- import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
2
- // @ts-ignore
3
- import {createElement} from 'lwc';
4
- import QuanticResultQuickview from '../quanticResultQuickview';
5
-
6
- const selectors = {
7
- quickViewButton: '[data-cy="quick-view-button"]',
8
- };
9
-
10
- jest.mock('c/quanticHeadlessLoader');
11
- jest.mock(
12
- '@salesforce/label/c.quantic_OpenPreview',
13
- () => ({default: 'Open preview'}),
14
- {
15
- virtual: true,
16
- }
17
- );
18
- jest.mock(
19
- '@salesforce/label/c.quantic_OpenFileForPreview',
20
- () => ({default: 'Open file for preview'}),
21
- {
22
- virtual: true,
23
- }
24
- );
25
- jest.mock(
26
- '@salesforce/label/c.quantic_NoPreviewAvailable',
27
- () => ({default: 'No preview available'}),
28
- {
29
- virtual: true,
30
- }
31
- );
32
- jest.mock('@salesforce/label/c.quantic_Close', () => ({default: 'Close'}), {
33
- virtual: true,
34
- });
35
-
36
- const exampleResult = {
37
- raw: {
38
- date: '123',
39
- },
40
- title: 'abc',
41
- uniqueId: '123',
42
- };
43
-
44
- function createTestComponent(options = {result: exampleResult}) {
45
- const element = createElement('c-quantic-result-quick-view', {
46
- is: QuanticResultQuickview,
47
- });
48
-
49
- if (options) {
50
- for (const [key, value] of Object.entries(options)) {
51
- element[key] = value;
52
- }
53
- }
54
-
55
- document.body.appendChild(element);
56
- return element;
57
- }
58
-
59
- // Helper function to wait until the microtask queue is empty.
60
- function flushPromises() {
61
- // eslint-disable-next-line @lwc/lwc/no-async-operation
62
- return new Promise((resolve) => setTimeout(resolve, 0));
63
- }
64
-
65
- const functionMocks = {
66
- pushRecentResult: jest.fn(),
67
- };
68
-
69
- let useCase = 'search';
70
-
71
- function mockHeadless() {
72
- jest.spyOn(mockHeadlessLoader, 'getHeadlessBundle').mockReturnValue({
73
- buildQuickview: () => ({
74
- state: {resultHasPreview: true},
75
- fetchResultContent: jest.fn(),
76
- subscribe: jest.fn((callback) => {
77
- callback();
78
- }),
79
- cancelPendingSelect: jest.fn(),
80
- }),
81
- buildInteractiveResult: jest.fn(),
82
- loadRecentResultsActions: () => ({
83
- pushRecentResult: functionMocks.pushRecentResult,
84
- }),
85
- });
86
-
87
- jest
88
- .spyOn(mockHeadlessLoader, 'isHeadlessBundle')
89
- .mockReturnValue(useCase === 'search');
90
-
91
- jest.spyOn(mockHeadlessLoader, 'getHeadlessEnginePromise').mockReturnValue(
92
- new Promise((resolve) => {
93
- resolve({
94
- dispatch: jest.fn(),
95
- });
96
- })
97
- );
98
- }
99
-
100
- function mockBueno() {
101
- jest.spyOn(mockHeadlessLoader, 'getBueno').mockReturnValue(
102
- new Promise(() => {
103
- // @ts-ignore
104
- global.Bueno = {
105
- isString: jest
106
- .fn()
107
- .mockImplementation(
108
- (value) =>
109
- Object.prototype.toString.call(value) === '[object String]'
110
- ),
111
- };
112
- })
113
- );
114
- }
115
-
116
- function cleanup() {
117
- // The jsdom instance is shared across test cases in a single file so reset the DOM.
118
- while (document.body.firstChild) {
119
- document.body.removeChild(document.body.firstChild);
120
- }
121
- jest.clearAllMocks();
122
- }
123
-
124
- describe('c-quantic-result-quick-view', () => {
125
- beforeEach(() => {
126
- mockHeadless();
127
- mockBueno();
128
- });
129
-
130
- afterEach(() => {
131
- cleanup();
132
- });
133
-
134
- describe('when the component is used in the search use case', () => {
135
- beforeAll(() => {
136
- useCase = 'search';
137
- });
138
-
139
- it('should dispatch the pushRecentResult action', async () => {
140
- const element = createTestComponent();
141
- await flushPromises();
142
-
143
- const quickViewButton = element.shadowRoot.querySelector(
144
- selectors.quickViewButton
145
- );
146
- await quickViewButton.click();
147
- await flushPromises();
148
-
149
- expect(functionMocks.pushRecentResult).toHaveBeenCalled();
150
- });
151
- });
152
-
153
- describe('when the component is not used in the search use case', () => {
154
- beforeAll(() => {
155
- useCase = 'insight';
156
- });
157
-
158
- it('should not dispatch the pushRecentResult action', async () => {
159
- const element = createTestComponent();
160
- await flushPromises();
161
-
162
- const quickViewButton = element.shadowRoot.querySelector(
163
- selectors.quickViewButton
164
- );
165
- await quickViewButton.click();
166
- await flushPromises();
167
-
168
- expect(functionMocks.pushRecentResult).not.toHaveBeenCalled();
169
- });
170
- });
171
- });