@coveo/quantic 3.13.0 → 3.14.0

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 (52) hide show
  1. package/docs/out/quantic-docs.json +11 -2
  2. package/force-app/main/default/labels/CustomLabels.labels-meta.xml +2 -2
  3. package/force-app/main/default/lwc/quanticBreadcrumbManager/__tests__/quanticBreadcrumbManager.test.js +6 -12
  4. package/force-app/main/default/lwc/quanticGeneratedAnswer/__tests__/quanticGeneratedAnswer.test.js +113 -6
  5. package/force-app/main/default/lwc/quanticGeneratedAnswer/quanticGeneratedAnswer.js +32 -5
  6. package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/generatedAnswer.html +1 -1
  7. package/force-app/main/default/lwc/quanticResultsPerPage/__tests__/quanticResultsPerPage.test.js +404 -0
  8. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/fixture.ts +74 -0
  9. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/pageObject.ts +85 -0
  10. package/force-app/main/default/lwc/quanticResultsPerPage/e2e/quanticResultsPerPage.e2e.ts +97 -0
  11. package/force-app/main/default/lwc/quanticResultsPerPage/quanticResultsPerPage.html +1 -1
  12. package/force-app/main/default/lwc/quanticResultsPerPage/quanticResultsPerPage.js +44 -9
  13. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/data.ts +2 -11
  14. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/fixture.ts +9 -5
  15. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/pageObject.ts +1 -1
  16. package/force-app/main/default/lwc/quanticSmartSnippetAnswer/quanticSmartSnippetAnswer.html +1 -1
  17. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/__tests__/quanticSmartSnippetSuggestions.test.js +329 -0
  18. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/data.ts +31 -0
  19. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/fixture.ts +93 -0
  20. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/pageObject.ts +160 -0
  21. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/quanticSmartSnippetSuggestions.e2e.ts +127 -0
  22. package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/quanticSmartSnippetSuggestions.html +2 -1
  23. package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +6 -6
  24. package/force-app/main/default/staticresources/coveoheadless/definitions/api/service/insight/get-interface/get-interface-config-response.d.ts +5 -1
  25. package/force-app/main/default/staticresources/coveoheadless/definitions/commerce.index.d.ts +1 -0
  26. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/context/cart/headless-cart.ssr.d.ts +0 -2
  27. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/context/headless-context.ssr.d.ts +0 -2
  28. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.d.ts +0 -2
  29. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/facets/generator/headless-commerce-facet-generator.ssr.d.ts +0 -2
  30. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/pagination/headless-core-commerce-pagination.ssr.d.ts +0 -2
  31. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/parameter-manager/headless-core-parameter-manager.ssr.d.ts +0 -2
  32. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/sort/headless-core-commerce-sort.ssr.d.ts +0 -2
  33. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/summary/headless-core-summary.ssr.d.ts +0 -2
  34. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/field-suggestions/headless-field-suggestions-generator.ssr.d.ts +0 -2
  35. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/instant-products/headless-instant-products.ssr.d.ts +0 -2
  36. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/product-list/headless-product-list.ssr.d.ts +3 -4
  37. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/product-view/headless-product-view.ssr.d.ts +0 -1
  38. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recent-queries-list/headless-recent-queries-list.ssr.d.ts +0 -2
  39. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recommendations/headless-recommendations.ssr.d.ts +0 -4
  40. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/search/did-you-mean/headless-did-you-mean.ssr.d.ts +1 -3
  41. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/search-box/headless-search-box.d.ts +1 -1
  42. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/search-box/headless-search-box.ssr.d.ts +1 -3
  43. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/standalone-search-box/headless-standalone-search-box.ssr.d.ts +0 -2
  44. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/triggers/headless-notify-trigger.ssr.d.ts +0 -2
  45. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/triggers/headless-query-trigger.ssr.d.ts +0 -2
  46. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/triggers/headless-redirection-trigger.ssr.d.ts +0 -2
  47. package/force-app/main/default/staticresources/coveoheadless/definitions/features/recent-queries/recent-queries-slice.d.ts +4 -2
  48. package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-commerce.index.d.ts +4 -3
  49. package/force-app/main/default/staticresources/coveoheadless/headless.js +8 -8
  50. package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +7 -7
  51. package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +6 -6
  52. package/package.json +10 -10
@@ -0,0 +1,404 @@
1
+ /* eslint-disable no-import-assign */
2
+ import QuanticResultsPerPage from 'c/quanticResultsPerPage';
3
+ import {createElement} from 'lwc';
4
+ import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
5
+
6
+ const initialResultsPerPageState = {numberOfResults: 10};
7
+ let resultsPerPageState = initialResultsPerPageState;
8
+
9
+ const initialSearchStatusState = {hasResults: true};
10
+ let searchStatusState = initialSearchStatusState;
11
+
12
+ const initialStoreState = {};
13
+ let storeState = initialStoreState;
14
+
15
+ const functionsMocks = {
16
+ buildResultsPerPage: jest.fn(() => ({
17
+ state: resultsPerPageState,
18
+ subscribe: functionsMocks.resultsPerPageStateSubscriber,
19
+ set: functionsMocks.set,
20
+ })),
21
+ resultsPerPageStateSubscriber: jest.fn((cb) => {
22
+ cb();
23
+ return functionsMocks.resultsPerPageStateUnsubscriber;
24
+ }),
25
+ resultsPerPageStateUnsubscriber: jest.fn(),
26
+ buildSearchStatus: jest.fn(() => ({
27
+ state: searchStatusState,
28
+ subscribe: functionsMocks.searchStatusStateSubscriber,
29
+ })),
30
+ searchStatusStateSubscriber: jest.fn((cb) => {
31
+ cb();
32
+ return functionsMocks.searchStatusStateUnsubscriber;
33
+ }),
34
+ searchStatusStateUnsubscriber: jest.fn(),
35
+ set: jest.fn(),
36
+ };
37
+
38
+ const selectors = {
39
+ componentError: 'c-quantic-component-error',
40
+ resultsPerPage: '[data-testid="results-per-page"]',
41
+ resultsPerPageOption: 'c-quantic-number-button',
42
+ selectedResultsPerPageOption:
43
+ 'c-quantic-number-button button.slds-button_brand',
44
+ };
45
+
46
+ const exampleEngine = {
47
+ id: 'exampleEngine',
48
+ };
49
+ let isInitialized = false;
50
+
51
+ function createTestComponent(options = {}) {
52
+ const element = createElement('c-quantic-results-per-page', {
53
+ is: QuanticResultsPerPage,
54
+ });
55
+ Object.assign(element, options);
56
+ document.body.appendChild(element);
57
+ return element;
58
+ }
59
+
60
+ function prepareHeadlessState() {
61
+ // @ts-ignore
62
+ mockHeadlessLoader.getHeadlessBundle = () => {
63
+ return {
64
+ buildResultsPerPage: functionsMocks.buildResultsPerPage,
65
+ buildSearchStatus: functionsMocks.buildSearchStatus,
66
+ };
67
+ };
68
+ }
69
+
70
+ function mockStoreState() {
71
+ // @ts-ignore
72
+ mockHeadlessLoader.getFromStore = () => {
73
+ return storeState;
74
+ };
75
+ }
76
+
77
+ // Helper function to wait until the microtask queue is empty.
78
+ function flushPromises() {
79
+ // eslint-disable-next-line @lwc/lwc/no-async-operation
80
+ return new Promise((resolve) => setTimeout(resolve, 0));
81
+ }
82
+
83
+ function mockSuccessfulHeadlessInitialization() {
84
+ // @ts-ignore
85
+ mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => {
86
+ if (element instanceof QuanticResultsPerPage && !isInitialized) {
87
+ isInitialized = true;
88
+ initialize(exampleEngine);
89
+ }
90
+ };
91
+ }
92
+
93
+ function mockErroneousHeadlessInitialization() {
94
+ // @ts-ignore
95
+ mockHeadlessLoader.initializeWithHeadless = (element) => {
96
+ if (element instanceof QuanticResultsPerPage) {
97
+ element.setInitializationError();
98
+ }
99
+ };
100
+ }
101
+
102
+ function cleanup() {
103
+ // The jsdom instance is shared across test cases in a single file so reset the DOM
104
+ while (document.body.firstChild) {
105
+ document.body.removeChild(document.body.firstChild);
106
+ }
107
+ jest.clearAllMocks();
108
+ isInitialized = false;
109
+ }
110
+
111
+ describe('c-quantic-results-per-page', () => {
112
+ const defaultInitialChoice = 10;
113
+ const defaultChoices = [10, 25, 50, 100];
114
+
115
+ beforeEach(() => {
116
+ mockSuccessfulHeadlessInitialization();
117
+ prepareHeadlessState();
118
+ mockStoreState();
119
+ });
120
+
121
+ afterEach(() => {
122
+ resultsPerPageState = initialResultsPerPageState;
123
+ storeState = initialStoreState;
124
+ cleanup();
125
+ });
126
+
127
+ describe('when an initialization error occurs', () => {
128
+ beforeEach(() => {
129
+ mockErroneousHeadlessInitialization();
130
+ });
131
+
132
+ it('should display the initialization error component', async () => {
133
+ const element = createTestComponent();
134
+ await flushPromises();
135
+
136
+ const initializationError = element.shadowRoot.querySelector(
137
+ selectors.componentError
138
+ );
139
+ expect(initializationError).not.toBeNull();
140
+ });
141
+ });
142
+
143
+ describe('controller initialization', () => {
144
+ beforeEach(() => {
145
+ mockSuccessfulHeadlessInitialization();
146
+ prepareHeadlessState();
147
+ });
148
+
149
+ it('should build the results per page and search status controllers and subscribe to state', async () => {
150
+ createTestComponent();
151
+ await flushPromises();
152
+
153
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledTimes(1);
154
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledWith(
155
+ exampleEngine,
156
+ {
157
+ initialState: {
158
+ numberOfResults: 10,
159
+ },
160
+ }
161
+ );
162
+ expect(functionsMocks.buildSearchStatus).toHaveBeenCalledTimes(1);
163
+ expect(functionsMocks.buildSearchStatus).toHaveBeenCalledWith(
164
+ exampleEngine
165
+ );
166
+ });
167
+ });
168
+
169
+ describe('with default options', () => {
170
+ it('should properly render with the default choice selected', async () => {
171
+ const element = createTestComponent();
172
+ await flushPromises();
173
+
174
+ const resultsPerPage = element.shadowRoot.querySelector(
175
+ selectors.resultsPerPage
176
+ );
177
+ expect(resultsPerPage).not.toBeNull();
178
+
179
+ const resultsPerPageOptions = Array.from(
180
+ element.shadowRoot.querySelectorAll(selectors.resultsPerPageOption)
181
+ );
182
+ expect(resultsPerPageOptions).toHaveLength(defaultChoices.length);
183
+
184
+ resultsPerPageOptions.forEach((option, index) => {
185
+ expect(option.number).toEqual(defaultChoices[index]);
186
+ expect(option.selected).toBe(
187
+ defaultChoices[index] === defaultInitialChoice
188
+ );
189
+ });
190
+ });
191
+
192
+ it('should update the state when the results per page is clicked', async () => {
193
+ const element = createTestComponent();
194
+ await flushPromises();
195
+
196
+ const resultsPerPage = element.shadowRoot.querySelector(
197
+ selectors.resultsPerPage
198
+ );
199
+ expect(resultsPerPage).not.toBeNull();
200
+
201
+ const resultsPerPageOptions = Array.from(
202
+ element.shadowRoot.querySelectorAll(selectors.resultsPerPageOption)
203
+ );
204
+
205
+ resultsPerPageOptions[1].dispatchEvent(
206
+ new CustomEvent('quantic__select', {
207
+ detail: defaultChoices[1],
208
+ })
209
+ );
210
+
211
+ expect(functionsMocks.set).toHaveBeenCalledTimes(1);
212
+ expect(functionsMocks.set).toHaveBeenCalledWith(defaultChoices[1]);
213
+ });
214
+
215
+ describe('the numberOfResults headless state', () => {
216
+ const expectedValueSelected = 100;
217
+ beforeEach(() => {
218
+ resultsPerPageState = {
219
+ ...resultsPerPageState,
220
+ numberOfResults: expectedValueSelected,
221
+ };
222
+ });
223
+
224
+ test('should reflect the headless state and select the right option', async () => {
225
+ const element = createTestComponent();
226
+ await flushPromises();
227
+
228
+ const resultsPerPage = element.shadowRoot.querySelector(
229
+ selectors.resultsPerPage
230
+ );
231
+ expect(resultsPerPage).not.toBeNull();
232
+
233
+ const resultsPerPageOptions = Array.from(
234
+ element.shadowRoot.querySelectorAll(selectors.resultsPerPageOption)
235
+ );
236
+
237
+ resultsPerPageOptions.forEach((option) => {
238
+ expect(option.selected).toBe(expectedValueSelected === option.number);
239
+ });
240
+ });
241
+ });
242
+ });
243
+
244
+ describe('with a custom #choicesDisplayed option', () => {
245
+ beforeEach(() => {
246
+ console.error = jest.fn();
247
+ });
248
+
249
+ it('should properly render with the choices displayed', async () => {
250
+ const customChoices = [100, 250, 500];
251
+ const element = createTestComponent({
252
+ choicesDisplayed: customChoices.join(','),
253
+ });
254
+ await flushPromises();
255
+
256
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledTimes(1);
257
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledWith(
258
+ exampleEngine,
259
+ {
260
+ initialState: {
261
+ numberOfResults: customChoices[0],
262
+ },
263
+ }
264
+ );
265
+
266
+ const resultsPerPage = element.shadowRoot.querySelector(
267
+ selectors.resultsPerPage
268
+ );
269
+ expect(resultsPerPage).not.toBeNull();
270
+
271
+ const resultsPerPageOptions = Array.from(
272
+ element.shadowRoot.querySelectorAll(selectors.resultsPerPageOption)
273
+ );
274
+ expect(resultsPerPageOptions).toHaveLength(customChoices.length);
275
+
276
+ resultsPerPageOptions.forEach((option, index) => {
277
+ expect(option.number).toEqual(customChoices[index]);
278
+ });
279
+ });
280
+
281
+ it('should log an error if the choices displayed are not numbers', async () => {
282
+ const customChoices = ['foo', 'bar', 'baz'];
283
+ const element = createTestComponent({
284
+ choicesDisplayed: customChoices.join(','),
285
+ });
286
+ await flushPromises();
287
+
288
+ const initializationError = element.shadowRoot.querySelector(
289
+ selectors.componentError
290
+ );
291
+ expect(initializationError).not.toBeNull();
292
+
293
+ expect(console.error).toHaveBeenCalledTimes(customChoices.length);
294
+ customChoices.forEach((choice, index) => {
295
+ expect(console.error).toHaveBeenNthCalledWith(
296
+ index + 1,
297
+ `The choice value "${choice}" from the "choicesDisplayed" option is not a number.`
298
+ );
299
+ });
300
+ });
301
+ });
302
+
303
+ describe('with a custom #initialChoice option', () => {
304
+ const customInitialChoiceIndex = 2;
305
+ const customInitialChoice = defaultChoices[customInitialChoiceIndex];
306
+
307
+ beforeEach(() => {
308
+ console.error = jest.fn();
309
+ resultsPerPageState = {
310
+ ...resultsPerPageState,
311
+ numberOfResults: customInitialChoice,
312
+ };
313
+ });
314
+
315
+ it('should properly render with the initial choice selected', async () => {
316
+ const element = createTestComponent({
317
+ initialChoice: customInitialChoice,
318
+ });
319
+ await flushPromises();
320
+
321
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledTimes(1);
322
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledWith(
323
+ exampleEngine,
324
+ {
325
+ initialState: {
326
+ numberOfResults: customInitialChoice,
327
+ },
328
+ }
329
+ );
330
+
331
+ const resultsPerPageOptions = Array.from(
332
+ element.shadowRoot.querySelectorAll(selectors.resultsPerPageOption)
333
+ );
334
+ expect(resultsPerPageOptions).toHaveLength(defaultChoices.length);
335
+
336
+ resultsPerPageOptions.forEach((option, index) => {
337
+ expect(option.selected).toBe(index === customInitialChoiceIndex);
338
+ });
339
+ });
340
+ it('should log an error if the initial choice is not included in the choices displayed but not display it to users', async () => {
341
+ const customInvalidInitialChoice = 123;
342
+ const element = createTestComponent({
343
+ initialChoice: customInvalidInitialChoice,
344
+ });
345
+ await flushPromises();
346
+
347
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledTimes(1);
348
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledWith(
349
+ exampleEngine,
350
+ {
351
+ initialState: {
352
+ numberOfResults: defaultChoices[0],
353
+ },
354
+ }
355
+ );
356
+
357
+ const initializationError = element.shadowRoot.querySelector(
358
+ selectors.componentError
359
+ );
360
+ expect(initializationError).toBeNull();
361
+
362
+ expect(console.error).toHaveBeenCalledTimes(1);
363
+ expect(console.error).toHaveBeenCalledWith(
364
+ `The "initialChoice" option value "${customInvalidInitialChoice}" is not included in the "choicesDisplayed" option "${defaultChoices}". Defaulting to the first value of the choices.`
365
+ );
366
+ });
367
+ });
368
+
369
+ describe('when you omit the #initialChoice option', () => {
370
+ const mockNumberOfResults = 100;
371
+
372
+ beforeEach(() => {
373
+ resultsPerPageState = {
374
+ ...resultsPerPageState,
375
+ numberOfResults: mockNumberOfResults,
376
+ };
377
+ });
378
+ it('should default to the first choice', async () => {
379
+ const customChoices = [100, 250, 500];
380
+ const element = createTestComponent({
381
+ choicesDisplayed: customChoices.join(','),
382
+ });
383
+ await flushPromises();
384
+
385
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledTimes(1);
386
+ expect(functionsMocks.buildResultsPerPage).toHaveBeenCalledWith(
387
+ exampleEngine,
388
+ {
389
+ initialState: {
390
+ numberOfResults: customChoices[0],
391
+ },
392
+ }
393
+ );
394
+
395
+ const resultsPerPageOptions = Array.from(
396
+ element.shadowRoot.querySelectorAll(selectors.resultsPerPageOption)
397
+ );
398
+ expect(resultsPerPageOptions).toHaveLength(customChoices.length);
399
+ resultsPerPageOptions.forEach((option, index) => {
400
+ expect(option.selected).toBe(index === 0);
401
+ });
402
+ });
403
+ });
404
+ });
@@ -0,0 +1,74 @@
1
+ import {ResultsPerPageObject} from './pageObject';
2
+ import {quanticBase} from '../../../../../../playwright/fixtures/baseFixture';
3
+ import {SearchObject} from '../../../../../../playwright/page-object/searchObject';
4
+ import {
5
+ searchRequestRegex,
6
+ insightSearchRequestRegex,
7
+ } from '../../../../../../playwright/utils/requests';
8
+ import {InsightSetupObject} from '../../../../../../playwright/page-object/insightSetupObject';
9
+ import {useCaseEnum} from '../../../../../../playwright/utils/useCase';
10
+
11
+ const resultsPerPageUrl = 's/quantic-results-per-page';
12
+
13
+ interface ResultsPerPageOptions {
14
+ initialChoice: number;
15
+ choicesDisplayed: string;
16
+ }
17
+
18
+ type QuanticResultsPerPageE2EFixtures = {
19
+ resultsPerPage: ResultsPerPageObject;
20
+ search: SearchObject;
21
+ options: Partial<ResultsPerPageOptions>;
22
+ };
23
+
24
+ type QuanticResultsPerPageE2ESearchFixtures =
25
+ QuanticResultsPerPageE2EFixtures & {
26
+ urlHash: string;
27
+ };
28
+
29
+ type QuanticResultsPerPageE2EInsightFixtures =
30
+ QuanticResultsPerPageE2ESearchFixtures & {
31
+ insightSetup: InsightSetupObject;
32
+ };
33
+
34
+ export const testSearch =
35
+ quanticBase.extend<QuanticResultsPerPageE2ESearchFixtures>({
36
+ options: {},
37
+ urlHash: '',
38
+ search: async ({page}, use) => {
39
+ await use(new SearchObject(page, searchRequestRegex));
40
+ },
41
+ resultsPerPage: async (
42
+ {page, options, configuration, search, urlHash},
43
+ use
44
+ ) => {
45
+ await page.goto(
46
+ urlHash ? `${resultsPerPageUrl}#${urlHash}` : resultsPerPageUrl
47
+ );
48
+ configuration.configure(options);
49
+ await search.waitForSearchResponse();
50
+ await use(new ResultsPerPageObject(page));
51
+ },
52
+ });
53
+
54
+ export const testInsight =
55
+ quanticBase.extend<QuanticResultsPerPageE2EInsightFixtures>({
56
+ options: {},
57
+ search: async ({page}, use) => {
58
+ await use(new SearchObject(page, insightSearchRequestRegex));
59
+ },
60
+ insightSetup: async ({page}, use) => {
61
+ await use(new InsightSetupObject(page));
62
+ },
63
+ resultsPerPage: async (
64
+ {page, options, search, configuration, insightSetup},
65
+ use
66
+ ) => {
67
+ await page.goto(resultsPerPageUrl);
68
+ configuration.configure({...options, useCase: useCaseEnum.insight});
69
+ await insightSetup.waitForInsightInterfaceInitialization();
70
+ await search.performSearch();
71
+ await search.waitForSearchResponse();
72
+ await use(new ResultsPerPageObject(page));
73
+ },
74
+ });
@@ -0,0 +1,85 @@
1
+ import type {Locator, Page, Request} from '@playwright/test';
2
+ import {isUaCustomEvent} from '../../../../../../playwright/utils/requests';
3
+
4
+ const resultsPerPageElementsSelectors = {
5
+ component: 'c-quantic-results-per-page',
6
+ componentError: 'c-quantic-component-error',
7
+ resultsPerPageTestId: 'results-per-page',
8
+ resultsPerPageOptionButton: 'c-quantic-number-button',
9
+ selectedResultsPerPageOptionButton: 'button.slds-button_brand',
10
+ };
11
+
12
+ export class ResultsPerPageObject {
13
+ constructor(public page: Page) {
14
+ this.page = page;
15
+ }
16
+
17
+ get component(): Locator {
18
+ return this.page.getByTestId(
19
+ resultsPerPageElementsSelectors.resultsPerPageTestId
20
+ );
21
+ }
22
+
23
+ get allResultsPerPageOptionsButtons(): Locator {
24
+ return this.component.locator(
25
+ resultsPerPageElementsSelectors.resultsPerPageOptionButton
26
+ );
27
+ }
28
+
29
+ get selectedResultsPerPageOption(): Locator {
30
+ return this.allResultsPerPageOptionsButtons.filter({
31
+ has: this.page.locator(
32
+ resultsPerPageElementsSelectors.selectedResultsPerPageOptionButton
33
+ ),
34
+ });
35
+ }
36
+
37
+ getResultPerPageOptionByValue(value: number): Locator {
38
+ return this.allResultsPerPageOptionsButtons.getByText(value.toString());
39
+ }
40
+
41
+ async clickResultsPerPageOptionByValue(value: number): Promise<void> {
42
+ await this.getResultPerPageOptionByValue(value).click();
43
+ }
44
+
45
+ async waitForResultsPerPageClickUA(
46
+ customChecker?: Function
47
+ ): Promise<Request> {
48
+ const uaRequest = this.page.waitForRequest((request) => {
49
+ if (isUaCustomEvent(request)) {
50
+ const requestBody = request.postDataJSON?.();
51
+ const {customData} = requestBody;
52
+
53
+ const expectedFields = {
54
+ eventType: 'getMoreResults',
55
+ eventValue: 'pagerResize',
56
+ };
57
+ const matchesExpectedFields = Object.keys(expectedFields).every(
58
+ (key) => requestBody?.[key] === expectedFields[key]
59
+ );
60
+
61
+ return (
62
+ matchesExpectedFields &&
63
+ (customChecker ? customChecker(customData) : true)
64
+ );
65
+ }
66
+ return false;
67
+ });
68
+ return uaRequest;
69
+ }
70
+
71
+ async waitForResultsPerPageUA(
72
+ expectedCustomFields: Record<string, any>
73
+ ): Promise<Request> {
74
+ return this.waitForResultsPerPageClickUA(
75
+ (customData: Record<string, any>) => {
76
+ return Object.keys(expectedCustomFields).every((key) =>
77
+ typeof expectedCustomFields[key] === 'object'
78
+ ? JSON.stringify(customData?.[key]) ===
79
+ JSON.stringify(expectedCustomFields[key])
80
+ : customData?.[key] === expectedCustomFields[key]
81
+ );
82
+ }
83
+ );
84
+ }
85
+ }
@@ -0,0 +1,97 @@
1
+ import {testSearch, testInsight} from './fixture';
2
+ import {
3
+ useCaseEnum,
4
+ useCaseTestCases,
5
+ } from '../../../../../../playwright/utils/useCase';
6
+
7
+ const fixtures = {
8
+ search: testSearch,
9
+ insight: testInsight,
10
+ };
11
+
12
+ const defaultChoices = [10, 25, 50, 100];
13
+ const defaultInitialChoice = 10;
14
+
15
+ useCaseTestCases.forEach((useCase) => {
16
+ let test = fixtures[useCase.value];
17
+
18
+ test.describe(`quantic results per page ${useCase.label}`, () => {
19
+ test.describe('with default options', () => {
20
+ test('should load as expected', async ({resultsPerPage}) => {
21
+ await test.expect(resultsPerPage.component).toBeVisible();
22
+ test
23
+ .expect(await resultsPerPage.allResultsPerPageOptionsButtons.count())
24
+ .toBe(defaultChoices.length);
25
+ test
26
+ .expect(resultsPerPage.selectedResultsPerPageOption)
27
+ .toHaveText(defaultInitialChoice.toString());
28
+ });
29
+
30
+ test.describe('when selecting a new results per page option', () => {
31
+ test('should trigger a new search and log analytics', async ({
32
+ resultsPerPage,
33
+ search,
34
+ }) => {
35
+ const newChoice = 25;
36
+
37
+ const searchResponsePromise = search.waitForSearchResponse();
38
+ const resultsPerPageAnalyticsPromise =
39
+ resultsPerPage.waitForResultsPerPageUA({
40
+ currentResultsPerPage: newChoice,
41
+ });
42
+
43
+ await resultsPerPage.clickResultsPerPageOptionByValue(newChoice);
44
+
45
+ const searchResponse = await searchResponsePromise;
46
+ await resultsPerPageAnalyticsPromise;
47
+
48
+ test
49
+ .expect(resultsPerPage.selectedResultsPerPageOption)
50
+ .toHaveText(newChoice.toString());
51
+ test
52
+ .expect(searchResponse.request().postDataJSON()?.numberOfResults)
53
+ .toBe(newChoice);
54
+ });
55
+ });
56
+ });
57
+
58
+ test.describe('with custom options', () => {
59
+ const customChoices = [20, 40, 80];
60
+ test.use({
61
+ options: {
62
+ choicesDisplayed: customChoices.join(','),
63
+ },
64
+ });
65
+
66
+ test('should load as expected', async ({resultsPerPage}) => {
67
+ await test.expect(resultsPerPage.component).toBeVisible();
68
+ test
69
+ .expect(await resultsPerPage.allResultsPerPageOptionsButtons.count())
70
+ .toBe(customChoices.length);
71
+ });
72
+ });
73
+
74
+ if (useCase.value === useCaseEnum.search) {
75
+ test.describe('when loading from URL hash', () => {
76
+ const expectedResultsPerPage = 50;
77
+ test.use({
78
+ urlHash: `numberOfResults=${expectedResultsPerPage}`,
79
+ });
80
+
81
+ test('should load the right number of results per page', async ({
82
+ resultsPerPage,
83
+ }) => {
84
+ await test.expect(resultsPerPage.component).toBeVisible();
85
+ test
86
+ .expect(
87
+ await resultsPerPage.allResultsPerPageOptionsButtons.count()
88
+ )
89
+ .toBe(defaultChoices.length);
90
+ test
91
+ .expect(resultsPerPage.selectedResultsPerPageOption)
92
+ .toHaveText(expectedResultsPerPage.toString());
93
+ });
94
+ });
95
+ }
96
+ });
97
+ });
@@ -5,7 +5,7 @@
5
5
  </template>
6
6
  <template lwc:else>
7
7
  <template if:true={hasResults}>
8
- <div class="slds-float_right">
8
+ <div class="slds-float_right" data-testid="results-per-page">
9
9
  <template for:each={choicesObjects} for:item="choice">
10
10
  <c-quantic-number-button
11
11
  key={choice.value}