fix: stabilize web e2e locale and timeout
This commit is contained in:
@@ -1,4 +1,20 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { test, expect, type Route } from '@playwright/test';
|
||||
|
||||
async function fulfillJson(route: Route, status: number, body: unknown) {
|
||||
const origin = route.request().headers()['origin'] ?? '*';
|
||||
|
||||
await route.fulfill({
|
||||
status,
|
||||
contentType: 'application/json',
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': origin,
|
||||
'Access-Control-Allow-Credentials': 'true',
|
||||
'Access-Control-Allow-Headers': 'content-type,x-csrf-token',
|
||||
'Access-Control-Allow-Methods': 'GET,POST,OPTIONS',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
}
|
||||
|
||||
test.describe('Register Page', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
@@ -6,12 +22,12 @@ test.describe('Register Page', () => {
|
||||
});
|
||||
|
||||
test('renders registration form with all fields', async ({ page }) => {
|
||||
await expect(page.getByRole('heading', { name: 'Tạo tài khoản' })).toBeVisible();
|
||||
await expect(page.getByText('Nhập thông tin để đăng ký tài khoản GoodGo')).toBeVisible();
|
||||
await expect(page.getByRole('heading', { name: 'Đăng ký' })).toBeVisible();
|
||||
await expect(page.getByText('Tạo tài khoản mới để bắt đầu sử dụng GoodGo')).toBeVisible();
|
||||
|
||||
await expect(page.getByLabel('Họ và tên')).toBeVisible();
|
||||
await expect(page.getByLabel('Số điện thoại')).toBeVisible();
|
||||
await expect(page.getByLabel('Email (tùy chọn)')).toBeVisible();
|
||||
await expect(page.getByLabel('Email')).toBeVisible();
|
||||
await expect(page.getByLabel('Mật khẩu', { exact: false }).first()).toBeVisible();
|
||||
await expect(page.getByLabel('Xác nhận mật khẩu')).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Đăng ký' })).toBeVisible();
|
||||
@@ -73,13 +89,19 @@ test.describe('Register Page', () => {
|
||||
|
||||
test('successful registration redirects to home', async ({ page }) => {
|
||||
await page.route('**/auth/register', (route) =>
|
||||
route.fulfill({
|
||||
status: 201,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
accessToken: 'fake-access-token',
|
||||
refreshToken: 'fake-refresh-token',
|
||||
}),
|
||||
fulfillJson(route, 201, { message: 'Registered successfully' }),
|
||||
);
|
||||
await page.route('**/auth/profile', (route) =>
|
||||
fulfillJson(route, 200, {
|
||||
id: 'test-user-id',
|
||||
email: null,
|
||||
phone: '0912345678',
|
||||
fullName: 'Test User',
|
||||
avatarUrl: null,
|
||||
role: 'USER',
|
||||
kycStatus: 'NOT_SUBMITTED',
|
||||
isActive: true,
|
||||
createdAt: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -94,11 +116,7 @@ test.describe('Register Page', () => {
|
||||
|
||||
test('displays server error on failed registration', async ({ page }) => {
|
||||
await page.route('**/auth/register', (route) =>
|
||||
route.fulfill({
|
||||
status: 409,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ message: 'Số điện thoại đã được đăng ký' }),
|
||||
}),
|
||||
fulfillJson(route, 409, { message: 'Số điện thoại đã được đăng ký' }),
|
||||
);
|
||||
|
||||
await page.getByLabel('Họ và tên').fill('Test User');
|
||||
|
||||
Reference in New Issue
Block a user