Skip to content

Commit f723315

Browse files
committed
Create Produkter.spec.ts
1 parent da572b3 commit f723315

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/tests/Produkter/Produkter.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { test, expect, Page, Route } from '@playwright/test';
2+
3+
test.describe('Produkter', () => {
4+
test.beforeEach(async ({ page }: { page: Page }) => {
5+
// Mock GraphQL responses
6+
await page.route('**/graphql', async (route: Route) => {
7+
const postData = route.request().postData();
8+
9+
// Mock successful response for all GraphQL requests
10+
await route.fulfill({
11+
status: 200,
12+
contentType: 'application/json',
13+
body: JSON.stringify({
14+
data: {
15+
products: {
16+
nodes: [{
17+
id: '29',
18+
name: 'Test simple',
19+
price: '100'
20+
}]
21+
}
22+
}
23+
})
24+
});
25+
});
26+
27+
await page.goto('http://localhost:3000');
28+
});
29+
30+
test('basic product purchase flow', async ({ page }: { page: Page }) => {
31+
// Click first product
32+
await page.getByRole('link', { name: 'Test simple' }).click();
33+
34+
// Wait for product page to load
35+
await expect(page.getByRole('button', { name: 'KJØP' })).toBeVisible();
36+
37+
// Click buy button
38+
await page.getByRole('button', { name: 'KJØP' }).click();
39+
40+
// Go to cart
41+
await page.getByRole('link', { name: 'Handlekurv' }).click();
42+
43+
// Verify cart page loaded
44+
await expect(page.getByRole('button', { name: 'GÅ TIL KASSE' })).toBeVisible();
45+
46+
// Go to checkout
47+
await page.getByRole('button', { name: 'GÅ TIL KASSE' }).click();
48+
49+
// Fill in a test field to verify form is accessible
50+
await page.getByPlaceholder('Etternavn').fill('testetternavn');
51+
await expect(page.getByPlaceholder('Etternavn')).toHaveValue('testetternavn');
52+
});
53+
});

0 commit comments

Comments
 (0)