-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcommand-palette-basic.spec.ts
More file actions
104 lines (73 loc) · 3.56 KB
/
Copy pathcommand-palette-basic.spec.ts
File metadata and controls
104 lines (73 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { test, expect } from '@playwright/test';
import { triggerCommandPaletteOpen } from './testUtils/triggerCommandPaletteOpen';
test.describe('Test basic interactions of Command Palette', () => {
test('should be able to open command palette & run first action', async ({ page }) => {
await page.goto('/demo');
await triggerCommandPaletteOpen(page);
await page.click('text=Increment Counter by 1');
await expect(page.locator('strong >> text=1')).toBeVisible();
});
test('should be able to search for actions in command palette', async ({ page }) => {
await page.goto('/demo');
await triggerCommandPaletteOpen(page);
await page.keyboard.type('GitHub');
const searchLocator = page.locator('input[type="search"]');
await expect(searchLocator).toHaveValue('GitHub');
const optionLocator = page.locator('[role="combobox"] >> [role="option"]');
const optionsNum = await optionLocator.count();
expect(optionsNum).toBe(1);
await expect(optionLocator.first()).toContainText('Go to GitHub repo');
});
test('should be able to navigate between actions using keyboard', async ({ page }) => {
await page.goto('/demo');
await triggerCommandPaletteOpen(page);
// Navigate to third action by pressing Down key twice.
await page.keyboard.press('ArrowDown');
await page.keyboard.press('ArrowDown');
const optionLocator = page.locator('[role="combobox"] >> [role="option"]');
let isThirdOptionSelected = await optionLocator.nth(2).getAttribute('aria-selected');
expect(isThirdOptionSelected).toEqual('true');
// Navigate to second action by pressing Up key once.
await page.keyboard.press('ArrowUp');
isThirdOptionSelected = await optionLocator.nth(2).getAttribute('aria-selected');
const isSecondOptionSelected = await optionLocator.nth(1).getAttribute('aria-selected');
expect(isThirdOptionSelected).toEqual('false');
expect(isSecondOptionSelected).toEqual('true');
});
test('should only render Unmute Audio action when muted', async ({ page }) => {
await page.goto('/demo');
await triggerCommandPaletteOpen(page);
await expect(page.locator('[role="combobox"]')).not.toContainText('Unmute');
await page.keyboard.press('Escape');
await page.check('label >> text=Audible');
await triggerCommandPaletteOpen(page);
await page.click('[role="combobox"] >> text=Unmute');
const isUnmuted = await page.isChecked('label >> text=Audible');
expect(isUnmuted).toBeFalsy();
});
test('should be able to run nested actions', async ({ page }) => {
await page.goto('/demo');
await triggerCommandPaletteOpen(page);
await page.keyboard.type('Profile');
const optionLocator = page.locator('[role="combobox"] >> [role="option"]');
await optionLocator.locator('text=Set profile').click();
const searchLocator = page.locator('input[type="search"]');
await expect(searchLocator).toHaveValue('');
const optionsNum = await optionLocator.count();
expect(optionsNum).toBe(2);
await optionLocator.locator('text=Set to Work profile').click();
const profileStatusLocator = page
.locator('section', {
hasText: 'Nested actions',
})
.last()
.locator('text=Active profile is work');
await expect(profileStatusLocator).toBeVisible();
});
test('should be able to open nested actions using keyboard', async ({ page }) => {
await page.goto('/demo');
await page.keyboard.press('p');
await page.keyboard.press('s');
await expect(page.locator('.command-palette-portal [role="combobox"]')).toBeVisible();
});
});