@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,212 +0,0 @@
1
- // @ts-ignore
2
- import {createElement} from 'lwc';
3
- import QuanticColoredResultBadge from '../quanticColoredResultBadge';
4
-
5
- const badgeSelector = '.result-badge';
6
- const resultFieldSelector = 'c-quantic-result-field';
7
- const errorSelector = '.error-message';
8
-
9
- const defaultPrimaryColor = '#FFF7BA';
10
- const defaultSecondaryColor = 'black';
11
- const exampleLabel = 'Document';
12
- const exampleColor = '#FFFFFF';
13
- const defaultOptions = {
14
- color: exampleColor,
15
- label: exampleLabel,
16
- result: {
17
- raw: {
18
- testField: 'test value',
19
- },
20
- },
21
- field: 'testField',
22
- type: 'string',
23
- };
24
-
25
- const coloredResultBadgeError =
26
- 'The c-quantic-colored-result-badge requires a label or result and a field to be specified.';
27
- const coloredResultBadgeWarning =
28
- 'The color property has not been specified, the default colors will be used.';
29
- const coloredResultBadgeColorError = (color) =>
30
- `The "${color}" color is not a valid HEX color.`;
31
-
32
- function createTestComponent(options = defaultOptions) {
33
- const element = createElement('c-quantic-colored-result-badge', {
34
- is: QuanticColoredResultBadge,
35
- });
36
-
37
- for (const [key, value] of Object.entries(options)) {
38
- element[key] = value;
39
- }
40
-
41
- document.body.appendChild(element);
42
-
43
- return element;
44
- }
45
-
46
- // Helper function to wait until the microtask queue is empty.
47
- function flushPromises() {
48
- return new Promise((resolve) => setTimeout(resolve, 0));
49
- }
50
-
51
- describe('c-quantic-colored-result-badge', () => {
52
- function cleanup() {
53
- // The jsdom instance is shared across test cases in a single file so reset the DOM
54
- while (document.body.firstChild) {
55
- document.body.removeChild(document.body.firstChild);
56
- }
57
- }
58
-
59
- beforeEach(() => {
60
- console.error = jest.fn();
61
- console.warn = jest.fn();
62
- // @ts-ignore
63
- global.Bueno = {
64
- isString: jest
65
- .fn()
66
- .mockImplementation(
67
- (value) => Object.prototype.toString.call(value) === '[object String]'
68
- ),
69
- isNumber: jest
70
- .fn()
71
- .mockImplementation(
72
- (value) => typeof value === 'number' && !isNaN(value)
73
- ),
74
- };
75
- });
76
-
77
- afterEach(() => {
78
- cleanup();
79
- jest.clearAllMocks();
80
- });
81
-
82
- describe('when the badge is used to display a label', () => {
83
- describe('when a label is given', () => {
84
- it('should display the colored badge with the correct label and color', async () => {
85
- const element = createTestComponent({
86
- ...defaultOptions,
87
- result: null,
88
- field: null,
89
- });
90
- await flushPromises();
91
-
92
- const badge = element.shadowRoot.querySelector(badgeSelector);
93
-
94
- expect(badge).not.toBeNull();
95
- expect(badge.textContent).toBe(exampleLabel);
96
- expect(badge.style._values['--primaryColor']).toBe(exampleColor);
97
- expect(badge.style._values['--secondaryColor']).toBe('black');
98
- });
99
- });
100
-
101
- describe('when no label is given', () => {
102
- it('should show an error', async () => {
103
- const element = createTestComponent({
104
- ...defaultOptions,
105
- label: null,
106
- result: null,
107
- field: null,
108
- });
109
- await flushPromises();
110
-
111
- const errorMessage = element.shadowRoot.querySelector(errorSelector);
112
-
113
- expect(errorMessage).not.toBeNull();
114
- expect(console.error).toHaveBeenCalledWith(coloredResultBadgeError);
115
- });
116
- });
117
- });
118
-
119
- describe('when the badge is used to display a result field', () => {
120
- describe('when a result and a field are provided', () => {
121
- it('should display the colored badge with the correct result field', async () => {
122
- const element = createTestComponent({
123
- ...defaultOptions,
124
- label: undefined,
125
- });
126
- await flushPromises();
127
-
128
- const badge = element.shadowRoot.querySelector(badgeSelector);
129
- const resultField =
130
- element.shadowRoot.querySelector(resultFieldSelector);
131
-
132
- expect(badge).not.toBeNull();
133
- expect(resultField).not.toBeNull();
134
- expect(resultField.result).toEqual(defaultOptions.result);
135
- expect(resultField.field).toEqual(defaultOptions.field);
136
- expect(resultField.type).toEqual(defaultOptions.type);
137
- expect(badge.style._values['--primaryColor']).toBe(exampleColor);
138
- expect(badge.style._values['--secondaryColor']).toBe('black');
139
- });
140
- });
141
-
142
- describe('when no result is given', () => {
143
- it('should show an error', async () => {
144
- const element = createTestComponent({
145
- ...defaultOptions,
146
- label: null,
147
- result: null,
148
- });
149
- await flushPromises();
150
-
151
- const errorMessage = element.shadowRoot.querySelector(errorSelector);
152
-
153
- expect(errorMessage).not.toBeNull();
154
- expect(console.error).toHaveBeenCalledWith(coloredResultBadgeError);
155
- });
156
- });
157
-
158
- describe('when no field is given', () => {
159
- it('should show an error', async () => {
160
- const element = createTestComponent({
161
- ...defaultOptions,
162
- label: null,
163
- field: null,
164
- });
165
- await flushPromises();
166
-
167
- const errorMessage = element.shadowRoot.querySelector(errorSelector);
168
-
169
- expect(errorMessage).not.toBeNull();
170
- expect(console.error).toHaveBeenCalledWith(coloredResultBadgeError);
171
- });
172
- });
173
- });
174
-
175
- describe('when no color is given', () => {
176
- it('should display the colored badge with the default colors', async () => {
177
- const element = createTestComponent({
178
- ...defaultOptions,
179
- color: null,
180
- });
181
- await flushPromises();
182
-
183
- const badge = element.shadowRoot.querySelector(badgeSelector);
184
-
185
- expect(badge).not.toBeNull();
186
- expect(badge.textContent).toBe(exampleLabel);
187
- expect(badge.style._values['--primaryColor']).toBe(defaultPrimaryColor);
188
- expect(badge.style._values['--secondaryColor']).toBe(
189
- defaultSecondaryColor
190
- );
191
- expect(console.warn).toHaveBeenCalledWith(coloredResultBadgeWarning);
192
- });
193
- });
194
-
195
- describe('when an invalid color is given', () => {
196
- it('should show an error', async () => {
197
- const invalidColor = 'invalid color';
198
- const element = createTestComponent({
199
- ...defaultOptions,
200
- color: invalidColor,
201
- });
202
- await flushPromises();
203
-
204
- const errorMessage = element.shadowRoot.querySelector(errorSelector);
205
-
206
- expect(errorMessage).not.toBeNull();
207
- expect(console.error).toHaveBeenCalledWith(
208
- coloredResultBadgeColorError(invalidColor)
209
- );
210
- });
211
- });
212
- });
@@ -1,321 +0,0 @@
1
- /* eslint-disable no-import-assign */
2
- // @ts-ignore
3
- import {createElement} from 'lwc';
4
- import QuanticDateFacet from 'c/quanticDateFacet';
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
- DATEFACETS: 'dateFacets',
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 dateFacetControllerMock = {
32
- subscribe: jest.fn((callback) => callback()),
33
- state: {
34
- facetId: exampleFacetId,
35
- values: [],
36
- },
37
- };
38
- const parentFacetIdError = `The ${exampleField} c-quantic-date-facet requires dependsOn.parentFacetId to be a valid string.`;
39
- const expectedValueError = `The ${exampleField} c-quantic-date-facet requires dependsOn.expectedValue to be a valid string.`;
40
-
41
- function createTestComponent(options = defaultOptions) {
42
- prepareHeadlessState();
43
-
44
- const element = createElement('c-quantic-date-facet', {
45
- is: QuanticDateFacet,
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
- buildDateFacet: jest.fn(() => dateFacetControllerMock),
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
- buildDateFacet: functionsMocks.buildDateFacet,
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 mockBueno() {
90
- // @ts-ignore
91
- mockHeadlessLoader.getBueno = () => {
92
- // @ts-ignore
93
- global.Bueno = {
94
- isString: jest
95
- .fn()
96
- .mockImplementation(
97
- (value) => Object.prototype.toString.call(value) === '[object String]'
98
- ),
99
- };
100
- return new Promise((resolve) => resolve());
101
- };
102
- }
103
-
104
- function mockSuccessfulHeadlessInitialization() {
105
- // @ts-ignore
106
- mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => {
107
- if (element instanceof QuanticDateFacet && !isInitialized) {
108
- isInitialized = true;
109
- initialize(exampleEngine);
110
- }
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-date-facet', () => {
124
- beforeAll(() => {
125
- mockSuccessfulHeadlessInitialization();
126
- mockBueno();
127
- });
128
-
129
- afterEach(() => {
130
- cleanup();
131
- });
132
-
133
- describe('the facet conditions manager', () => {
134
- it('should build the controller when the dependsOn property is set', async () => {
135
- const exampleFacetDependency = {
136
- parentFacetId: 'filetype',
137
- expectedValue: 'txt',
138
- };
139
- createTestComponent({
140
- ...defaultOptions,
141
- dependsOn: exampleFacetDependency,
142
- });
143
- await flushPromises();
144
-
145
- expect(functionsMocks.buildDateFacet).toHaveBeenCalledTimes(1);
146
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
147
- 1
148
- );
149
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledWith(
150
- exampleEngine,
151
- {
152
- facetId: exampleFacetId,
153
- }
154
- );
155
-
156
- expect(generateFacetDependencyConditions).toHaveBeenCalledTimes(1);
157
- expect(generateFacetDependencyConditions).toHaveBeenCalledWith({
158
- [exampleFacetDependency.parentFacetId]:
159
- exampleFacetDependency.expectedValue,
160
- });
161
- });
162
-
163
- it('should not build the controller when the dependsOn property is not set', async () => {
164
- createTestComponent();
165
- await flushPromises();
166
-
167
- expect(functionsMocks.buildDateFacet).toHaveBeenCalledTimes(1);
168
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
169
- 0
170
- );
171
- expect(generateFacetDependencyConditions).toHaveBeenCalledTimes(0);
172
- });
173
- });
174
-
175
- describe('the facet enablement', () => {
176
- describe('when the facet is enabled', () => {
177
- beforeAll(() => {
178
- functionsMocks.buildDateFacet.mockReturnValue({
179
- ...dateFacetControllerMock,
180
- state: {...dateFacetControllerMock.state, enabled: true},
181
- });
182
- });
183
-
184
- it('should display the facet content', async () => {
185
- const element = createTestComponent();
186
- await flushPromises();
187
-
188
- const facetContent = element.shadowRoot.querySelector(
189
- selectors.facetContent
190
- );
191
- expect(facetContent).not.toBeNull();
192
- });
193
- });
194
-
195
- describe('when the facet is not enabled', () => {
196
- beforeAll(() => {
197
- functionsMocks.buildDateFacet.mockReturnValue({
198
- ...dateFacetControllerMock,
199
- state: {...dateFacetControllerMock.state, enabled: false},
200
- });
201
- });
202
-
203
- it('should not display the facet content', async () => {
204
- const element = createTestComponent();
205
- await flushPromises();
206
-
207
- const facetContent = element.shadowRoot.querySelector(
208
- selectors.facetContent
209
- );
210
- expect(facetContent).toBeNull();
211
- });
212
- });
213
-
214
- afterAll(() => {
215
- functionsMocks.buildDateFacet.mockReturnValue(dateFacetControllerMock);
216
- });
217
- });
218
-
219
- describe('validation of the dependsOn property', () => {
220
- let consoleError;
221
- beforeAll(() => {
222
- consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
223
- });
224
- describe('when dependsOn.parentFacetId is not provided', () => {
225
- it('should display the error component', async () => {
226
- const invalidFacetDependency = {
227
- expectedValue: 'txt',
228
- };
229
- const element = createTestComponent({
230
- ...defaultOptions,
231
- dependsOn: invalidFacetDependency,
232
- });
233
- await flushPromises();
234
-
235
- const componentError = element.shadowRoot.querySelector(
236
- selectors.componentError
237
- );
238
- const facetContent = element.shadowRoot.querySelector(
239
- selectors.facetContent
240
- );
241
-
242
- expect(consoleError).toHaveBeenCalledTimes(1);
243
- expect(consoleError).toHaveBeenCalledWith(parentFacetIdError);
244
- expect(componentError).not.toBeNull();
245
- expect(facetContent).toBeNull();
246
- });
247
- });
248
-
249
- describe('when dependsOn.parentFacetId is not a string', () => {
250
- it('should display the error component', async () => {
251
- const invalidFacetDependency = {
252
- parentFacetId: 1,
253
- expectedValue: 'txt',
254
- };
255
- const element = createTestComponent({
256
- ...defaultOptions,
257
- dependsOn: invalidFacetDependency,
258
- });
259
- await flushPromises();
260
-
261
- const componentError = element.shadowRoot.querySelector(
262
- selectors.componentError
263
- );
264
- const facetContent = element.shadowRoot.querySelector(
265
- selectors.facetContent
266
- );
267
-
268
- expect(consoleError).toHaveBeenCalledTimes(1);
269
- expect(consoleError).toHaveBeenCalledWith(parentFacetIdError);
270
- expect(componentError).not.toBeNull();
271
- expect(facetContent).toBeNull();
272
- });
273
- });
274
-
275
- describe('when dependsOn.expectedValue is not a string', () => {
276
- it('should display the error component', async () => {
277
- const invalidFacetDependency = {
278
- parentFacetId: 'filetype',
279
- expectedValue: 2,
280
- };
281
- const element = createTestComponent({
282
- ...defaultOptions,
283
- dependsOn: invalidFacetDependency,
284
- });
285
- await flushPromises();
286
-
287
- const componentError = element.shadowRoot.querySelector(
288
- selectors.componentError
289
- );
290
- const facetContent = element.shadowRoot.querySelector(
291
- selectors.facetContent
292
- );
293
-
294
- expect(consoleError).toHaveBeenCalledTimes(1);
295
- expect(consoleError).toHaveBeenCalledWith(expectedValueError);
296
- expect(componentError).not.toBeNull();
297
- expect(facetContent).toBeNull();
298
- });
299
- });
300
- });
301
-
302
- describe('when the component is disconnected', () => {
303
- it('should make the condition manager stop watching the facet', async () => {
304
- const exampleFacetDependency = {
305
- parentFacetId: 'filetype',
306
- expectedValue: 'txt',
307
- };
308
- const element = createTestComponent({
309
- ...defaultOptions,
310
- dependsOn: exampleFacetDependency,
311
- });
312
- await flushPromises();
313
- expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
314
- 1
315
- );
316
-
317
- document.body.removeChild(element);
318
- expect(functionsMocks.stopWatching).toHaveBeenCalledTimes(1);
319
- });
320
- });
321
- });