@ni/nimble-components 29.4.2 → 29.5.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.
@@ -0,0 +1,56 @@
1
+ import type { MenuButton } from '..';
2
+ /**
3
+ * Page object for `nimble-menu-button` component to provide consistent ways
4
+ * of querying and interacting with the component during tests.
5
+ *
6
+ * This page object is intended to be used to interact with a `nimble-menu-button`,
7
+ * not the menu slotted into the button or the menu items.
8
+ */
9
+ export declare class MenuButtonPageObject {
10
+ protected readonly menuButtonElement: MenuButton;
11
+ constructor(menuButtonElement: MenuButton);
12
+ /**
13
+ * @returns Whether or not the menu is open.
14
+ */
15
+ isOpen(): boolean;
16
+ /**
17
+ * Opens the menu.
18
+ * @returns A promise that resolves when the menu opens.
19
+ */
20
+ openMenu(): Promise<void>;
21
+ /**
22
+ * Closes the menu by pressing Escape.
23
+ * Throws an error if the menu is not open.
24
+ */
25
+ closeMenuWithEscape(): void;
26
+ /**
27
+ * Gets the text in the menu button.
28
+ * @returns The trimmed text that is slotted into the menu button.
29
+ */
30
+ getLabelText(): string;
31
+ /**
32
+ * @internal
33
+ * Focuses and clicks the menu button.
34
+ */
35
+ clickMenuButton(): void;
36
+ /**
37
+ * @internal
38
+ * Presses the Enter key on the menu button.
39
+ */
40
+ pressEnterKey(): void;
41
+ /**
42
+ * @internal
43
+ * Presses the Space key on the menu button.
44
+ */
45
+ pressSpaceKey(): void;
46
+ /**
47
+ * @internal
48
+ * Presses the Arrow Up key on the menu button.
49
+ */
50
+ pressArrowUpKey(): void;
51
+ /**
52
+ * @internal
53
+ * Presses the Arrow Down key on the menu button.
54
+ */
55
+ pressArrowDownKey(): void;
56
+ }
@@ -0,0 +1,103 @@
1
+ import { keyArrowDown, keyArrowUp, keyEnter, keyEscape, keySpace } from '@microsoft/fast-web-utilities';
2
+ import { waitForEventAsync } from '../../utilities/tests/component';
3
+ /**
4
+ * Page object for `nimble-menu-button` component to provide consistent ways
5
+ * of querying and interacting with the component during tests.
6
+ *
7
+ * This page object is intended to be used to interact with a `nimble-menu-button`,
8
+ * not the menu slotted into the button or the menu items.
9
+ */
10
+ export class MenuButtonPageObject {
11
+ constructor(menuButtonElement) {
12
+ this.menuButtonElement = menuButtonElement;
13
+ }
14
+ /**
15
+ * @returns Whether or not the menu is open.
16
+ */
17
+ isOpen() {
18
+ return this.menuButtonElement.open;
19
+ }
20
+ /**
21
+ * Opens the menu.
22
+ * @returns A promise that resolves when the menu opens.
23
+ */
24
+ async openMenu() {
25
+ if (this.isOpen()) {
26
+ return;
27
+ }
28
+ const toggleEventPromise = waitForEventAsync(this.menuButtonElement, 'toggle');
29
+ this.clickMenuButton();
30
+ await toggleEventPromise;
31
+ }
32
+ /**
33
+ * Closes the menu by pressing Escape.
34
+ * Throws an error if the menu is not open.
35
+ */
36
+ closeMenuWithEscape() {
37
+ if (!this.isOpen()) {
38
+ throw new Error('Cannot close menu when it is not open');
39
+ }
40
+ const event = new KeyboardEvent('keydown', {
41
+ key: keyEscape
42
+ });
43
+ this.menuButtonElement.region.dispatchEvent(event);
44
+ }
45
+ /**
46
+ * Gets the text in the menu button.
47
+ * @returns The trimmed text that is slotted into the menu button.
48
+ */
49
+ getLabelText() {
50
+ return this.menuButtonElement.textContent?.trim() ?? '';
51
+ }
52
+ /**
53
+ * @internal
54
+ * Focuses and clicks the menu button.
55
+ */
56
+ clickMenuButton() {
57
+ // Focus the menu button before calling click() because ordinarily a mouse click
58
+ // would bring focus to the button, but calling click() directly does not.
59
+ this.menuButtonElement.focus();
60
+ this.menuButtonElement.toggleButton.control.click();
61
+ }
62
+ /**
63
+ * @internal
64
+ * Presses the Enter key on the menu button.
65
+ */
66
+ pressEnterKey() {
67
+ const event = new KeyboardEvent('keypress', {
68
+ key: keyEnter
69
+ });
70
+ this.menuButtonElement.toggleButton.control.dispatchEvent(event);
71
+ }
72
+ /**
73
+ * @internal
74
+ * Presses the Space key on the menu button.
75
+ */
76
+ pressSpaceKey() {
77
+ const event = new KeyboardEvent('keypress', {
78
+ key: keySpace
79
+ });
80
+ this.menuButtonElement.toggleButton.control.dispatchEvent(event);
81
+ }
82
+ /**
83
+ * @internal
84
+ * Presses the Arrow Up key on the menu button.
85
+ */
86
+ pressArrowUpKey() {
87
+ const event = new KeyboardEvent('keydown', {
88
+ key: keyArrowUp
89
+ });
90
+ this.menuButtonElement.toggleButton.dispatchEvent(event);
91
+ }
92
+ /**
93
+ * @internal
94
+ * Presses the Arrow Down key on the menu button.
95
+ */
96
+ pressArrowDownKey() {
97
+ const event = new KeyboardEvent('keydown', {
98
+ key: keyArrowDown
99
+ });
100
+ this.menuButtonElement.toggleButton.dispatchEvent(event);
101
+ }
102
+ }
103
+ //# sourceMappingURL=menu-button.pageobject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menu-button.pageobject.js","sourceRoot":"","sources":["../../../../src/menu-button/testing/menu-button.pageobject.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACX,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,OAAO,oBAAoB;IAC7B,YAAsC,iBAA6B;QAA7B,sBAAiB,GAAjB,iBAAiB,CAAY;IAAG,CAAC;IAEvE;;OAEG;IACI,MAAM;QACT,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,QAAQ;QACjB,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACf,OAAO;SACV;QAED,MAAM,kBAAkB,GAAG,iBAAiB,CACxC,IAAI,CAAC,iBAAiB,EACtB,QAAQ,CACX,CAAC;QACF,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,MAAM,kBAAkB,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACI,mBAAmB;QACtB,IAAI,CAAC,IA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;IACI,iBAAiB;QACpB,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,SAAS,EAAE;YACvC,GAAG,EAAE,YAAY;SACpB,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,CAAC,YAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import {\n keyArrowDown,\n keyArrowUp,\n keyEnter,\n keyEscape,\n keySpace\n} from '@microsoft/fast-web-utilities';\nimport type { MenuButton } from '..';\nimport { waitForEventAsync } from '../../utilities/tests/component';\n\n/**\n * Page object for `nimble-menu-button` component to provide consistent ways\n * of querying and interacting with the component during tests.\n *\n * This page object is intended to be used to interact with a `nimble-menu-button`,\n * not the menu slotted into the button or the menu items.\n */\nexport class MenuButtonPageObject {\n public constructor(protected readonly menuButtonElement: MenuButton) {}\n\n /**\n * @returns Whether or not the menu is open.\n */\n public isOpen(): boolean {\n return this.menuButtonElement.open;\n }\n\n /**\n * Opens the menu.\n * @returns A promise that resolves when the menu opens.\n */\n public async openMenu(): Promise<void> {\n if (this.isOpen()) {\n return;\n }\n\n const toggleEventPromise = waitForEventAsync(\n this.menuButtonElement,\n 'toggle'\n );\n this.clickMenuButton();\n await toggleEventPromise;\n }\n\n /**\n * Closes the menu by pressing Escape.\n * Throws an error if the menu is not open.\n */\n public closeMenuWithEscape(): void {\n if (!this.isOpen()) {\n throw new Error('Cannot close menu when it is not open');\n }\n\n const event = new KeyboardEvent('keydown', {\n key: keyEscape\n });\n this.menuButtonElement.region!.dispatchEvent(event);\n }\n\n /**\n * Gets the text in the menu button.\n * @returns The trimmed text that is slotted into the menu button.\n */\n public getLabelText(): string {\n return this.menuButtonElement.textContent?.trim() ?? '';\n }\n\n /**\n * @internal\n * Focuses and clicks the menu button.\n */\n public clickMenuButton(): void {\n // Focus the menu button before calling click() because ordinarily a mouse click\n // would bring focus to the button, but calling click() directly does not.\n this.menuButtonElement.focus();\n this.menuButtonElement.toggleButton!.control.click();\n }\n\n /**\n * @internal\n * Presses the Enter key on the menu button.\n */\n public pressEnterKey(): void {\n const event = new KeyboardEvent('keypress', {\n key: keyEnter\n });\n this.menuButtonElement.toggleButton!.control.dispatchEvent(event);\n }\n\n /**\n * @internal\n * Presses the Space key on the menu button.\n */\n public pressSpaceKey(): void {\n const event = new KeyboardEvent('keypress', {\n key: keySpace\n });\n this.menuButtonElement.toggleButton!.control.dispatchEvent(event);\n }\n\n /**\n * @internal\n * Presses the Arrow Up key on the menu button.\n */\n public pressArrowUpKey(): void {\n const event = new KeyboardEvent('keydown', {\n key: keyArrowUp\n });\n this.menuButtonElement.toggleButton!.dispatchEvent(event);\n }\n\n /**\n * @internal\n * Presses the Arrow Down key on the menu button.\n */\n public pressArrowDownKey(): void {\n const event = new KeyboardEvent('keydown', {\n key: keyArrowDown\n });\n this.menuButtonElement.toggleButton!.dispatchEvent(event);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ni/nimble-components",
3
- "version": "29.4.2",
3
+ "version": "29.5.0",
4
4
  "description": "Styled web components for the NI Nimble Design System",
5
5
  "scripts": {
6
6
  "build": "npm run generate-icons && npm run generate-workers && npm run build-components && npm run bundle-components && npm run generate-scss",