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

100 lines
4.0 KiB
TypeScript

import { test, expect } from '../../fixtures';
test.describe('سناریوی مدیریت و فیلتر سفارشات در پنل ادمین (Admin Orders Flow & Exact Value Assertion)', () => {
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-12345',
trackingNumber: 'CN-88990',
totalAmount: 1850000,
status: 'shipped',
paymentMethod: 'ONLINE',
createdAt: new Date().toISOString(),
user: { firstName: 'علی', lastName: 'رضایی', phone: '09121112233' },
items: [{ id: 'item-1', name: 'مکمل مفاصل سگ', quantity: 2, priceValue: 925000 }],
},
],
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. ورود به صفحه مدیریت سفارشات
await page.goto('/orders', { waitUntil: 'domcontentloaded' });
await expect(page).toHaveURL(/\/orders/);
// 3. راستی‌آزمایی دقیق تیتر مدیریت سفارشات
const ordersHeading = page.locator('h2').filter({ hasText: 'مدیریت سفارشات' });
await expect(ordersHeading).toBeVisible({ timeout: 15000 });
// 4. راستی‌آزمایی مقدار دقیق متنی فیلد وضعیت سفارش در سطر جدول (ارسال شده)
const orderStatusSelect = page.locator('[data-testid="order-status-select"]').first();
await expect(orderStatusSelect).toBeVisible({ timeout: 10000 });
await expect(orderStatusSelect).toHaveValue('shipped');
// 5. راستی‌آزمایی دراپ‌داون فیلتر وضعیت در بالای صفحه و انتخاب وضعیت جدید
const topFilterSelect = page.locator('select').first();
await expect(topFilterSelect).toBeVisible();
await topFilterSelect.selectOption({ label: 'ارسال شده' });
await expect(page).toHaveURL(/status=/);
});
});