@vuu-ui/vuu-playwright-helpers 4.0.0-beta.7 → 4.0.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.
- package/README.md +50 -2
- package/package.json +2 -2
- package/src/PwChart.js +77 -0
- package/src/PwChartDataPoint.js +61 -0
- package/src/PwColumnPicker.js +44 -0
- package/src/PwContextMenu.js +14 -0
- package/src/PwTable.js +82 -7
- package/src/PwTableFooter.js +16 -0
- package/src/PwTableHeaderCell.js +8 -0
- package/src/index.js +4 -0
- package/types/PwChart.d.ts +124 -0
- package/types/PwChartDataPoint.d.ts +116 -0
- package/types/PwColumnPicker.d.ts +116 -0
- package/types/PwComponent.d.ts +45 -0
- package/types/PwContextMenu.d.ts +116 -8
- package/types/PwMenuItem.d.ts +150 -2
- package/types/PwTable.d.ts +358 -7
- package/types/PwTableFooter.d.ts +40 -0
- package/types/PwTableHeaderCell.d.ts +43 -0
- package/types/index.d.ts +5 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Locator, Page } from "@playwright/test";
|
|
2
|
+
import { PlaywrightPageObject } from "./PlaywrightPageObject";
|
|
3
|
+
import { PwContextMenu } from "./PwContextMenu";
|
|
4
|
+
/**
|
|
5
|
+
* Position and value of a chart data point, as resolved by PwChart.
|
|
6
|
+
*/
|
|
7
|
+
export interface ChartDataPointInfo {
|
|
8
|
+
seriesName: string;
|
|
9
|
+
/**
|
|
10
|
+
* 0 based index into the series data (and the category axis).
|
|
11
|
+
*/
|
|
12
|
+
dataIndex: number;
|
|
13
|
+
/**
|
|
14
|
+
* The category (x axis) value at dataIndex.
|
|
15
|
+
*/
|
|
16
|
+
category: string;
|
|
17
|
+
value: number;
|
|
18
|
+
/**
|
|
19
|
+
* True when the data point is rendered as an excluded data item.
|
|
20
|
+
*/
|
|
21
|
+
isExcluded: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Pixel position of the data point, relative to the chart canvas.
|
|
24
|
+
*/
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A single data point within a PwChart. Obtained from PwChart.dataPoint.
|
|
30
|
+
*
|
|
31
|
+
* The properties (value, x, y etc) are a snapshot, taken when the data point is
|
|
32
|
+
* obtained. Interactions (click, hover, right click) are performed with the
|
|
33
|
+
* mouse at the data point's current position, which is resolved again before
|
|
34
|
+
* each action, waiting until the position is stable (e.g. while the chart is
|
|
35
|
+
* resizing). This mirrors Playwright Locator actionability checks.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* test("select a data point", async ({ page }) => {
|
|
39
|
+
* const chart = new PwChart(page);
|
|
40
|
+
* const point = await chart.dataPoint("price", 3);
|
|
41
|
+
* expect(point.value).toEqual(103);
|
|
42
|
+
* await point.click();
|
|
43
|
+
* await expect(point.symbol).toHaveAttribute("fill", "purple");
|
|
44
|
+
* });
|
|
45
|
+
*/
|
|
46
|
+
export declare class PwChartDataPoint extends PlaywrightPageObject implements ChartDataPointInfo {
|
|
47
|
+
private readonly canvas;
|
|
48
|
+
private readonly resolve;
|
|
49
|
+
readonly seriesName: string;
|
|
50
|
+
readonly dataIndex: number;
|
|
51
|
+
readonly category: string;
|
|
52
|
+
readonly value: number;
|
|
53
|
+
readonly isExcluded: boolean;
|
|
54
|
+
readonly x: number;
|
|
55
|
+
readonly y: number;
|
|
56
|
+
/**
|
|
57
|
+
* @param page the Playwright page
|
|
58
|
+
* @param canvas Locator for the element that renders the chart (and receives mouse events)
|
|
59
|
+
* @param info position and value of the data point
|
|
60
|
+
* @param resolve resolves the current position and value of the data point
|
|
61
|
+
*/
|
|
62
|
+
constructor(page: Page, canvas: Locator, info: ChartDataPointInfo, resolve: () => Promise<ChartDataPointInfo>);
|
|
63
|
+
/**
|
|
64
|
+
* Locator for the symbol rendered at this data point (an SVG path, requires
|
|
65
|
+
* the svg renderer). Matched by position only, so its size and color can be
|
|
66
|
+
* asserted as they change, e.g. on hover or selection. Uses the position
|
|
67
|
+
* when the data point was obtained.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* test("hover enlarges symbol", async ({ page }) => {
|
|
71
|
+
* const point = await new PwChart(page).dataPoint("price", 3);
|
|
72
|
+
* await expect(point.symbol).toBeAttached();
|
|
73
|
+
* await point.hover();
|
|
74
|
+
* await expect(point.symbol).toHaveAttribute("transform", /^matrix\(8,/);
|
|
75
|
+
* });
|
|
76
|
+
*/
|
|
77
|
+
get symbol(): Locator;
|
|
78
|
+
/**
|
|
79
|
+
* Click the data point. With a chart selectionModel, this toggles selection.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* test("click selects data point", async ({ page }) => {
|
|
83
|
+
* const point = await new PwChart(page).dataPoint("price", 3);
|
|
84
|
+
* await point.click();
|
|
85
|
+
* await expect(point.symbol).toHaveAttribute("fill", "purple");
|
|
86
|
+
* });
|
|
87
|
+
*/
|
|
88
|
+
click(options?: Omit<Parameters<Locator["click"]>[0], "position">): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Move the mouse over the data point.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* test("hover highlights data point", async ({ page }) => {
|
|
94
|
+
* const point = await new PwChart(page).dataPoint("price", 3);
|
|
95
|
+
* await point.hover();
|
|
96
|
+
* await expect(point.symbol).toHaveAttribute("transform", /^matrix\(8,/);
|
|
97
|
+
* });
|
|
98
|
+
*/
|
|
99
|
+
hover(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Right click the data point to invoke the context menu. Resolves once the
|
|
102
|
+
* menu is visible and has focus.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* test("exclude data point", async ({ page }) => {
|
|
106
|
+
* const point = await new PwChart(page).dataPoint("price", 3);
|
|
107
|
+
* const menu = await point.showContextMenu();
|
|
108
|
+
* await menu.menuItem("Exclude Item").click();
|
|
109
|
+
* });
|
|
110
|
+
*/
|
|
111
|
+
showContextMenu(): Promise<PwContextMenu>;
|
|
112
|
+
/**
|
|
113
|
+
* The current position of the data point, once it has stopped moving.
|
|
114
|
+
*/
|
|
115
|
+
private stablePosition;
|
|
116
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type Locator } from "@playwright/test";
|
|
2
|
+
import { PwComponent } from "./PwComponent";
|
|
3
|
+
/**
|
|
4
|
+
* A ColumnPicker. The upper list holds the columns in view (selected), the
|
|
5
|
+
* lower list the columns available to add. Columns are identified by name
|
|
6
|
+
* (the data-name of the list option), not by display label.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* test("add a column", async ({ page }) => {
|
|
10
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
11
|
+
* await picker.addColumn("lotSize");
|
|
12
|
+
* await picker.assertSelectedColumns(["bbg", "currency", "lotSize"]);
|
|
13
|
+
* });
|
|
14
|
+
*/
|
|
15
|
+
export declare class PwColumnPicker extends PwComponent {
|
|
16
|
+
protected readonly defaultCssSelector = ".vuuColumnPicker";
|
|
17
|
+
/**
|
|
18
|
+
* Locator for the options in the list of selected columns (columns in view).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* test("four columns in view", async ({ page }) => {
|
|
22
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
23
|
+
* await expect(picker.selectedOptions).toHaveCount(4);
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
get selectedOptions(): Locator;
|
|
27
|
+
/**
|
|
28
|
+
* Locator for the options in the list of available columns.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* test("three columns available", async ({ page }) => {
|
|
32
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
33
|
+
* await expect(picker.availableOptions).toHaveCount(3);
|
|
34
|
+
* });
|
|
35
|
+
*/
|
|
36
|
+
get availableOptions(): Locator;
|
|
37
|
+
/**
|
|
38
|
+
* The names of the selected columns (columns in view), in list order.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* test("columns in view", async ({ page }) => {
|
|
42
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
43
|
+
* expect(await picker.selectedColumns()).toEqual(["bbg", "currency"]);
|
|
44
|
+
* });
|
|
45
|
+
*/
|
|
46
|
+
selectedColumns(): Promise<string[]>;
|
|
47
|
+
/**
|
|
48
|
+
* The names of the available columns, in list order.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* test("columns available", async ({ page }) => {
|
|
52
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
53
|
+
* expect(await picker.availableColumns()).toContain("lotSize");
|
|
54
|
+
* });
|
|
55
|
+
*/
|
|
56
|
+
availableColumns(): Promise<string[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Add a column to the view. Hovers the column in the available list, then
|
|
59
|
+
* clicks its add button.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* test("add lotSize", async ({ page }) => {
|
|
63
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
64
|
+
* await picker.addColumn("lotSize");
|
|
65
|
+
* });
|
|
66
|
+
*/
|
|
67
|
+
addColumn(columnName: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Remove a column from the view. Hovers the column in the selected list,
|
|
70
|
+
* then clicks its remove button.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* test("remove currency", async ({ page }) => {
|
|
74
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
75
|
+
* await picker.removeColumn("currency");
|
|
76
|
+
* });
|
|
77
|
+
*/
|
|
78
|
+
removeColumn(columnName: string): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Enter text in the search input, filtering both lists.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* test("search for lot", async ({ page }) => {
|
|
84
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
85
|
+
* await picker.search("lot");
|
|
86
|
+
* expect(await picker.availableColumns()).toEqual(["lotSize"]);
|
|
87
|
+
* });
|
|
88
|
+
*/
|
|
89
|
+
search(text: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Assert the names of the selected columns, in order, retrying until the
|
|
92
|
+
* expect timeout.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* test("columns in view", async ({ page }) => {
|
|
96
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
97
|
+
* await picker.assertSelectedColumns(["bbg", "currency"]);
|
|
98
|
+
* });
|
|
99
|
+
*/
|
|
100
|
+
assertSelectedColumns(columnNames: string[]): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Assert that the named columns are in the available list, retrying until
|
|
103
|
+
* the expect timeout. Other columns may also be available.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* test("currency is available again", async ({ page }) => {
|
|
107
|
+
* const picker = await new PwTableFooter(page).showColumnPicker();
|
|
108
|
+
* await picker.removeColumn("currency");
|
|
109
|
+
* await picker.assertAvailableColumns(["currency"]);
|
|
110
|
+
* });
|
|
111
|
+
*/
|
|
112
|
+
assertAvailableColumns(columnNames: string[]): Promise<void>;
|
|
113
|
+
private clickAction;
|
|
114
|
+
private option;
|
|
115
|
+
private optionNames;
|
|
116
|
+
}
|
package/types/PwComponent.d.ts
CHANGED
|
@@ -9,6 +9,18 @@ export type PwComponentTarget = string | Locator;
|
|
|
9
9
|
* Base class for helpers that wrap a single component instance. Subclasses
|
|
10
10
|
* provide a defaultCssSelector, which can be overridden at runtime by passing
|
|
11
11
|
* a css selector or Locator to the constructor.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // a hypothetical helper for a toolbar component
|
|
15
|
+
* export class PwToolbar extends PwComponent {
|
|
16
|
+
* protected readonly defaultCssSelector = ".vuuToolbar";
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* test("toolbar renders", async ({ page }) => {
|
|
20
|
+
* await new PwToolbar(page).assertVisible();
|
|
21
|
+
* await new PwToolbar(page, "#main-toolbar").assertVisible();
|
|
22
|
+
* await new PwToolbar(page, page.getByTestId("toolbar")).assertVisible();
|
|
23
|
+
* });
|
|
12
24
|
*/
|
|
13
25
|
export declare abstract class PwComponent extends PlaywrightPageObject {
|
|
14
26
|
protected readonly target?: PwComponentTarget | undefined;
|
|
@@ -21,6 +33,12 @@ export declare abstract class PwComponent extends PlaywrightPageObject {
|
|
|
21
33
|
/**
|
|
22
34
|
* Locator for the component root element. Use this for web-first assertions
|
|
23
35
|
* that are not covered by a helper method.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* test("menu is vertical", async ({ page }) => {
|
|
39
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
40
|
+
* await expect(menu.locator).toHaveAttribute("aria-orientation", "vertical");
|
|
41
|
+
* });
|
|
24
42
|
*/
|
|
25
43
|
get locator(): Locator;
|
|
26
44
|
/**
|
|
@@ -36,8 +54,35 @@ export declare abstract class PwComponent extends PlaywrightPageObject {
|
|
|
36
54
|
/**
|
|
37
55
|
* Is the component currently visible. Does not wait or retry, prefer
|
|
38
56
|
* assertVisible within tests unless the component is known to be stable.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* test("menu is open", async ({ page }) => {
|
|
60
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
61
|
+
* expect(await menu.isVisible()).toBe(true);
|
|
62
|
+
* });
|
|
39
63
|
*/
|
|
40
64
|
isVisible(): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Assert the component is visible, retrying until the expect timeout.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* test("table renders", async ({ mount, page }) => {
|
|
70
|
+
* await mount("Table/ContextMenu/LocalContextMenu");
|
|
71
|
+
* await new PwTable(page).assertVisible();
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
41
74
|
assertVisible(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Assert the component is not in the DOM, retrying until the expect timeout.
|
|
77
|
+
* Passes as soon as the element is absent, so it does not prove an element
|
|
78
|
+
* will not appear later (see PwTable.assertNoContextMenu).
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* test("menu closes after click", async ({ page }) => {
|
|
82
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
83
|
+
* await menu.menuItem("Copy text").click();
|
|
84
|
+
* await menu.assertNotAttached();
|
|
85
|
+
* });
|
|
86
|
+
*/
|
|
42
87
|
assertNotAttached(): Promise<void>;
|
|
43
88
|
}
|
package/types/PwContextMenu.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Locator } from "@playwright/test";
|
|
1
|
+
import { type Locator, type Page } from "@playwright/test";
|
|
2
2
|
import { PwComponent } from "./PwComponent";
|
|
3
3
|
import { PwMenuItem } from "./PwMenuItem";
|
|
4
4
|
/**
|
|
@@ -9,7 +9,9 @@ import { PwMenuItem } from "./PwMenuItem";
|
|
|
9
9
|
* test("cell menu", async ({ page }) => {
|
|
10
10
|
* const table = new PwTable(page);
|
|
11
11
|
* const menu = await table.showContextMenu("ric", 2);
|
|
12
|
-
* expect(
|
|
12
|
+
* expect(
|
|
13
|
+
* await menu.hasMenuItems(["Copy text", "Filter", "Sort", "Delete row"]),
|
|
14
|
+
* ).toBe(true);
|
|
13
15
|
* const filterMenu = await menu.menuItem("Filter").openSubMenu();
|
|
14
16
|
* await filterMenu.menuItem("Include value").click();
|
|
15
17
|
* await menu.assertNotAttached();
|
|
@@ -17,33 +19,129 @@ import { PwMenuItem } from "./PwMenuItem";
|
|
|
17
19
|
*/
|
|
18
20
|
export declare class PwContextMenu extends PwComponent {
|
|
19
21
|
protected readonly defaultCssSelector = ".vuuContextMenuPanel[role=\"menu\"]";
|
|
22
|
+
/**
|
|
23
|
+
* Perform the action that opens a context menu (e.g. a right click), then
|
|
24
|
+
* resolve with the menu once it is visible and has focus. Component helpers
|
|
25
|
+
* use this to implement showContextMenu.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* test("context menu from custom element", async ({ page }) => {
|
|
29
|
+
* const menu = await PwContextMenu.open(page, () =>
|
|
30
|
+
* page.getByTestId("panel").click({ button: "right" }),
|
|
31
|
+
* );
|
|
32
|
+
* expect(await menu.hasMenuItems()).toBe(true);
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
static open(page: Page, openAction: () => Promise<unknown>): Promise<PwContextMenu>;
|
|
36
|
+
/**
|
|
37
|
+
* Perform the action that would open a context menu (e.g. a right click),
|
|
38
|
+
* then assert that no context menu is shown.
|
|
39
|
+
*
|
|
40
|
+
* A negative assertion passes as soon as the menu is absent, which may be
|
|
41
|
+
* before a menu would have rendered. To avoid false passes we wait for two
|
|
42
|
+
* animation frames after the action, allowing React to commit and the menu
|
|
43
|
+
* to be positioned, before asserting.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* test("no context menu on panel", async ({ page }) => {
|
|
47
|
+
* await PwContextMenu.assertNotOpened(page, () =>
|
|
48
|
+
* page.getByTestId("panel").click({ button: "right" }),
|
|
49
|
+
* );
|
|
50
|
+
* });
|
|
51
|
+
*/
|
|
52
|
+
static assertNotOpened(page: Page, openAction: () => Promise<unknown>): Promise<void>;
|
|
20
53
|
/**
|
|
21
54
|
* Locator for the menu items of this menu. Sub menus are rendered in their
|
|
22
55
|
* own (portalled) panels, so their items are not included.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* test("menu has four items", async ({ page }) => {
|
|
59
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
60
|
+
* await expect(menu.menuItems).toHaveCount(4);
|
|
61
|
+
* });
|
|
23
62
|
*/
|
|
24
63
|
get menuItems(): Locator;
|
|
25
64
|
/**
|
|
26
65
|
* The labels of the menu items, in rendered order.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* test("menu items are in expected order", async ({ page }) => {
|
|
69
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
70
|
+
* expect(await menu.menuItemLabels()).toEqual([
|
|
71
|
+
* "Copy text",
|
|
72
|
+
* "Filter",
|
|
73
|
+
* "Sort",
|
|
74
|
+
* "Delete row",
|
|
75
|
+
* ]);
|
|
76
|
+
* });
|
|
27
77
|
*/
|
|
28
78
|
menuItemLabels(): Promise<string[]>;
|
|
29
79
|
/**
|
|
30
80
|
* With no argument, does the menu have any menu items. With labels, does
|
|
31
|
-
* the menu have exactly these menu items, in this order.
|
|
81
|
+
* the menu have exactly these menu items, in this order. Labels are compared
|
|
82
|
+
* exactly, a partial list returns false.
|
|
83
|
+
*
|
|
84
|
+
* Does not wait or retry. The menu items are rendered with the menu, so this
|
|
85
|
+
* is safe to call once the menu is ready (e.g. after showContextMenu).
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* test("cell menu has expected items", async ({ page }) => {
|
|
89
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
90
|
+
* expect(await menu.hasMenuItems()).toBe(true);
|
|
91
|
+
* expect(
|
|
92
|
+
* await menu.hasMenuItems(["Copy text", "Filter", "Sort", "Delete row"]),
|
|
93
|
+
* ).toBe(true);
|
|
94
|
+
* // exact match, a partial list is false
|
|
95
|
+
* expect(await menu.hasMenuItems(["Copy text", "Filter"])).toBe(false);
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* test("sub menu has expected items", async ({ page }) => {
|
|
100
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
101
|
+
* const filterMenu = await menu.menuItem("Filter").openSubMenu();
|
|
102
|
+
* expect(
|
|
103
|
+
* await filterMenu.hasMenuItems(["Include value", "Exclude value"]),
|
|
104
|
+
* ).toBe(true);
|
|
105
|
+
* });
|
|
32
106
|
*/
|
|
33
107
|
hasMenuItems(labels?: string[]): Promise<boolean>;
|
|
34
108
|
/**
|
|
35
|
-
* Menu item by label, or by 0 based index.
|
|
109
|
+
* Menu item by label (exact match), or by 0 based index.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* test("locate menu items", async ({ page }) => {
|
|
113
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
114
|
+
* const copy = menu.menuItem("Copy text");
|
|
115
|
+
* expect(await copy.isEnabled()).toBe(true);
|
|
116
|
+
* expect(await menu.menuItem(1).label()).toEqual("Filter");
|
|
117
|
+
* });
|
|
36
118
|
*/
|
|
37
119
|
menuItem(labelOrIndex: string | number): PwMenuItem;
|
|
38
120
|
/**
|
|
39
121
|
* The menu item that currently has keyboard focus. The item must also be the
|
|
40
122
|
* menu's active item (tabindex="0"), which confirms the menu has processed the
|
|
41
123
|
* focus change and is ready for the next key press.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* test("first item focused after ArrowDown", async ({ page }) => {
|
|
127
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
128
|
+
* await menu.press("ArrowDown");
|
|
129
|
+
* await expect(menu.focusedMenuItem.locator).toHaveText("Copy text");
|
|
130
|
+
* });
|
|
42
131
|
*/
|
|
43
132
|
get focusedMenuItem(): PwMenuItem;
|
|
44
133
|
/**
|
|
45
134
|
* Assert the focused menu item. Wait on this between key presses, keys
|
|
46
135
|
* pressed before the menu has processed a focus change may be misdirected.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* test("arrow keys move focus", async ({ page }) => {
|
|
139
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
140
|
+
* await menu.press("ArrowDown");
|
|
141
|
+
* await menu.assertFocusedMenuItem("Copy text");
|
|
142
|
+
* await menu.press("ArrowDown");
|
|
143
|
+
* await menu.assertFocusedMenuItem("Filter");
|
|
144
|
+
* });
|
|
47
145
|
*/
|
|
48
146
|
assertFocusedMenuItem(label: string): Promise<void>;
|
|
49
147
|
/**
|
|
@@ -53,13 +151,23 @@ export declare class PwContextMenu extends PwComponent {
|
|
|
53
151
|
* a key depends on the focus change of the previous key.
|
|
54
152
|
*
|
|
55
153
|
* @example
|
|
56
|
-
*
|
|
57
|
-
* await
|
|
58
|
-
*
|
|
154
|
+
* test("Enter invokes focused item", async ({ page }) => {
|
|
155
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
156
|
+
* await menu.press("ArrowDown");
|
|
157
|
+
* await menu.assertFocusedMenuItem("Copy text");
|
|
158
|
+
* await menu.press("Enter");
|
|
159
|
+
* await menu.assertNotAttached();
|
|
160
|
+
* });
|
|
59
161
|
*/
|
|
60
162
|
press(...keys: string[]): Promise<void>;
|
|
61
163
|
/**
|
|
62
|
-
* Close the menu by pressing Escape.
|
|
164
|
+
* Close the menu by pressing Escape. Resolves once the menu is removed.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* test("Escape closes menu", async ({ page }) => {
|
|
168
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
169
|
+
* await menu.close();
|
|
170
|
+
* });
|
|
63
171
|
*/
|
|
64
172
|
close(): Promise<void>;
|
|
65
173
|
}
|
package/types/PwMenuItem.d.ts
CHANGED
|
@@ -4,45 +4,193 @@ import { PwContextMenu } from "./PwContextMenu";
|
|
|
4
4
|
/**
|
|
5
5
|
* A single item within a PwContextMenu. Usually obtained from
|
|
6
6
|
* PwContextMenu.menuItem rather than constructed directly.
|
|
7
|
+
*
|
|
8
|
+
* The boolean query methods (hasChildren, isDisabled, hasIcon etc) read the
|
|
9
|
+
* current state and do not retry. For state that changes after an action, use
|
|
10
|
+
* a web-first assertion on `locator`, e.g.
|
|
11
|
+
* `await expect(item.locator).toHaveAttribute("aria-expanded", "true")`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* test("menu item state", async ({ page }) => {
|
|
15
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
16
|
+
* const item = menu.menuItem("Copy text");
|
|
17
|
+
* expect(await item.isEnabled()).toBe(true);
|
|
18
|
+
* expect(await item.hasIcon("edit")).toBe(true);
|
|
19
|
+
* await item.click();
|
|
20
|
+
* });
|
|
7
21
|
*/
|
|
8
22
|
export declare class PwMenuItem extends PwComponent {
|
|
9
23
|
protected readonly defaultCssSelector = "[role=\"menuitem\"]";
|
|
10
24
|
/**
|
|
11
25
|
* The text label of the menu item.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* test("second item is Filter", async ({ page }) => {
|
|
29
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
30
|
+
* expect(await menu.menuItem(1).label()).toEqual("Filter");
|
|
31
|
+
* });
|
|
12
32
|
*/
|
|
13
33
|
label(): Promise<string>;
|
|
14
34
|
/**
|
|
15
|
-
* Does this menu item open a sub menu.
|
|
35
|
+
* Does this menu item open a sub menu (aria-haspopup="menu").
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* test("Filter has a sub menu", async ({ page }) => {
|
|
39
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
40
|
+
* expect(await menu.menuItem("Filter").hasChildren()).toBe(true);
|
|
41
|
+
* expect(await menu.menuItem("Copy text").hasChildren()).toBe(false);
|
|
42
|
+
* });
|
|
16
43
|
*/
|
|
17
44
|
hasChildren(): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Is the menu item disabled (aria-disabled="true"). Disabled items cannot be
|
|
47
|
+
* clicked and are skipped by keyboard navigation.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* test("Delete row is disabled", async ({ page }) => {
|
|
51
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
52
|
+
* expect(await menu.menuItem("Delete row").isDisabled()).toBe(true);
|
|
53
|
+
* });
|
|
54
|
+
*/
|
|
18
55
|
isDisabled(): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Is the menu item enabled. The inverse of isDisabled.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* test("Copy text is enabled", async ({ page }) => {
|
|
61
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
62
|
+
* expect(await menu.menuItem("Copy text").isEnabled()).toBe(true);
|
|
63
|
+
* });
|
|
64
|
+
*/
|
|
19
65
|
isEnabled(): Promise<boolean>;
|
|
20
66
|
/**
|
|
21
|
-
* Is the sub menu of this menu item open. Always
|
|
67
|
+
* Is the sub menu of this menu item open (aria-expanded="true"). Always
|
|
68
|
+
* false for leaf items.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* test("Filter expands on hover", async ({ page }) => {
|
|
72
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
73
|
+
* const filter = menu.menuItem("Filter");
|
|
74
|
+
* expect(await filter.isExpanded()).toBe(false);
|
|
75
|
+
* await filter.openSubMenu();
|
|
76
|
+
* expect(await filter.isExpanded()).toBe(true);
|
|
77
|
+
* });
|
|
22
78
|
*/
|
|
23
79
|
isExpanded(): Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* Does the menu item have DOM focus. Does not wait or retry, prefer
|
|
82
|
+
* PwContextMenu.assertFocusedMenuItem after a key press.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* test("Copy text focused", async ({ page }) => {
|
|
86
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
87
|
+
* await menu.press("ArrowDown");
|
|
88
|
+
* await menu.assertFocusedMenuItem("Copy text");
|
|
89
|
+
* expect(await menu.menuItem("Copy text").isFocused()).toBe(true);
|
|
90
|
+
* });
|
|
91
|
+
*/
|
|
24
92
|
isFocused(): Promise<boolean>;
|
|
25
93
|
/**
|
|
26
94
|
* Is the menu item decorated with the given icon (data-icon attribute).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* test("Copy text has edit icon", async ({ page }) => {
|
|
98
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
99
|
+
* expect(await menu.menuItem("Copy text").hasIcon("edit")).toBe(true);
|
|
100
|
+
* });
|
|
27
101
|
*/
|
|
28
102
|
hasIcon(iconName: string): Promise<boolean>;
|
|
29
103
|
/**
|
|
30
104
|
* Click the menu item. Playwright will not click a disabled item unless
|
|
31
105
|
* { force: true } is passed.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* test("click invokes menu action", async ({ page }) => {
|
|
109
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
110
|
+
* await menu.menuItem("Copy text").click();
|
|
111
|
+
* await menu.assertNotAttached();
|
|
112
|
+
* });
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* test("clicking disabled item does nothing", async ({ page }) => {
|
|
116
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
117
|
+
* await menu.menuItem("Delete row").click({ force: true });
|
|
118
|
+
* await menu.assertVisible();
|
|
119
|
+
* });
|
|
32
120
|
*/
|
|
33
121
|
click(options?: Parameters<Locator["click"]>[0]): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Hover over the menu item. Hovering an item with children opens its sub
|
|
124
|
+
* menu, use openSubMenu to also wait for the sub menu.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* test("hover expands Filter", async ({ page }) => {
|
|
128
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
129
|
+
* const filter = menu.menuItem("Filter");
|
|
130
|
+
* await filter.hover();
|
|
131
|
+
* await expect(filter.locator).toHaveAttribute("aria-expanded", "true");
|
|
132
|
+
* });
|
|
133
|
+
*/
|
|
34
134
|
hover(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Give the menu item DOM focus.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* test("focus Sort then open with keyboard", async ({ page }) => {
|
|
140
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
141
|
+
* const sort = menu.menuItem("Sort");
|
|
142
|
+
* await sort.focus();
|
|
143
|
+
* await sort.press("ArrowRight");
|
|
144
|
+
* await expect(sort.locator).toHaveAttribute("aria-expanded", "true");
|
|
145
|
+
* });
|
|
146
|
+
*/
|
|
35
147
|
focus(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Press a key with the menu item as target. Focuses the item first.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* test("Enter on item invokes action", async ({ page }) => {
|
|
153
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
154
|
+
* await menu.menuItem("Copy text").press("Enter");
|
|
155
|
+
* await menu.assertNotAttached();
|
|
156
|
+
* });
|
|
157
|
+
*/
|
|
36
158
|
press(key: string): Promise<void>;
|
|
37
159
|
/**
|
|
38
160
|
* The sub menu opened by this menu item. The sub menu must already be open,
|
|
39
161
|
* use openSubMenu to open it.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* test("sub menu opened by hover", async ({ page }) => {
|
|
165
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
166
|
+
* const filter = menu.menuItem("Filter");
|
|
167
|
+
* await filter.hover();
|
|
168
|
+
* const filterMenu = await filter.subMenu();
|
|
169
|
+
* expect(await filterMenu.hasMenuItems()).toBe(true);
|
|
170
|
+
* });
|
|
40
171
|
*/
|
|
41
172
|
subMenu(): Promise<PwContextMenu>;
|
|
42
173
|
/**
|
|
43
174
|
* Open the sub menu of this menu item, using the mouse (hover) or keyboard
|
|
44
175
|
* (ArrowRight). Resolves once the sub menu is visible and, when opened with
|
|
45
176
|
* the keyboard, once focus has moved into the sub menu.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* test("open sub menu with mouse", async ({ page }) => {
|
|
180
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
181
|
+
* const filterMenu = await menu.menuItem("Filter").openSubMenu();
|
|
182
|
+
* await filterMenu.menuItem("Include value").click();
|
|
183
|
+
* await menu.assertNotAttached();
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* test("open sub menu with keyboard", async ({ page }) => {
|
|
188
|
+
* const menu = await new PwTable(page).showContextMenu("ric", 2);
|
|
189
|
+
* const sortMenu = await menu.menuItem("Sort").openSubMenu("keyboard");
|
|
190
|
+
* await sortMenu.assertFocusedMenuItem("Ascending");
|
|
191
|
+
* await sortMenu.press("ArrowLeft");
|
|
192
|
+
* await sortMenu.assertNotAttached();
|
|
193
|
+
* });
|
|
46
194
|
*/
|
|
47
195
|
openSubMenu(using?: "mouse" | "keyboard"): Promise<PwContextMenu>;
|
|
48
196
|
}
|