79 lines
2.7 KiB
TypeScript
79 lines
2.7 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { mockAuthenticatedUser } from './support/auth';
|
|
|
|
const mockModerationQueue = {
|
|
data: [
|
|
{
|
|
listingId: 'l1', propertyTitle: 'Căn hộ cần duyệt', propertyType: 'APARTMENT',
|
|
transactionType: 'SALE', priceVND: 5000000000, sellerName: 'Nguyen Van A',
|
|
moderationScore: 85, createdAt: '2026-03-01T00:00:00Z',
|
|
},
|
|
{
|
|
listingId: 'l2', propertyTitle: 'Nhà phố cần duyệt', propertyType: 'HOUSE',
|
|
transactionType: 'RENT', priceVND: 15000000, sellerName: 'Tran Thi B',
|
|
moderationScore: 42, createdAt: '2026-03-02T00:00:00Z',
|
|
},
|
|
],
|
|
total: 2, page: 1, limit: 20, totalPages: 1,
|
|
};
|
|
|
|
test.describe('Admin Moderation Page', () => {
|
|
test.beforeEach(async ({ page, context, baseURL }) => {
|
|
await mockAuthenticatedUser(page, context, baseURL, { role: 'ADMIN' });
|
|
|
|
await page.route('**/api/v1/admin/moderation**', (route) => {
|
|
if (route.request().method() === 'GET') {
|
|
return route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(mockModerationQueue),
|
|
});
|
|
}
|
|
return route.continue();
|
|
});
|
|
});
|
|
|
|
test('renders moderation queue with listings', async ({ page }) => {
|
|
await page.goto('/admin/moderation');
|
|
|
|
await expect(page.getByText('Căn hộ cần duyệt')).toBeVisible({ timeout: 10000 });
|
|
await expect(page.getByText('Nhà phố cần duyệt')).toBeVisible();
|
|
});
|
|
|
|
test('displays AI moderation scores', async ({ page }) => {
|
|
await page.goto('/admin/moderation');
|
|
|
|
await expect(page.getByText('Căn hộ cần duyệt')).toBeVisible({ timeout: 10000 });
|
|
await expect(page.getByText('85')).toBeVisible();
|
|
await expect(page.getByText('42')).toBeVisible();
|
|
});
|
|
|
|
test('shows seller names', async ({ page }) => {
|
|
await page.goto('/admin/moderation');
|
|
|
|
await expect(page.getByText('Nguyen Van A')).toBeVisible({ timeout: 10000 });
|
|
await expect(page.getByText('Tran Thi B')).toBeVisible();
|
|
});
|
|
|
|
test('has refresh button', async ({ page }) => {
|
|
await page.goto('/admin/moderation');
|
|
|
|
const refreshButton = page.getByRole('button').filter({ has: page.locator('svg') }).first();
|
|
await expect(refreshButton).toBeVisible({ timeout: 10000 });
|
|
});
|
|
|
|
test('handles empty moderation queue', async ({ page }) => {
|
|
await page.route('**/api/v1/admin/moderation**', (route) =>
|
|
route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ data: [], total: 0, page: 1, limit: 20, totalPages: 0 }),
|
|
}),
|
|
);
|
|
|
|
await page.goto('/admin/moderation');
|
|
await page.waitForTimeout(2000);
|
|
await expect(page.locator('body')).toBeVisible();
|
|
});
|
|
});
|