Files
goodgo-platform/e2e/web/create-listing.spec.ts
2026-05-04 20:11:09 +07:00

53 lines
2.1 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { mockAuthenticatedUser } from './support/auth';
test.describe('Create Listing Page (Multi-step Form)', () => {
test.beforeEach(async ({ page, context, baseURL }) => {
await mockAuthenticatedUser(page, context, baseURL, { role: 'AGENT' });
await page.goto('/my-listings/new');
});
test('renders step 1 - basic info form', async ({ page }) => {
// Step indicators should be visible
await expect(page.getByText('Thông tin', { exact: true })).toBeVisible();
await expect(page.getByText('Vị trí', { exact: true })).toBeVisible();
await expect(page.getByText('Chi tiết', { exact: true })).toBeVisible();
await expect(page.getByText('Giá cả', { exact: true })).toBeVisible();
await expect(page.getByText('Hình ảnh', { exact: true })).toBeVisible();
});
test('shows validation errors when advancing without filling required fields', async ({ page }) => {
// Try to go to next step without filling anything
const nextButton = page.getByRole('button', { name: /Tiep|Next|Tiếp/i });
if (await nextButton.isVisible()) {
await nextButton.click();
// Should show validation errors
const alerts = page.locator('[role="alert"], .text-destructive');
await expect(alerts.first()).toBeVisible({ timeout: 5000 });
}
});
test('has back button disabled on first step', async ({ page }) => {
const backButton = page.getByRole('button', { name: /Quay lai|Back|Quay lại/i });
if (await backButton.isVisible()) {
await expect(backButton).toBeDisabled();
}
});
test('shows error alert on submission failure', async ({ page }) => {
await page.route('**/api/v1/listings', (route) => {
if (route.request().method() === 'POST') {
return route.fulfill({
status: 400,
contentType: 'application/json',
body: JSON.stringify({ message: 'Validation failed' }),
});
}
return route.continue();
});
// Page should render without errors
await expect(page.getByText('Thông tin', { exact: true })).toBeVisible();
});
});