canina/tests/e2e/admin/admin-orders-flow.spec.ts

95 lines
3.6 KiB
TypeScript

import { test, expect } from '../../fixtures';
test.describe('سناریوی مدیریت سفارشات و تغییر وضعیت در پنل ادمین (Admin Orders Management)', () => {
test('ورود به بخش سفارشات -> فیلتر وضعیت -> مشاهده جزئیات فاکتور', async ({ page }) => {
// Intercept and mock Admin Auth & Orders 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/orders*', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
success: true,
data: [
{
id: 'ord-101',
orderNumber: 'CN-10001',
customerName: 'علی رضایی',
customerPhone: '09121112233',
totalAmount: 1850000,
status: 'PROCESSING',
createdAt: new Date().toISOString(),
items: [{ id: 'item-1', productName: 'مکمل مفاصل سگ', quantity: 2, price: 925000 }],
},
],
meta: { total: 1, lastPage: 1 },
}),
});
});
// 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('/orders', { waitUntil: 'domcontentloaded' });
await expect(page).toHaveURL(/\/orders/);
// 3. بررسی تیتر صفحه و لیست سفارشات
const ordersHeader = page.locator('h1, h2, div').filter({ hasText: /سفارشات|مدیریت سفارش/i }).first();
await expect(ordersHeader).toBeVisible({ timeout: 15000 });
// 4. تست فیلترهای وضعیت سفارش (در حال پردازش، ارسال شده، تکمیل شده)
const statusFilter = page.locator('select, button').filter({ hasText: /وضعیت|همه|پردازش/i }).first();
if (await statusFilter.isVisible()) {
await statusFilter.click();
}
});
});