Skip to content

Commit f9d6d78

Browse files
committed
test(add_product): add dialog assertion for successful product save
1 parent 0c11b6b commit f9d6d78

2 files changed

Lines changed: 35 additions & 27 deletions

File tree

tests/e2e/add_product.spec.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@ import { test, expect } from '@playwright/test';
33
test.use({ baseURL: process.env.STORE_ADMIN_URL });
44

55
test('can add product ', async ({ page }) => {
6-
await page.goto('/');
7-
8-
await page.getByRole('link', { name: 'Products' }).click();
9-
await page.getByRole('button', { name: 'Add Product' }).click();
10-
11-
await page.getByPlaceholder('Product Name').fill('Bear Snacks');
12-
await page.getByPlaceholder('Price').fill('29.99');
13-
await page.getByPlaceholder('Product Keywords').fill('dog, snack, treat, courage, ghosts');
14-
15-
const askOpenAI = page.getByRole('button', { name: 'Ask OpenAI' });
16-
17-
if (await askOpenAI.isVisible()) {
18-
const aiApiCall = page.waitForResponse('/ai/generate/description');
19-
await askOpenAI.click();
20-
await aiApiCall;
21-
}
22-
else {
23-
await page.getByPlaceholder('Product Description').fill('Something tasty for the pups');
24-
}
25-
26-
await page.getByRole('button', { name: 'Save Product' }).click();
27-
await expect(page.getByRole('heading', { name: 'Bear Snacks - 29.99' })).toBeVisible();
28-
await expect(page.getByRole('button', { name: 'Edit Product' })).toBeVisible();
6+
await page.goto('/');
7+
8+
await page.getByRole('link', { name: 'Products' }).click();
9+
await page.getByRole('button', { name: 'Add Product' }).click();
10+
11+
await page.getByPlaceholder('Product Name').fill('Bear Snacks');
12+
await page.getByPlaceholder('Price').fill('29.99');
13+
await page.getByPlaceholder('Product Keywords').fill('dog, snack, treat, courage, ghosts');
14+
15+
const askOpenAI = page.getByRole('button', { name: 'Ask OpenAI' });
16+
17+
if (await askOpenAI.isVisible()) {
18+
const aiApiCall = page.waitForResponse('/ai/generate/description');
19+
await askOpenAI.click();
20+
await aiApiCall;
21+
}
22+
else {
23+
await page.getByPlaceholder('Product Description').fill('Something tasty for the pups');
24+
}
25+
26+
await page.getByRole('button', { name: 'Save Product' }).click();
27+
28+
page.on('dialog', async dialog => {
29+
expect(dialog.type()).toBe('alert');
30+
expect(dialog.message()).toBe('Product saved successfully');
31+
await dialog.accept();
2932
});
33+
34+
await expect(page).toHaveURL(/\/product\/\d+/);
35+
await expect(page.getByRole('heading', { name: 'Bear Snacks - 29.99' })).toBeVisible();
36+
await expect(page.getByRole('button', { name: 'Edit Product' })).toBeVisible();
37+
});

tests/playwright.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export default defineConfig({
3434
use: { ...devices['Desktop Chrome'] },
3535
},
3636

37-
{
38-
name: 'firefox',
39-
use: { ...devices['Desktop Firefox'] },
40-
},
37+
// {
38+
// name: 'firefox',
39+
// use: { ...devices['Desktop Firefox'] },
40+
// },
4141

4242
// {
4343
// name: 'webkit',

0 commit comments

Comments
 (0)