|
1 | | -import { test, expect } from '@playwright/test'; |
2 | | - |
3 | | -test('test', async ({ page }) => { |
4 | | - await page.goto('http://127.0.0.1:8080/component/?name=select&', { timeout: 20 * 60 * 1000 }); // Increase timeout to 20 minutes |
5 | | - // Find Select a fruit... |
6 | | - let selectTrigger = page.locator(".select-trigger"); |
7 | | - await selectTrigger.click(); |
8 | | - // Assert the select menu is open |
9 | | - const selectMenu = page.locator('.select-list'); |
10 | | - await expect(selectMenu).toHaveAttribute('data-state', 'open'); |
11 | | - |
12 | | - // Assert the menu is focused |
13 | | - await expect(selectMenu).toBeFocused(); |
14 | | - await page.keyboard.press('ArrowDown'); |
15 | | - const firstOption = selectMenu.getByRole('option', { name: 'apple' }); |
16 | | - await expect(firstOption).toBeFocused(); |
17 | | - |
18 | | - // Assert moving down with arrow keys moves focus to the next option |
19 | | - await page.keyboard.press('ArrowDown'); |
20 | | - const secondOption = selectMenu.getByRole('option', { name: 'banana' }); |
21 | | - await expect(secondOption).toBeFocused(); |
22 | | - |
23 | | - // Assert moving up with arrow keys moves focus back to the previous option |
24 | | - await page.keyboard.press('ArrowUp'); |
25 | | - await expect(firstOption).toBeFocused(); |
26 | | - |
27 | | - // Assert pressing Enter selects the focused option |
28 | | - await page.keyboard.press('Enter'); |
29 | | - // Assert the select menu is closed after selection |
30 | | - await expect(selectMenu).toHaveCount(0); |
31 | | - |
32 | | - // Assert the selected value is displayed in the button |
33 | | - await expect(selectTrigger).toHaveText('apple'); |
34 | | - |
35 | | - // Reopen the select menu |
36 | | - await selectTrigger.click(); |
37 | | - |
38 | | - // Assert typeahead functionality works |
39 | | - await page.keyboard.type('Ban'); |
40 | | - // Assert the second option is focused after typing 'Ban' |
41 | | - await expect(secondOption).toBeFocused(); |
42 | | - |
43 | | - // Assert pressing Escape closes the select menu |
44 | | - await page.keyboard.press('Escape'); |
45 | | - // Assert the select menu is closed |
46 | | - await expect(selectMenu).toHaveCount(0); |
47 | | - |
48 | | - // Reopen the select menu |
49 | | - await selectTrigger.click(); |
50 | | - // Assert the select menu is open again |
51 | | - await expect(selectMenu).toHaveAttribute('data-state', 'open'); |
52 | | - |
53 | | - // Click the second option to select it |
54 | | - let bananaOption = selectMenu.getByRole('option', { name: 'banana' }); |
55 | | - await bananaOption.click(); |
56 | | - // Assert the select menu is closed after clicking an option |
57 | | - await expect(selectMenu).toHaveCount(0); |
58 | | - // Assert the selected value is now 'banana' |
59 | | - await expect(selectTrigger).toHaveText('banana'); |
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +test("test", async ({ page }) => { |
| 4 | + await page.goto("http://127.0.0.1:8080/component/?name=select&", { |
| 5 | + timeout: 20 * 60 * 1000, |
| 6 | + }); // Increase timeout to 20 minutes |
| 7 | + // Find Select a fruit... |
| 8 | + let selectTrigger = page.locator(".select-trigger"); |
| 9 | + await selectTrigger.click(); |
| 10 | + // Assert the select menu is open |
| 11 | + const selectMenu = page.locator(".select-list"); |
| 12 | + await expect(selectMenu).toHaveAttribute("data-state", "open"); |
| 13 | + |
| 14 | + // Assert the menu is focused |
| 15 | + await expect(selectMenu).toBeFocused(); |
| 16 | + await page.keyboard.press("ArrowDown"); |
| 17 | + const firstOption = selectMenu.getByRole("option", { name: "apple" }); |
| 18 | + await expect(firstOption).toBeFocused(); |
| 19 | + |
| 20 | + // Assert moving down with arrow keys moves focus to the next option |
| 21 | + await page.keyboard.press("ArrowDown"); |
| 22 | + const secondOption = selectMenu.getByRole("option", { name: "banana" }); |
| 23 | + await expect(secondOption).toBeFocused(); |
| 24 | + |
| 25 | + // Assert moving up with arrow keys moves focus back to the previous option |
| 26 | + await page.keyboard.press("ArrowUp"); |
| 27 | + await expect(firstOption).toBeFocused(); |
| 28 | + |
| 29 | + // Assert pressing Enter selects the focused option |
| 30 | + await page.keyboard.press("Enter"); |
| 31 | + // Assert the select menu is closed after selection |
| 32 | + await expect(selectMenu).toHaveCount(0); |
| 33 | + |
| 34 | + // Assert the selected value is displayed in the button |
| 35 | + await expect(selectTrigger).toHaveText("Apple"); |
| 36 | + |
| 37 | + // Reopen the select menu |
| 38 | + await selectTrigger.click(); |
| 39 | + |
| 40 | + // Assert typeahead functionality works |
| 41 | + await page.keyboard.type("Ban"); |
| 42 | + // Assert the second option is focused after typing 'Ban' |
| 43 | + await expect(secondOption).toBeFocused(); |
| 44 | + |
| 45 | + // Assert pressing Escape closes the select menu |
| 46 | + await page.keyboard.press("Escape"); |
| 47 | + // Assert the select menu is closed |
| 48 | + await expect(selectMenu).toHaveCount(0); |
| 49 | + |
| 50 | + // Reopen the select menu |
| 51 | + await selectTrigger.click(); |
| 52 | + // Assert the select menu is open again |
| 53 | + await expect(selectMenu).toHaveAttribute("data-state", "open"); |
| 54 | + |
| 55 | + // Click the second option to select it |
| 56 | + let bananaOption = selectMenu.getByRole("option", { name: "banana" }); |
| 57 | + await bananaOption.click(); |
| 58 | + // Assert the select menu is closed after clicking an option |
| 59 | + await expect(selectMenu).toHaveCount(0); |
| 60 | + // Assert the selected value is now 'banana' |
| 61 | + await expect(selectTrigger).toHaveText("Banana"); |
60 | 62 | }); |
0 commit comments