test(e2e): expand Playwright test coverage with shop filters, tracking, cart operations and admin modules
This commit is contained in:
1 parent
270e491d08
commit
3c325c412c
9 files changed
+493
No files matched your search
@@ -0,0 +1,86 @@
|
||||
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/admin/b2b-applications*', 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"], 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. ورود به صفحه مدیریت درخواستهای B2B
|
||||
await page.goto('/b2b', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/b2b/);
|
||||
|
||||
// 3. بررسی ساختار لودینگ صفحه یا جدول اطلاعات
|
||||
const b2bHeader = page.locator('h1, h2, h3, div').filter({ hasText: /درخواست|B2B|همکاری|کلینیک|پتشاپ/i }).first();
|
||||
await expect(b2bHeader).toBeVisible({ timeout: 15000 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,102 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی مدیریت مقالات و وبلاگ در پنل ادمین (Admin Blogs & CMS Flow)', () => {
|
||||
test('ورود به بخش مقالات -> باز کردن فرم ایجاد -> پر کردن عنوان و محتوا -> ذخیره', async ({ page }) => {
|
||||
// Intercept and mock Admin Auth & Blogs 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/blogs*', async (route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
id: 'blog-1',
|
||||
titleFa: 'راهنمای جامع سلامت مفاصل سگ و گربه',
|
||||
slug: 'dog-joint-health-guide',
|
||||
status: 'PUBLISHED',
|
||||
views: 1250,
|
||||
},
|
||||
],
|
||||
meta: { total: 1, lastPage: 1 },
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.fulfill({
|
||||
status: 201,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ success: true, message: 'مقاله با موفقیت ایجاد شد' }),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 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('/blogs', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/blogs/);
|
||||
|
||||
// 3. بررسی دکمه ایجاد مقاله جدید
|
||||
const newBlogBtn = page.getByRole('button', { name: /مقاله جدید|افزودن مقاله|پست جدید/i }).or(
|
||||
page.locator('button').filter({ hasText: /جدید|افزودن/i })
|
||||
).first();
|
||||
await expect(newBlogBtn).toBeVisible({ timeout: 15000 });
|
||||
await newBlogBtn.click();
|
||||
|
||||
// 4. بررسی فرم ایجاد مقاله
|
||||
const blogTitleInput = page.locator('input[placeholder*="عنوان"], input[name*="title"]').first();
|
||||
if (await blogTitleInput.isVisible()) {
|
||||
await blogTitleInput.fill('مقاله آموزشی تستی تستهای سرتاسری Playwright');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
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();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی عملیات پیشرفته سبد خرید (Cart Drawer Interactive Operations)', () => {
|
||||
test('افزودن کالا به سبد -> افزایش و کاهش تعداد -> حذف کالا -> بررسی حالت خالی', async ({ page }) => {
|
||||
// 1. ورود به فروشگاه
|
||||
await page.goto('/shop', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/shop/);
|
||||
|
||||
// 2. افزودن محصول به سبد خرید
|
||||
const buyButton = page.locator('button').filter({ hasText: /خرید|افزودن به سبد/i }).first();
|
||||
await expect(buyButton).toBeVisible({ timeout: 15000 });
|
||||
await buyButton.click();
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// 3. تست افزایش تعداد با دکمه +
|
||||
const plusButton = page.locator('button').filter({ hasText: '+' }).first();
|
||||
if (await plusButton.isVisible()) {
|
||||
await plusButton.click();
|
||||
await page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
// 4. تست کاهش تعداد با دکمه -
|
||||
const minusButton = page.locator('button').filter({ hasText: '-' }).first();
|
||||
if (await minusButton.isVisible()) {
|
||||
await minusButton.click();
|
||||
await page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
// 5. باز کردن دراور یا صفحه تسویهحساب
|
||||
await page.goto('/checkout', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/checkout/);
|
||||
|
||||
const checkoutSummary = page.locator('button, div, h2, span').filter({ hasText: /پرداخت|فاکتور|سبد خرید|مجموع/i }).first();
|
||||
await expect(checkoutSummary).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
@@ -24,6 +24,7 @@ test.describe('سناریوی خرید و سبد خرید (Storefront Checkout F
|
||||
const buyButtonOnCard = page.locator('button').filter({ hasText: /خرید/i }).first();
|
||||
if (await buyButtonOnCard.isVisible()) {
|
||||
await buyButtonOnCard.click();
|
||||
await page.waitForTimeout(1000);
|
||||
} else {
|
||||
const href = await productCard.getAttribute('href');
|
||||
if (href) {
|
||||
@@ -38,6 +39,7 @@ test.describe('سناریوی خرید و سبد خرید (Storefront Checkout F
|
||||
).first();
|
||||
await expect(addToCartBtn).toBeVisible({ timeout: 15000 });
|
||||
await addToCartBtn.click();
|
||||
await page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
// 5. رفتن به صفحه تسویه حساب (Checkout)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی پیگیری سفارشات (Order Tracking Flow & Edge Cases)', () => {
|
||||
test('ورود به صفحه پیگیری -> استعلام کد نامعتبر (Edge Case) -> استعلام سفارش معتبر', async ({ page }) => {
|
||||
// 1. ورود به صفحه /track
|
||||
await page.goto('/track', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/track/);
|
||||
|
||||
// 2. بررسی وجود المانهای پیگیری و فیلد ورودی
|
||||
const trackingInput = page.locator('input[placeholder*="شماره سفارش"], input[placeholder*="کد رهگیری"]').first();
|
||||
await expect(trackingInput).toBeVisible({ timeout: 15000 });
|
||||
|
||||
const trackBtn = page.getByRole('button', { name: /رهگیری|پیگیری|استعلام/i }).or(
|
||||
page.locator('button').filter({ hasText: /رهگیری|پیگیری/i })
|
||||
).first();
|
||||
await expect(trackBtn).toBeVisible();
|
||||
|
||||
// 3. تست Edge Case: ورود کد پیگیری نامعتبر
|
||||
await trackingInput.fill('INVALID-TRACK-99999');
|
||||
await trackBtn.click();
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// 4. تست ورود کد رهگیری ساختگی یا بررسی ساختار تایملاین وضعیت
|
||||
await trackingInput.fill('CN-10001');
|
||||
await trackBtn.click();
|
||||
|
||||
// 5. بررسی تایملاین مراحل تحویل (ثبت سفارش، آمادهسازی، ارسال)
|
||||
const timelineStep = page.locator('div, h4, span').filter({ hasText: /ثبت سفارش|آمادهسازی|تحویل|وضعیت/i }).first();
|
||||
await expect(timelineStep).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی جستجو، فیلترها و مرتبسازی در فروشگاه (Shop Filter, Search & Edge Cases)', () => {
|
||||
test('جستجوی محصول، فیلتر بر اساس علائم و دستهها، و مدیریت حالت بدون نتیجه', async ({ page }) => {
|
||||
// 1. ورود به صفحه فروشگاه
|
||||
await page.goto('/shop', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/shop/);
|
||||
|
||||
// 2. تست باکس جستجو
|
||||
const searchInput = page.locator('input[placeholder*="جستجو"], input[type="search"]').first();
|
||||
if (await searchInput.isVisible()) {
|
||||
// جستجوی یک کلمه کلیدی موجود
|
||||
await searchInput.fill('مفاصل');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// پاک کردن و جستجوی عبارت ناموجود برای تست Edge Case (بدون نتیجه)
|
||||
await searchInput.fill('عبارت_ناموجود_تستی_۱۲۳۴۵۶');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// بررسی وضعیت خالی / عدم یافت محصول یا پاک کردن فیلتر
|
||||
const clearSearchOrEmpty = page.locator('text=یافت نشد').or(
|
||||
page.locator('button').filter({ hasText: /پاک کردن|نمایش همه/i })
|
||||
).or(searchInput);
|
||||
await expect(clearSearchOrEmpty.first()).toBeVisible();
|
||||
|
||||
// بازگردانی جستجو به حالت عادی
|
||||
await searchInput.fill('');
|
||||
}
|
||||
|
||||
// 3. تست دکمههای فیلتر دستهبندی
|
||||
const categoryTabs = page.locator('button, a').filter({ hasText: /مفاصل|مکمل|پت|ویتامین/i }).first();
|
||||
if (await categoryTabs.isVisible()) {
|
||||
await categoryTabs.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
// 4. تست کلیک روی تگ علائم یا اندیکاسیون (Symptom Badges)
|
||||
const symptomBadge = page.locator('a[href*="symptom="], button[data-symptom]').first();
|
||||
if (await symptomBadge.isVisible()) {
|
||||
await symptomBadge.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
// 5. بررسی نمایش حداقل یک کارت محصول یا ساختار گرید کاتالوگ
|
||||
const productGrid = page.locator('a[href^="/shop/"], div[data-product-card]').first();
|
||||
await expect(productGrid).toBeVisible({ timeout: 15000 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user