Skip to content

Commit eee9dc3

Browse files
[wizard] small tests improvement
1 parent dba1b22 commit eee9dc3

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

semcore/wizard/__tests__/wizard.browser-test.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from '@semcore/testing-utils/playwright';
33

44
const locators = {
55
trigger: (page: any, name = 'Open wizard') => page.getByRole('button', { name }),
6-
modal: (page: any) => page.locator('div[data-ui-name=\'Wizard\']'),
6+
modal: (page: any) => page.getByRole('dialog'),
77
sidebar: (page: any) => page.locator('[data-ui-name=\'Wizard.Sidebar\']'),
88
stepperTabs: (page: any) => page.locator('[data-ui-name=\'Wizard.Stepper\']'),
99
contentPanel: (page: any) => page.locator('[data-ui-name=\'Wizard.Content\']'),
@@ -26,7 +26,7 @@ test.describe('Base example', () => {
2626

2727
await test.step('Open modal and verify modal attributes', async () => {
2828
await trigger(page).click();
29-
await page.waitForTimeout(50);
29+
await modal(page).waitFor({ state: 'visible' });
3030
await expect(modal(page)).toBeVisible();
3131
await expect(modal(page)).toHaveAttribute('aria-modal', 'true');
3232
await expect(modal(page)).toHaveAttribute('role', 'dialog');
@@ -101,9 +101,13 @@ test.describe('Base example', () => {
101101

102102
await test.step('Verify selected step saved when Close and reopen modal', async () => {
103103
await nextButton(page, 'Close').click();
104+
await modal(page).waitFor({ state: 'hidden' });
105+
104106
await expect(modal(page)).toBeHidden();
105107

106108
await trigger(page).click();
109+
await modal(page).waitFor({ state: 'visible' });
110+
107111
await expect(modal(page)).toBeVisible();
108112
});
109113

@@ -137,29 +141,30 @@ test.describe('Base example', () => {
137141
await test.step('Open modal using keyboard and verify focus', async () => {
138142
await page.keyboard.press('Tab');
139143
await page.keyboard.press('Enter');
140-
await page.waitForTimeout(50);
144+
await modal(page).waitFor({ state: 'visible' });
141145
await expect(modal(page)).toBeVisible();
142146
await expect(nextButton(page, 'Close')).toBeFocused();
143147
});
144148

145149
await test.step('Close modal using keyboard', async () => {
146150
await page.keyboard.press('Enter');
147-
await expect(modal(page)).toBeHidden();
151+
await modal(page).waitFor({ state: 'hidden' });
148152
await expect(trigger(page)).toBeFocused();
149153
});
150154

151155
await test.step('Reopen and close modal with Escape key', async () => {
152156
await page.keyboard.press('Enter');
153-
await page.waitForTimeout(50);
157+
await modal(page).waitFor({ state: 'visible' });
154158
await expect(modal(page)).toBeVisible();
155159
await page.keyboard.press('Escape');
160+
await modal(page).waitFor({ state: 'hidden' });
156161
await expect(modal(page)).toBeHidden();
157162
await expect(trigger(page)).toBeFocused();
158163
});
159164

160165
await test.step('Verify keyboard navigation on 1st page by TAB after modal just opened', async () => {
161166
await page.keyboard.press('Enter');
162-
await page.waitForTimeout(50);
167+
await modal(page).waitFor({ state: 'visible' });
163168
await expect(nextButton(page, 'Close')).toBeFocused();
164169
await page.keyboard.press('Tab');
165170
await expect(firstStep).toBeFocused();
@@ -279,20 +284,21 @@ test.describe('Custom step example', () => {
279284
await test.step('Open modal using keyboard and verify focus', async () => {
280285
await page.keyboard.press('Tab');
281286
await page.keyboard.press('Enter');
282-
await page.waitForTimeout(50);
287+
await modal(page).waitFor({ state: 'visible' });
283288
await expect(modal(page)).toBeVisible();
284289
await expect(nextButton(page, 'Close')).toBeFocused();
285290
});
286291

287292
await test.step('Close modal with Escape key', async () => {
288293
await page.keyboard.press('Escape');
294+
await modal(page).waitFor({ state: 'hidden' });
289295
await expect(modal(page)).toBeHidden();
290296
await expect(trigger(page)).toBeFocused();
291297
});
292298

293299
await test.step('Verify keyboard navigation on 1st page with inputs by TAB after modal just opened', async () => {
294300
await page.keyboard.press('Enter');
295-
await page.waitForTimeout(50);
301+
await modal(page).waitFor({ state: 'visible' });
296302
await expect(nextButton(page, 'Close')).toBeFocused();
297303
await page.keyboard.press('Tab');
298304
await expect(firstStep).toBeFocused();
@@ -398,7 +404,7 @@ test.describe('Custom stepper example', () => {
398404

399405
await test.step('Open modal using mouse', async () => {
400406
await trigger(page).click();
401-
await page.waitForTimeout(50);
407+
await modal(page).waitFor({ state: 'visible' });
402408
await expect(modal(page)).toBeVisible();
403409
});
404410

@@ -464,7 +470,7 @@ test.describe('Custom stepper example', () => {
464470
await test.step('Open modal using keyboard and verify focus', async () => {
465471
await page.keyboard.press('Tab');
466472
await page.keyboard.press('Enter');
467-
await page.waitForTimeout(150);
473+
await modal(page).waitFor({ state: 'visible' });
468474
await page.keyboard.press('Tab');
469475
await page.keyboard.press('ArrowDown');
470476
await page.keyboard.press('ArrowDown');
@@ -516,8 +522,7 @@ test.describe('Steps and buttons states', () => {
516522

517523
await test.step('Hover active', async () => {
518524
await trigger(page).click();
519-
await page.waitForTimeout(50);
520-
await expect(modal(page)).toBeVisible();
525+
await modal(page).waitFor({ state: 'visible' });
521526
await checkedStep.hover();
522527
await expect(page).toHaveScreenshot();
523528
});

0 commit comments

Comments
 (0)