|
1 | | -import { expect } from '@playwright/test' |
2 | 1 | import { readFixture } from '../app/utils/fixtures' |
3 | | -import { test } from './base-test' |
| 2 | +import { test, expect } from './base-test' |
4 | 3 |
|
5 | 4 | test.use({ |
6 | 5 | storageState: 'e2e/fixtures/auth/public.json', |
7 | 6 | }) |
8 | 7 |
|
9 | | -test.skip('Login', async ({ page, queries: { getByRole } }) => { |
10 | | - // Go to http://localhost:3000/ |
| 8 | +test.skip('Login', async ({ page, screen }) => { |
| 9 | + // Go to homepage |
11 | 10 | await page.goto('/') |
12 | 11 |
|
13 | | - // Click text=Masuk |
14 | | - await page.click('text=Masuk') |
15 | | - await expect(page).toHaveURL('http://localhost:3000/login') |
| 12 | + // Click login link and wait for navigation |
| 13 | + await page.getByRole('link', { name: /masuk/i }).click() |
| 14 | + await page.waitForURL('**/login') |
16 | 15 |
|
17 | 16 | const { email } = JSON.parse( |
18 | 17 | await readFixture(`../../e2e/fixtures/users/member.local.json`) |
19 | 18 | ) |
20 | 19 |
|
21 | | - // Query email |
22 | | - const emailField = await getByRole('textbox', { |
| 20 | + // Query email - using Locator-based screen queries |
| 21 | + const emailField = screen.getByRole('textbox', { |
23 | 22 | name: /alamat email/i, |
24 | 23 | }) |
25 | 24 |
|
26 | 25 | // Fill email |
27 | 26 | await emailField.fill(email) |
28 | 27 |
|
29 | | - // Click text=Kirim link ke alamat email |
30 | | - await Promise.all([ |
31 | | - page.waitForNavigation(/*{ url: 'http://localhost:3000/login' }*/), |
32 | | - page.click('text=Kirim link ke alamat email'), |
33 | | - ]) |
| 28 | + // Submit login form |
| 29 | + await page.getByRole('button', { name: /kirim link/i }).click() |
34 | 30 |
|
35 | | - // Click text=Link telah dikirim ke alamat email Anda |
| 31 | + // Wait for success message |
36 | 32 | await expect( |
37 | | - page.locator('text=Link telah dikirim ke alamat email Anda').first() |
| 33 | + page.getByText('Link telah dikirim ke alamat email Anda') |
38 | 34 | ).toBeVisible() |
39 | 35 |
|
40 | 36 | const { magicLink } = JSON.parse( |
41 | 37 | await readFixture(`../../e2e/fixtures/magic.local.json`) |
42 | 38 | ) |
43 | 39 |
|
44 | | - // Go to the magic link |
| 40 | + // Go to the magic link and verify dashboard redirect |
45 | 41 | await page.goto(magicLink) |
46 | | - |
47 | | - // If the magic link matches the current token stored in the session storage, |
48 | | - // the user will be redirected to the dashboard automatically. |
49 | | - await expect(page).toHaveURL('http://localhost:3000/dashboard') |
| 42 | + await page.waitForURL('**/dashboard') |
50 | 43 | }) |
0 commit comments