@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,199 +0,0 @@
1
- /* eslint-disable no-import-assign */
2
- // @ts-ignore
3
- import {createElement} from 'lwc';
4
- import QuanticDidYouMean from '../quanticDidYouMean';
5
- import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
6
-
7
- jest.mock('c/quanticHeadlessLoader');
8
-
9
- let isInitialized = false;
10
-
11
- const exampleEngine = {
12
- id: 'exampleEngineId',
13
- };
14
-
15
- const defaultQueryCorrectionMode = 'legacy';
16
-
17
- const defaultOptions = {
18
- engineId: exampleEngine.id,
19
- disableQueryAutoCorrection: false,
20
- queryCorrectionMode: defaultQueryCorrectionMode,
21
- };
22
-
23
- const mockDidYouMeanState = {
24
- wasCorrectedTo: 'example corrected query',
25
- originalQuery: 'example original query',
26
- wasAutomaticallyCorrected: true,
27
- queryCorrection: {
28
- correctedQuery: 'example corrected query',
29
- wordCorrected: 'example',
30
- },
31
- hasQueryCorrection: true,
32
- };
33
-
34
- const functionsMocks = {
35
- buildDidYouMean: jest.fn(() => ({
36
- state: mockDidYouMeanState,
37
- subscribe: functionsMocks.subscribe,
38
- })),
39
- buildQueryTrigger: jest.fn(() => ({
40
- state: {},
41
- subscribe: functionsMocks.subscribe,
42
- })),
43
- applyCorrection: jest.fn(() => {}),
44
- subscribe: jest.fn((cb) => {
45
- cb();
46
- return functionsMocks.unsubscribe;
47
- }),
48
- unsubscribe: jest.fn(() => {}),
49
- };
50
-
51
- function prepareHeadlessState() {
52
- // @ts-ignore
53
- mockHeadlessLoader.getHeadlessBundle = () => {
54
- return {
55
- buildDidYouMean: functionsMocks.buildDidYouMean,
56
- buildQueryTrigger: functionsMocks.buildQueryTrigger,
57
- };
58
- };
59
- }
60
-
61
- function mockSuccessfulHeadlessInitialization() {
62
- // @ts-ignore
63
- mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => {
64
- if (element instanceof QuanticDidYouMean && !isInitialized) {
65
- isInitialized = true;
66
- initialize(exampleEngine);
67
- }
68
- };
69
- }
70
-
71
- function createTestComponent(options = defaultOptions) {
72
- prepareHeadlessState();
73
- const element = createElement('c-quantic-did-you-mean', {
74
- is: QuanticDidYouMean,
75
- });
76
-
77
- for (const [key, value] of Object.entries(options)) {
78
- element[key] = value;
79
- }
80
-
81
- document.body.appendChild(element);
82
- return element;
83
- }
84
-
85
- // Helper function to wait until the microtask queue is empty.
86
- async function flushPromises() {
87
- return Promise.resolve();
88
- }
89
-
90
- describe('c-quantic-did-you-mean', () => {
91
- function cleanup() {
92
- // The jsdom instance is shared across test cases in a single file so reset the DOM
93
- while (document.body.firstChild) {
94
- document.body.removeChild(document.body.firstChild);
95
- }
96
- jest.clearAllMocks();
97
- isInitialized = false;
98
- }
99
-
100
- beforeEach(() => {
101
- mockSuccessfulHeadlessInitialization();
102
- });
103
-
104
- afterEach(() => {
105
- cleanup();
106
- });
107
-
108
- describe('controller initialization', () => {
109
- it('should subscribe to the headless state changes', async () => {
110
- createTestComponent();
111
- await flushPromises();
112
-
113
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalled();
114
- expect(functionsMocks.subscribe).toHaveBeenCalled();
115
- });
116
-
117
- describe('#disableQueryAutoCorrection property', () => {
118
- describe('when disableQueryAutoCorrection is false (default)', () => {
119
- it('should properly initialize the controller with automatic query correction enabled', async () => {
120
- createTestComponent();
121
- await flushPromises();
122
-
123
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalledTimes(1);
124
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalledWith(
125
- exampleEngine,
126
- expect.objectContaining({
127
- options: expect.objectContaining({
128
- automaticallyCorrectQuery: true,
129
- queryCorrectionMode: defaultQueryCorrectionMode,
130
- }),
131
- })
132
- );
133
- });
134
- });
135
-
136
- describe('when disableQueryAutoCorrection is true', () => {
137
- it('should properly initialize the controller with automatic query correction disabled', async () => {
138
- createTestComponent({
139
- ...defaultOptions,
140
- disableQueryAutoCorrection: true,
141
- });
142
- await flushPromises();
143
-
144
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalledTimes(1);
145
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalledWith(
146
- exampleEngine,
147
- expect.objectContaining({
148
- options: expect.objectContaining({
149
- automaticallyCorrectQuery: false,
150
- queryCorrectionMode: defaultQueryCorrectionMode,
151
- }),
152
- })
153
- );
154
- });
155
- });
156
- });
157
-
158
- describe('#queryCorrectionMode property', () => {
159
- describe('when queryCorrectionMode is `legacy` (default)', () => {
160
- it('should properly initialize the controller with the query correction mode set to `legacy`', async () => {
161
- createTestComponent();
162
- await flushPromises();
163
-
164
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalledTimes(1);
165
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalledWith(
166
- exampleEngine,
167
- expect.objectContaining({
168
- options: expect.objectContaining({
169
- automaticallyCorrectQuery: true,
170
- queryCorrectionMode: defaultQueryCorrectionMode,
171
- }),
172
- })
173
- );
174
- });
175
- });
176
-
177
- describe('when queryCorrectionMode is `next`', () => {
178
- it('should properly initialize the controller with the query correction mode set to `next`', async () => {
179
- createTestComponent({
180
- ...defaultOptions,
181
- queryCorrectionMode: 'next',
182
- });
183
- await flushPromises();
184
-
185
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalledTimes(1);
186
- expect(functionsMocks.buildDidYouMean).toHaveBeenCalledWith(
187
- exampleEngine,
188
- expect.objectContaining({
189
- options: expect.objectContaining({
190
- automaticallyCorrectQuery: true,
191
- queryCorrectionMode: 'next',
192
- }),
193
- })
194
- );
195
- });
196
- });
197
- });
198
- });
199
- });
@@ -1,341 +0,0 @@
1
- /* eslint-disable no-import-assign */
2
- // @ts-ignore
3
- import {createElement} from 'lwc';
4
- import QuanticFacet from 'c/quanticFacet';
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
- },
14
- },
15
- I18nUtils: {
16
- format: jest.fn(),
17
- },
18
- }));
19
- jest.mock('c/quanticHeadlessLoader');
20
-
21
- const selectors = {
22
- facetContent: '[data-test="facet-content"]',
23
- componentError: 'c-quantic-component-error',
24
- };
25
-
26
- const exampleFacetId = 'example facet id';
27
- const exampleField = 'exampleField';
28
- const defaultOptions = {
29
- field: exampleField,
30
- };
31
- const facetControllerMock = {
32
- subscribe: jest.fn((callback) => callback()),
33
- state: {
34
- facetId: exampleFacetId,
35
- values: [],
36
- },
37
- };
38
- const parentFacetIdError = `The ${exampleField} c-quantic-facet requires dependsOn.parentFacetId to be a valid string.`;
39
- const expectedValueError = `The ${exampleField} c-quantic-facet requires dependsOn.expectedValue to be a valid string.`;
40
-
41
- function createTestComponent(options = defaultOptions) {
42
- prepareHeadlessState();
43
-
44
- const element = createElement('c-quantic-facet', {
45
- is: QuanticFacet,
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
- const functionsMocks = {
56
- buildFacet: jest.fn(() => facetControllerMock),
57
- stopWatching: jest.fn(),
58
- buildFacetConditionsManager: jest.fn(() => ({
59
- stopWatching: functionsMocks.stopWatching,
60
- })),
61
- buildSearchStatus: jest.fn(() => ({
62
- subscribe: jest.fn((callback) => callback()),
63
- state: {},
64
- })),
65
- };
66
-
67
- function prepareHeadlessState() {
68
- // @ts-ignore
69
- mockHeadlessLoader.getHeadlessBundle = () => {
70
- return {
71
- buildFacet: functionsMocks.buildFacet,
72
- buildSearchStatus: functionsMocks.buildSearchStatus,
73
- buildFacetConditionsManager: functionsMocks.buildFacetConditionsManager,
74
- };
75
- };
76
- }
77
-
78
- // Helper function to wait until the microtask queue is empty.
79
- function flushPromises() {
80
- // eslint-disable-next-line @lwc/lwc/no-async-operation
81
- return new Promise((resolve) => setTimeout(resolve, 0));
82
- }
83
-
84
- const exampleEngine = {
85
- id: 'dummy engine',
86
- };
87
- let isInitialized = false;
88
-
89
- function mockSuccessfulHeadlessInitialization() {
90
- // @ts-ignore
91
- mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => {
92
- if (element instanceof QuanticFacet && !isInitialized) {
93
- isInitialized = true;
94
- initialize(exampleEngine);
95
- }
96
- };
97
- }
98
-
99
- function mockBueno() {
100
- // @ts-ignore
101
- mockHeadlessLoader.getBueno = () => {
102
- // @ts-ignore
103
- global.Bueno = {
104
- isString: jest
105
- .fn()
106
- .mockImplementation(
107
- (value) => Object.prototype.toString.call(value) === '[object String]'
108
- ),
109
- };
110
- return new Promise((resolve) => resolve());
111
- };
112
- }
113
-
114
- function cleanup() {
115
- // The jsdom instance is shared across test cases in a single file so reset the DOM
116
- while (document.body.firstChild) {
117
- document.body.removeChild(document.body.firstChild);
118
- }
119
- jest.clearAllMocks();
120
- isInitialized = false;
121
- }
122
-
123
- describe('c-quantic-facet', () => {
124
- beforeAll(() => {
125
- mockSuccessfulHeadlessInitialization();
126
- mockBueno();
127
- });
128
-
129
- afterEach(() => {
130
- cleanup();
131
- });
132
-
133
- describe('controller initialization', () => {
134
- it('should initialize the controller with the correct customSort value', async () => {
135
- const exampleCustomSortValues = ['test'];
136
- createTestComponent({
137
- ...defaultOptions,
138
- customSort: exampleCustomSortValues,
139
- });
140
- await flushPromises();
141
-
142
- expect(functionsMocks.buildFacet).toHaveBeenCalledTimes(1);
143
- expect(functionsMocks.buildFacet).toHaveBeenCalledWith(
144
- exampleEngine,
145
- expect.objectContaining({
146
- options: expect.objectContaining({
147
- customSort: exampleCustomSortValues,
148
- }),
149
- })
150
- );
151
- });
152
- });
153
-
154
- describe('the facet conditions manager', () => {
155
- it('should build the controller when the dependsOn property is set', async () => {
156
- const exampleFacetDependency = {
157
- parentFacetId: 'filetype',
158
- expectedValue: 'txt',
159
- };
160
- createTestComponent({
161
- ...defaultOptions,
162
- dependsOn: exampleFacetDependency,
163
- });
164
- await flushPromises();
165
-
166
- expect(functionsMocks.buildFacet).toHaveBeenCalledTimes(1);
167
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
168
- 1
169
- );
170
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledWith(
171
- exampleEngine,
172
- {
173
- facetId: exampleFacetId,
174
- }
175
- );
176
-
177
- expect(generateFacetDependencyConditions).toHaveBeenCalledTimes(1);
178
- expect(generateFacetDependencyConditions).toHaveBeenCalledWith({
179
- [exampleFacetDependency.parentFacetId]:
180
- exampleFacetDependency.expectedValue,
181
- });
182
- });
183
-
184
- it('should not build the controller when the dependsOn property is not set', async () => {
185
- createTestComponent();
186
- await flushPromises();
187
-
188
- expect(functionsMocks.buildFacet).toHaveBeenCalledTimes(1);
189
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
190
- 0
191
- );
192
- expect(generateFacetDependencyConditions).toHaveBeenCalledTimes(0);
193
- });
194
- });
195
-
196
- describe('the facet enablement', () => {
197
- describe('when the facet is enabled', () => {
198
- beforeAll(() => {
199
- functionsMocks.buildFacet.mockReturnValue({
200
- ...facetControllerMock,
201
- state: {...facetControllerMock.state, enabled: true},
202
- });
203
- });
204
-
205
- it('should display the facet content', async () => {
206
- const element = createTestComponent();
207
- await flushPromises();
208
-
209
- const facetContent = element.shadowRoot.querySelector(
210
- selectors.facetContent
211
- );
212
- expect(facetContent).not.toBeNull();
213
- });
214
- });
215
-
216
- describe('when the facet is not enabled', () => {
217
- beforeAll(() => {
218
- functionsMocks.buildFacet.mockReturnValue({
219
- ...facetControllerMock,
220
- state: {...facetControllerMock.state, enabled: false},
221
- });
222
- });
223
-
224
- it('should not display the facet content', async () => {
225
- const element = createTestComponent();
226
- await flushPromises();
227
-
228
- const facetContent = element.shadowRoot.querySelector(
229
- selectors.facetContent
230
- );
231
- expect(facetContent).toBeNull();
232
- });
233
- });
234
-
235
- afterAll(() => {
236
- functionsMocks.buildFacet.mockReturnValue(facetControllerMock);
237
- });
238
- });
239
-
240
- describe('validation of the dependsOn property', () => {
241
- let consoleError;
242
- beforeAll(() => {
243
- consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
244
- });
245
- describe('when dependsOn.parentFacetId is not provided', () => {
246
- it('should display the error component', async () => {
247
- const invalidFacetDependency = {
248
- expectedValue: 'txt',
249
- };
250
- const element = createTestComponent({
251
- ...defaultOptions,
252
- dependsOn: invalidFacetDependency,
253
- });
254
- await flushPromises();
255
-
256
- const componentError = element.shadowRoot.querySelector(
257
- selectors.componentError
258
- );
259
- const facetContent = element.shadowRoot.querySelector(
260
- selectors.facetContent
261
- );
262
-
263
- expect(consoleError).toHaveBeenCalledTimes(1);
264
- expect(consoleError).toHaveBeenCalledWith(parentFacetIdError);
265
- expect(componentError).not.toBeNull();
266
- expect(facetContent).toBeNull();
267
- });
268
- });
269
-
270
- describe('when dependsOn.parentFacetId is not a string', () => {
271
- it('should display the error component', async () => {
272
- const invalidFacetDependency = {
273
- parentFacetId: 1,
274
- expectedValue: 'txt',
275
- };
276
- const element = createTestComponent({
277
- ...defaultOptions,
278
- dependsOn: invalidFacetDependency,
279
- });
280
- await flushPromises();
281
-
282
- const componentError = element.shadowRoot.querySelector(
283
- selectors.componentError
284
- );
285
- const facetContent = element.shadowRoot.querySelector(
286
- selectors.facetContent
287
- );
288
-
289
- expect(consoleError).toHaveBeenCalledTimes(1);
290
- expect(consoleError).toHaveBeenCalledWith(parentFacetIdError);
291
- expect(componentError).not.toBeNull();
292
- expect(facetContent).toBeNull();
293
- });
294
- });
295
-
296
- describe('when dependsOn.expectedValue is not a string', () => {
297
- it('should display the error component', async () => {
298
- const invalidFacetDependency = {
299
- parentFacetId: 'filetype',
300
- expectedValue: 2,
301
- };
302
- const element = createTestComponent({
303
- ...defaultOptions,
304
- dependsOn: invalidFacetDependency,
305
- });
306
- await flushPromises();
307
-
308
- const componentError = element.shadowRoot.querySelector(
309
- selectors.componentError
310
- );
311
- const facetContent = element.shadowRoot.querySelector(
312
- selectors.facetContent
313
- );
314
-
315
- expect(consoleError).toHaveBeenCalledTimes(1);
316
- expect(consoleError).toHaveBeenCalledWith(expectedValueError);
317
- expect(componentError).not.toBeNull();
318
- expect(facetContent).toBeNull();
319
- });
320
- });
321
- });
322
- describe('when the component is disconnected', () => {
323
- it('should make the condition manager stop watching the facet', async () => {
324
- const exampleFacetDependency = {
325
- parentFacetId: 'filetype',
326
- expectedValue: 'txt',
327
- };
328
- const element = createTestComponent({
329
- ...defaultOptions,
330
- dependsOn: exampleFacetDependency,
331
- });
332
- await flushPromises();
333
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
334
- 1
335
- );
336
-
337
- document.body.removeChild(element);
338
- expect(functionsMocks.stopWatching).toHaveBeenCalledTimes(1);
339
- });
340
- });
341
- });
@@ -1,28 +0,0 @@
1
- // @ts-ignore
2
- import {createElement} from 'lwc';
3
- import QuanticFacetCaption from '../quanticFacetCaption';
4
-
5
- function createTestComponent(options) {
6
- const element = createElement('c-quantic-facet-caption', {
7
- is: QuanticFacetCaption,
8
- });
9
-
10
- for (const [key, value] of Object.entries(options)) {
11
- element[key] = value;
12
- }
13
-
14
- document.body.appendChild(element);
15
- return element;
16
- }
17
-
18
- describe('c-quantic-facet-caption', () => {
19
- it('should expose captions through the `captions` property', () => {
20
- const value = 'the-facet-value';
21
- const caption = 'The custom caption';
22
- const element = createTestComponent({value, caption});
23
-
24
- const captions = element.captions;
25
-
26
- expect(captions[value]).toBe(caption);
27
- });
28
- });