canina/tests/e2e/admin/admin-b2b-submissions.spec.ts

96 lines
3.6 KiB
TypeScript

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',
clinicName: 'کلینیک تخصصی دامپزشکی پایتخت',
managerName: 'دکتر محمدی',
phone: '09123334455',
status: 'PENDING',
createdAt: new Date().toISOString(),
},
],
meta: { total: 1, lastPage: 1 },
}),
});
});
// 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 });
// 4. راستی‌آزمایی تب‌های درخواست‌ها و همکاران
const partnerTab = page.getByRole('button', { name: /حساب‌های تاییدشده همکار/i });
await expect(partnerTab).toBeVisible();
await partnerTab.click();
const inquiriesTab = page.getByRole('button', { name: /درخواست‌های دریافت نمایندگی/i });
await expect(inquiriesTab).toBeVisible();
await inquiriesTab.click();
});
});