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 }); }); });