import { test, expect } from '@playwright/test'; import { TEST_URLS } from '../fixtures/test-data'; /** * Admin Pending Courses Page Tests * ใช้ cookies จาก admin-setup project (ไม่ต้อง login ซ้ำ) */ test.describe('Admin Pending Courses', () => { test.beforeEach(async ({ page }) => { await page.goto(TEST_URLS.adminPendingCourses); await page.waitForLoadState('networkidle'); }); test('should display stats cards', async ({ page }) => { await expect(page.getByText('รอตรวจสอบ')).toBeVisible(); await expect(page.getByText('บททั้งหมด')).toBeVisible(); await expect(page.getByText('บทเรียนทั้งหมด')).toBeVisible(); }); test('should search courses by keyword "พื้นฐาน"', async ({ page }) => { const searchInput = page.locator('input[placeholder*="ค้นหา"]'); await expect(searchInput).toBeVisible(); // ค้นหาคำว่า "พื้นฐาน" await searchInput.fill('พื้นฐาน'); await page.waitForTimeout(500); // ตรวจสอบว่าแสดงผลลัพธ์ที่ตรงกัน หรือแสดง empty state const emptyState = page.getByText('ไม่มีคอร์สที่รอการอนุมัติ'); const isEmpty = await emptyState.isVisible().catch(() => false); if (isEmpty) { await expect(emptyState).toBeVisible(); } else { // ถ้ามีผลลัพธ์ ชื่อคอร์สต้องมีคำว่า "พื้นฐาน" const courseCards = page.locator('.bg-white.rounded-xl.shadow-sm.overflow-hidden'); const count = await courseCards.count(); expect(count).toBeGreaterThan(0); for (let i = 0; i < count; i++) { await expect(courseCards.nth(i)).toContainText('พื้นฐาน'); } } }); test('should filter courses by search text', async ({ page }) => { const searchInput = page.locator('input[placeholder*="ค้นหา"]'); await searchInput.fill('nonexistent-course-xyz'); // Should show empty state or filtered results // Wait briefly for filter to apply await page.waitForTimeout(500); // Either shows "ไม่มีคอร์สที่รอการอนุมัติ" or filtered results const emptyState = page.getByText('ไม่มีคอร์สที่รอการอนุมัติ'); const courseCards = page.locator('.bg-white.rounded-xl.shadow-sm.overflow-hidden'); // One of these should be visible const isEmpty = await emptyState.isVisible().catch(() => false); if (isEmpty) { await expect(emptyState).toBeVisible(); } }); test('should toggle between card and table view', async ({ page }) => { // Find the view toggle buttons const toggleGroup = page.locator('.q-btn-toggle'); await expect(toggleGroup).toBeVisible(); // Click table view await page.locator('.q-btn-toggle button').last().click(); await page.waitForTimeout(300); // Table should be visible await expect(page.locator('.q-table')).toBeVisible(); // Switch back to card view await page.locator('.q-btn-toggle button').first().click(); await page.waitForTimeout(300); await page.locator('.q-btn-toggle button').last().click(); await page.waitForTimeout(300); // Table should have expected columns await expect(page.getByText('ชื่อคอร์ส')).toBeVisible(); await expect(page.getByText('ผู้สอน')).toBeVisible(); await expect(page.getByText('วันที่ส่ง')).toBeVisible(); }); test('should have refresh button', async ({ page }) => { const refreshBtn = page.getByRole('button', { name: /รีเฟรช/ }); await expect(refreshBtn).toBeVisible(); // Click refresh await refreshBtn.click(); // Should trigger loading (spinner appears briefly) await page.waitForLoadState('networkidle'); }); test('should navigate to course detail on click if ', async ({ page }) => { // Check if there are any courses const courseExists = await page.locator('.bg-white.rounded-xl').first().isVisible().catch(() => false); if (courseExists) { // Click "ดูรายละเอียด" button on first course const viewBtn = page.locator('.q-table button[class*="q-btn"]').first(); if (await viewBtn.isVisible()) { await viewBtn.click(); await page.waitForURL('**/admin/courses/**'); await expect(page).toHaveURL(/\/admin\/courses\/\d+/); await page.waitForTimeout(1000); } } }); });