elearning/frontend_management/tests/admin/recommended-courses.spec.ts

68 lines
2.8 KiB
TypeScript
Raw Normal View History

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();
// Close dialog via close button in q-bar
await page.locator('.q-bar .q-btn').filter({ has: page.locator('[class*="q-icon"]') }).click();
await page.waitForTimeout(300);
await expect(page.getByText('รายละเอียดคอร์ส (Course Details)')).not.toBeVisible();
}
});
});