import { test, expect } from '../../fixtures'; test.describe('سناریوی مدیریت مقالات و وبلاگ در پنل ادمین (Admin Blogs & CMS Flow)', () => { test('ورود به بخش مقالات -> باز کردن فرم ایجاد -> پر کردن عنوان و محتوا -> ذخیره', async ({ page }) => { // Intercept and mock Admin Auth & Blogs API calls await page.route('**/api/auth/admin-login*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: { accessToken: 'mock_e2e_admin_jwt_token', user: { id: 'admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN' }, }, }), }); }); await page.route('**/api/auth/refresh*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: { accessToken: 'mock_e2e_admin_jwt_token', user: { id: 'admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN' }, }, }), }); }); await page.route('**/api/users/profile*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: { id: 'admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN' }, }), }); }); await page.route('**/api/admin/blogs*', async (route) => { if (route.request().method() === 'GET') { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: [ { id: 'blog-1', titleFa: 'راهنمای جامع سلامت مفاصل سگ و گربه', slug: 'dog-joint-health-guide', status: 'PUBLISHED', views: 1250, }, ], meta: { total: 1, lastPage: 1 }, }), }); } else { await route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify({ success: true, message: 'مقاله با موفقیت ایجاد شد' }), }); } }); // 1. لاگین ادمین await page.goto('/login', { waitUntil: 'domcontentloaded' }); const emailInput = page.locator('input[type="email"], input[placeholder*="ایمیل"]').first(); const passwordInput = page.locator('input[type="password"], input[placeholder*="رمز"]').first(); if (await emailInput.isVisible()) { await emailInput.fill('admin@canina.ir'); await passwordInput.fill('Admin@123456'); const submitBtn = page.getByRole('button', { name: /ورود به پنل|ورود/i }).first(); await submitBtn.click(); await page.waitForTimeout(500); } // 2. ورود به صفحه مدیریت مقالات وبلاگ await page.goto('/blogs', { waitUntil: 'domcontentloaded' }); await expect(page).toHaveURL(/\/blogs/); // 3. بررسی دکمه ایجاد مقاله جدید const newBlogBtn = page.getByRole('button', { name: /مقاله جدید|افزودن مقاله|پست جدید/i }).or( page.locator('button').filter({ hasText: /جدید|افزودن/i }) ).first(); await expect(newBlogBtn).toBeVisible({ timeout: 15000 }); await newBlogBtn.click(); // 4. بررسی فرم ایجاد مقاله const blogTitleInput = page.locator('input[placeholder*="عنوان"], input[name*="title"]').first(); if (await blogTitleInput.isVisible()) { await blogTitleInput.fill('مقاله آموزشی تستی تست‌های سرتاسری Playwright'); } }); });