@coveo/quantic 3.38.0 → 3.38.1

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.
@@ -1,4 +1,4 @@
1
- import type {Locator, Page, Request} from '@playwright/test';
1
+ import {expect, type Locator, type Page, type Request} from '@playwright/test';
2
2
  import {isUaSearchEvent} from '../../../../../../playwright/utils/requests';
3
3
 
4
4
  export class SortObject {
@@ -32,7 +32,20 @@ export class SortObject {
32
32
  } else {
33
33
  await this.sortDropDown.press('Space');
34
34
  }
35
- await this.sortButton('Oldest').waitFor({state: 'visible'});
35
+ const overlay = this.page.locator('div[part="dropdown overlay"]');
36
+ await overlay.waitFor({state: 'visible'});
37
+ await overlay
38
+ .locator('[role="option"]')
39
+ .first()
40
+ .waitFor({state: 'visible'});
41
+ }
42
+
43
+ async selectNextSortOptionUsingKeyboard(
44
+ expectedLabel: string
45
+ ): Promise<void> {
46
+ await this.sortDropDown.press('ArrowDown');
47
+ await this.sortDropDown.press('Enter');
48
+ await expect(this.sortDropDown).toHaveText(expectedLabel);
36
49
  }
37
50
 
38
51
  async waitForSortUaAnalytics(eventValue: any): Promise<Request> {
@@ -60,24 +73,22 @@ export class SortObject {
60
73
  return uaRequest;
61
74
  }
62
75
 
63
- async allSortLabelOptions() {
64
- const options = await this.page
65
- .locator('div[part="dropdown overlay"]')
66
- .allInnerTexts();
67
- const arrSort = options[0].split('\n');
68
- return arrSort;
69
- }
76
+ async getSortLabelValue(): Promise<{label: string; value: string | null}[]> {
77
+ const sortOptions = this.page.locator(
78
+ 'div[part="dropdown overlay"] [role="option"]'
79
+ );
80
+ await sortOptions.first().waitFor({state: 'visible'});
70
81
 
71
- async getSortLabelValue() {
72
- const arrSort = await this.allSortLabelOptions();
73
- const sortLabelwithValueList = await Promise.all(
74
- arrSort.map(async (item) => ({
75
- label: item,
76
- value: await this.page
77
- .getByRole('option', {name: item})
78
- .getAttribute('data-value'),
82
+ return sortOptions.evaluateAll((options) =>
83
+ options.map((option) => ({
84
+ label: (
85
+ (option as HTMLElement).innerText ||
86
+ option.getAttribute('aria-label') ||
87
+ option.getAttribute('title') ||
88
+ ''
89
+ ).trim(),
90
+ value: option.getAttribute('data-value'),
79
91
  }))
80
92
  );
81
- return sortLabelwithValueList;
82
93
  }
83
94
  }
@@ -11,8 +11,8 @@ const fixtures = {
11
11
 
12
12
  useCaseTestCases.forEach((useCase) => {
13
13
  let test;
14
- let sortArrOptions;
15
- let sortLabelWithValue;
14
+ let sortArrOptions: string[];
15
+ let sortLabelWithValue: {label: string; value: string | null}[];
16
16
  if (useCase.value === useCaseEnum.search) {
17
17
  test = fixtures[useCase.value] as typeof testSearch;
18
18
  } else {
@@ -22,8 +22,8 @@ useCaseTestCases.forEach((useCase) => {
22
22
  test.describe(`quantic sort ${useCase.label}`, () => {
23
23
  test.beforeEach(async ({sort}) => {
24
24
  await sort.clickSortDropDown();
25
- sortArrOptions = await sort.allSortLabelOptions();
26
25
  sortLabelWithValue = await sort.getSortLabelValue();
26
+ sortArrOptions = sortLabelWithValue.map(({label}) => label);
27
27
  await sort.clickSortDropDown();
28
28
  });
29
29
 
@@ -53,15 +53,13 @@ useCaseTestCases.forEach((useCase) => {
53
53
  // Selecting the next sort using Enter to open dropdown, the ArrowDown, then ENTER key
54
54
  await sort.focusSortDropDown();
55
55
  await sort.openSortDropdownUsingKeyboardEnter();
56
- await sort.sortDropDown.press('ArrowDown');
57
- await sort.sortDropDown.press('Enter');
56
+ await sort.selectNextSortOptionUsingKeyboard(sortArrOptions[1]);
58
57
  await expect(sort.sortDropDown).toHaveText(sortArrOptions[1]);
59
58
 
60
59
  // Selecting the next sort using Space to open dropdown, the ArrowDown, then ENTER key
61
60
  await sort.focusSortDropDown();
62
61
  await sort.openSortDropdownUsingKeyboardEnter(false);
63
- await sort.sortDropDown.press('ArrowDown');
64
- await sort.sortDropDown.press('Enter');
62
+ await sort.selectNextSortOptionUsingKeyboard(sortArrOptions[2]);
65
63
  await expect(sort.sortDropDown).toHaveText(sortArrOptions[2]);
66
64
  });
67
65
  });
@@ -76,7 +74,7 @@ useCaseTestCases.forEach((useCase) => {
76
74
  sortLabelWithValue[2]; // Assuming 0 is the first sort option
77
75
 
78
76
  const currentUrl = await page.url();
79
- const urlHash = `#sortCriteria=${encodeURI(expectedSortValue)}`;
77
+ const urlHash = `#sortCriteria=${encodeURI(expectedSortValue!)}`;
80
78
 
81
79
  await page.goto(`${currentUrl}/${urlHash}`);
82
80
  await page.getByRole('button', {name: 'Try it now'}).click();