import { test, expect } from '../../fixtures'; test.describe('سناریوی مدیریت درخواست‌های B2B و فرم‌های تماس (Admin B2B Submissions Flow)', () => { test('ورود به بخش B2B -> راستی‌آزمایی حضور درخواست‌ها -> تعویض تب و فیلترها', async ({ page }) => { // Intercept and mock Admin Auth & B2B 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/b2b/inquiries*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: [ { id: 'b2b-1', companyName: 'کلینیک تخصصی دامپزشکی پایتخت', contactName: 'دکتر محمدی', phone: '09123334455', email: 'clinic@paytakht.ir', businessType: 'کلینیک دامپزشکی', message: 'درخواست خرید عمده مکمل‌های مفاصل کنینا', status: 'PENDING', createdAt: new Date().toISOString(), }, ], meta: { total: 1, lastPage: 1 }, }), }); }); await page.route('**/api/b2b/partners*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, data: [ { id: 'partner-1', companyName: 'پت شاپ مرکزی ارکیده', userId: 'usr-901', taxId: '1400889922', creditLimit: 50000000, discountTier: 'طلایی (۲۵٪)', status: 'ACTIVE', }, ], }), }); }); // 1. لاگین ادمین await page.goto('/login', { waitUntil: 'domcontentloaded' }); const emailInput = page.locator('input[type="email"]'); const passwordInput = page.locator('input[type="password"]'); await expect(emailInput).toBeVisible({ timeout: 10000 }); 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. ورود به صفحه مدیریت B2B await page.goto('/b2b', { waitUntil: 'domcontentloaded' }); await expect(page).toHaveURL(/\/b2b/); // 3. راستی‌آزمایی تیتر اختصاصی مدیریت B2B و درخواست متناظر const b2bHeader = page.locator('h2').filter({ hasText: 'مدیریت همکاران عمده‌فروشی و B2B' }); await expect(b2bHeader).toBeVisible({ timeout: 15000 }); await expect(page.locator('span').filter({ hasText: 'کلینیک تخصصی دامپزشکی پایتخت' }).first()).toBeVisible({ timeout: 10000 }); // 4. سوئیچ به تب حساب‌های تاییدشده همکار const partnerTab = page.locator('[data-testid="b2b-partners-tab"]').first(); await expect(partnerTab).toBeVisible(); await partnerTab.click(); // راستی‌آزمایی دقیق رندر شدن جدول حساب‌های همکار const partnerRowText = page.locator('td').filter({ hasText: 'پت شاپ مرکزی ارکیده' }).first(); await expect(partnerRowText).toBeVisible({ timeout: 10000 }); // 5. سوئیچ مجدد به تب درخواست‌ها const inquiriesTab = page.locator('[data-testid="b2b-inquiries-tab"]').first(); await expect(inquiriesTab).toBeVisible(); await inquiriesTab.click(); await expect(page.locator('span').filter({ hasText: 'کلینیک تخصصی دامپزشکی پایتخت' }).first()).toBeVisible({ timeout: 10000 }); }); test('راستی‌آزمایی رندر امن و عدم اجرای پیلود XSS در پنل ادمین (Admin Safe XSS Rendering)', async ({ page }) => { let adminDialogFired = false; page.on('dialog', () => { adminDialogFired = true; }); const xssSenderName = ' دکتر تست'; const xssMessageBody = ' متن پیام تستی با پیلود مخرب'; 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/contact/submissions*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ success: true, items: [ { id: 'contact-xss-1', name: xssSenderName, phone: '09121112233', subject: 'تست امنیت XSS در ادمین', message: xssMessageBody, status: 'PENDING', createdAt: new Date().toISOString(), }, ], }), }); }); await page.route('**/api/contact/info*', async (route) => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify([]), }); }); // 1. لاگین ادمین await page.goto('/login', { waitUntil: 'domcontentloaded' }); const emailInput = page.locator('input[type="email"]'); const passwordInput = page.locator('input[type="password"]'); await expect(emailInput).toBeVisible({ timeout: 10000 }); 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('/contact', { waitUntil: 'domcontentloaded' }); await expect(page).toHaveURL(/\/contact/); // 3. راستی‌آزمایی رندر امن نام فرستنده به عنوان متن خام در جدول const senderCell = page.locator('td').filter({ hasText: xssSenderName }).first(); await expect(senderCell).toBeVisible({ timeout: 15000 }); // 4. باز کردن جزئیات پیام و راستی‌آزمایی نمایش متن پیام const detailsBtn = page.getByRole('button', { name: /مشاهده و پاسخ|مشاهده/i }).first(); await expect(detailsBtn).toBeVisible({ timeout: 10000 }); await detailsBtn.click(); // 5. راستی‌آزمایی قطعی عدم اجرای آلرت جاوااسکریپتی در پنل ادمین expect(adminDialogFired).toBe(false); }); });