import { test, expect } from '@playwright/test'; import { TEST_URLS } from '../fixtures/test-data'; /** * Admin Audit Log Page Tests * ใช้ cookies จาก admin-setup project (ไม่ต้อง login ซ้ำ) */ test.describe('Admin Audit Log', () => { test.beforeEach(async ({ page }) => { await page.goto(TEST_URLS.adminAuditLog); await page.waitForLoadState('networkidle'); }); test('check display page', async ({ page }) => { // Header await expect(page.getByText('Audit Logs', { exact: true })).toBeVisible(); await expect(page.getByText('ประวัติการใช้งานระบบและกิจกรรมต่างๆ')).toBeVisible(); // Stats cards await expect(page.getByText('Logs ทั้งหมด')).toBeVisible(); await expect(page.getByText('Logs วันนี้')).toBeVisible(); await expect(page.getByRole('button', { name: 'รีเฟรช' })).toBeVisible(); await expect(page.getByRole('button', { name: 'ล้างประวัติเก่า' })).toBeVisible(); }); test('should refresh data when clicking refresh button', async ({ page }) => { const refreshBtn = page.getByRole('button', { name: 'รีเฟรช' }); await refreshBtn.click(); await page.waitForLoadState('networkidle'); // Table should still be visible after refresh await expect(page.locator('.q-table')).toBeVisible(); }); test('should filter by Action', async ({ page }) => { // Click the Action select const actionSelect = page.locator('label').filter({ hasText: 'Action' }); await actionSelect.click(); await page.waitForTimeout(300); // Select an option from dropdown const option = page.locator('.q-item__label').filter({ hasText: 'LOGIN' }).first(); await option.click(); // Click search await page.getByRole('button', { name: 'ค้นหา' }).click(); await page.waitForLoadState('networkidle'); // Table should be visible await expect(page.locator('.q-table')).toBeVisible(); await page.getByRole('button', { name: 'ล้างตัวกรอง' }).click(); await page.waitForLoadState('networkidle'); // Entity type input should be cleared await expect(option).not.toBeVisible(); }); test('check open details dialog', async ({ page }) => { // Wait for table data to load const viewBtn = page.locator('.q-table .q-btn').filter({ has: page.locator('.q-icon') }).first(); const hasData = await viewBtn.isVisible().catch(() => false); if (hasData) { await viewBtn.click(); await page.waitForTimeout(300); // Details dialog should be visible await expect(page.getByText('รายละเอียด Audit Log')).toBeVisible(); // Close button await page.getByRole('button', { name: 'ปิด' }).click(); } }); test('check close cleanup dialog on cancel', async ({ page }) => { await page.getByRole('button', { name: 'ล้างประวัติเก่า' }).click(); await page.waitForTimeout(300); await expect(page.locator('.q-dialog')).toBeVisible(); // Click cancel await page.getByRole('button', { name: 'ยกเลิก' }).click(); await expect(page.locator('.q-dialog')).not.toBeVisible(); }); test('check close cleanup dialog on confirm', async ({ page }) => { await page.getByRole('button', { name: 'ล้างประวัติเก่า' }).click(); await page.waitForTimeout(300); await expect(page.locator('.q-dialog')).toBeVisible(); // Click confirm await page.getByRole('button', { name: 'ลบข้อมูล', exact: true }).click(); await expect(page.locator('.q-dialog')).not.toBeVisible(); }); });