import { test, expect } from '@playwright/test'; import { TEST_URLS } from '../fixtures/test-data'; /** * Admin Recommended Courses Page Tests * ใช้ cookies จาก admin-setup project (ไม่ต้อง login ซ้ำ) */ test.describe('Admin Recommended Courses', () => { test.beforeEach(async ({ page }) => { await page.goto(TEST_URLS.adminRecommendedCourses); await page.waitForLoadState('networkidle'); }); test('check display page', async ({ page }) => { // Header await expect(page.getByText('จัดการคอร์สแนะนำ')).toBeVisible(); await expect(page.getByText('Recommended Courses Management')).toBeVisible(); const toggles = page.locator('.q-table .q-toggle'); const hasData = await toggles.first().isVisible().catch(() => false); if (hasData) { await expect(toggles.first()).toBeVisible(); } }); test('should toggle recommendation status', async ({ page }) => { const toggle = page.locator('.q-table .q-toggle').first(); const hasData = await toggle.isVisible().catch(() => false); if (hasData) { await toggle.click(); await page.waitForTimeout(500); // Should show notification (success or error) await expect(page.locator('.q-notification')).toBeVisible({ timeout: 10_000 }); await toggle.click(); await page.waitForTimeout(500); // Should show notification (success or error) await expect(page.locator('.q-notification').last()).toBeVisible({ timeout: 10_000 }); } }); test('open course details dialog', async ({ page }) => { 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(500); // Dialog should be visible with course details await expect(page.getByText('รายละเอียดคอร์ส (Course Details)')).toBeVisible(); // Detail sections await expect(page.getByText('รายละเอียด (Description)')).toBeVisible(); await expect(page.getByText('หมวดหมู่ (Category):')).toBeVisible(); await expect(page.getByText('ผู้สอน (Instructors)')).toBeVisible(); await page.waitForTimeout(1000); } }); });