test(e2e): refactor 6 e2e suites with strict assertions, add mutation verification and update test coverage map

This commit is contained in:
parsa aghaei committed 2026-08-25 15:19:22 +03:30
1 parent 3c325c412c
commit 6ef293ea59
28 files changed
+20676 -16743

No files matched your search

+23 -14
View File
@@ -1,7 +1,7 @@
import { test, expect } from '../../fixtures';
test.describe('سناریوی مدیریت درخواست‌های B2B و فرم‌های تماس (Admin B2B Submissions Flow)', () => {
test('ورود به بخش B2B -> مشاهده درخواست‌ها -> فیلتر و بررسی جزئیات', async ({ page }) => {
test('ورود به بخش B2B -> راستی‌آزمایی حضور درخواست‌ها -> تعویض تب و فیلترها', async ({ page }) => {
// Intercept and mock Admin Auth & B2B API calls
await page.route('**/api/auth/admin-login*', async (route) => {
await route.fulfill({
@@ -42,7 +42,7 @@ test.describe('سناریوی مدیریت درخواست‌های B2B و فرم
});
});
await page.route('**/api/admin/b2b-applications*', async (route) => {
await page.route('**/api/b2b/inquiries*', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
@@ -65,22 +65,31 @@ test.describe('سناریوی مدیریت درخواست‌های B2B و فرم
// 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);
}
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');
// 2. ورود به صفحه مدیریت درخواست‌های B2B
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();
// 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();
});
});
+27 -22
View File
@@ -1,7 +1,7 @@
import { test, expect } from '../../fixtures';
test.describe('سناریوی مدیریت مقالات و وبلاگ در پنل ادمین (Admin Blogs & CMS Flow)', () => {
test('ورود به بخش مقالات -> باز کردن فرم ایجاد -> پر کردن عنوان و محتوا -> ذخیره', async ({ page }) => {
test('ورود به بخش مقالات -> باز کردن فرم ایجاد -> پر کردن عنوان و ذخیره نهایی', async ({ page }) => {
// Intercept and mock Admin Auth & Blogs API calls
await page.route('**/api/auth/admin-login*', async (route) => {
await route.fulfill({
@@ -52,7 +52,7 @@ test.describe('سناریوی مدیریت مقالات و وبلاگ در پن
data: [
{
id: 'blog-1',
titleFa: 'راهنمای جامع سلامت مفاصل سگ و گربه',
title: 'راهنمای جامع سلامت مفاصل سگ و گربه',
slug: 'dog-joint-health-guide',
status: 'PUBLISHED',
views: 1250,
@@ -65,38 +65,43 @@ test.describe('سناریوی مدیریت مقالات و وبلاگ در پن
await route.fulfill({
status: 201,
contentType: 'application/json',
body: JSON.stringify({ success: true, message: 'مقاله با موفقیت ایجاد شد' }),
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);
}
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('/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 });
// 3. راستی‌آزمایی حضور هدر و دکمه مقاله جدید
const blogsHeading = page.locator('h2').filter({ hasText: 'مدیریت جامع وبلاگ' });
await expect(blogsHeading).toBeVisible({ timeout: 15000 });
const newBlogBtn = page.getByRole('button', { name: 'مقاله جدید' });
await expect(newBlogBtn).toBeVisible();
await newBlogBtn.click();
// 4. بررسی فرم ایجاد مقاله
const blogTitleInput = page.locator('input[placeholder*="عنوان"], input[name*="title"]').first();
if (await blogTitleInput.isVisible()) {
await blogTitleInput.fill('مقاله آموزشی تستی تست‌های سرتاسری Playwright');
}
// 4. راستی‌آزمایی باز شدن فرم ایجاد و پر کردن عنوان
const blogTitleInput = page.locator('input[placeholder*="عنوان"]').first();
await expect(blogTitleInput).toBeVisible({ timeout: 10000 });
await blogTitleInput.fill('مقاله آموزشی تستی پلی‌رایت');
// 5. ذخیره فرم و راستی‌آزمایی پیام موفقیت یا فراخوانی موفقیت‌آمیز
const saveBlogBtn = page.getByRole('button', { name: /ذخیره|ثبت|انتشار/i }).first();
await expect(saveBlogBtn).toBeVisible();
await saveBlogBtn.click();
});
});
+21 -21
View File
@@ -1,7 +1,7 @@
import { test, expect } from '../../fixtures';
test.describe('سناریوی مدیریت سفارشات و تغییر وضعیت در پنل ادمین (Admin Orders Management)', () => {
test('ورود به بخش سفارشات -> فیلتر وضعیت -> مشاهده جزئیات فاکتور', async ({ page }) => {
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({
@@ -55,9 +55,9 @@ test.describe('سناریوی مدیریت سفارشات و تغییر وضعی
customerName: 'علی رضایی',
customerPhone: '09121112233',
totalAmount: 1850000,
status: 'PROCESSING',
status: 'processing',
createdAt: new Date().toISOString(),
items: [{ id: 'item-1', productName: 'مکمل مفاصل سگ', quantity: 2, price: 925000 }],
items: [{ id: 'item-1', name: 'مکمل مفاصل سگ', quantity: 2, priceValue: 925000 }],
},
],
meta: { total: 1, lastPage: 1 },
@@ -67,28 +67,28 @@ test.describe('سناریوی مدیریت سفارشات و تغییر وضعی
// 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);
}
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 ordersHeader = page.locator('h1, h2, div').filter({ hasText: /سفارشات|مدیریت سفارش/i }).first();
await expect(ordersHeader).toBeVisible({ timeout: 15000 });
// 3. راستی‌آزمایی دقیق تیتر مدیریت سفارشات
const ordersHeading = page.locator('h2').filter({ hasText: 'مدیریت سفارشات' });
await expect(ordersHeading).toBeVisible({ timeout: 15000 });
// 4. تست فیلترهای وضعیت سفارش (در حال پردازش، ارسال شده، تکمیل شده)
const statusFilter = page.locator('select, button').filter({ hasText: /وضعیت|همه|پردازش/i }).first();
if (await statusFilter.isVisible()) {
await statusFilter.click();
}
// 4. راستی‌آزمایی دراپ‌داون فیلتر وضعیت و انتخاب وضعیت جدید
const statusSelect = page.locator('select').first();
await expect(statusSelect).toBeVisible();
await statusSelect.selectOption({ label: 'در حال پردازش' });
await expect(page).toHaveURL(/status=/);
});
});
+22 -23
View File
@@ -1,36 +1,35 @@
import { test, expect } from '../../fixtures';
test.describe('سناریوی عملیات پیشرفته سبد خرید (Cart Drawer Interactive Operations)', () => {
test('افزودن کالا به سبد -> افزایش و کاهش تعداد -> حذف کالا -> بررسی حالت خالی', async ({ page }) => {
// 1. ورود به فروشگاه
test.describe('سناریوی عملیات پیشرفته سبد خرید (Cart Operations & State Synchronization)', () => {
test('ورود به صفحه محصول -> افزودن مستقیم به سبد خرید -> راستی‌آزمایی در تسویه‌حساب', async ({ page, isMobile }) => {
// 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);
const productCard = page.locator('a[href^="/shop/"]').first();
await expect(productCard).toBeVisible({ timeout: 20000 });
// 3. تست افزایش تعداد با دکمه +
const plusButton = page.locator('button').filter({ hasText: '+' }).first();
if (await plusButton.isVisible()) {
await plusButton.click();
await page.waitForTimeout(300);
const productHref = await productCard.getAttribute('href');
expect(productHref).toBeTruthy();
await page.goto(productHref!, { waitUntil: 'domcontentloaded' });
// 2. کلیک روی دکمه «افزودن به سبد» متناسب با دسکتاپ یا موبایل
if (isMobile) {
const mobileAddBtn = page.locator('div.fixed.bottom-0 button').filter({ hasText: /افزودن به سبد/i }).first();
await expect(mobileAddBtn).toBeVisible({ timeout: 15000 });
await mobileAddBtn.click();
} else {
const desktopAddBtn = page.locator('button').filter({ hasText: /افزودن به سبد خرید/i }).first();
await expect(desktopAddBtn).toBeVisible({ timeout: 15000 });
await desktopAddBtn.click();
}
// 4. تست کاهش تعداد با دکمه -
const minusButton = page.locator('button').filter({ hasText: '-' }).first();
if (await minusButton.isVisible()) {
await minusButton.click();
await page.waitForTimeout(300);
}
// 5. باز کردن دراور یا صفحه تسویه‌حساب
// 3. رفتن به صفحه تسویه‌حساب و راستی‌آزمایی حضور کالا و دکمه پرداخت
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 });
const submitOrderBtn = page.getByRole('button', { name: /پرداخت و تکمیل سفارش/i });
await expect(submitOrderBtn).toBeVisible({ timeout: 15000 });
});
});
+46 -14
View File
@@ -1,31 +1,63 @@
import { test, expect } from '../../fixtures';
test.describe('سناریوی پیگیری سفارشات (Order Tracking Flow & Edge Cases)', () => {
test('ورود به صفحه پیگیری -> استعلام کد نامعتبر (Edge Case) -> استعلام سفارش معتبر', async ({ page }) => {
test('استعلام کد رهگیری نامعتبر -> راستی‌آزمایی پیام خطا -> ثبت و استعلام سفارش معتبر', 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 });
// 2. راستی‌آزمایی وجود المان‌های ورودی و دکمه استعلام
const trackingInput = page.locator('input[placeholder*="شماره سفارش"]');
await expect(trackingInput).toBeVisible({ timeout: 20000 });
const trackBtn = page.getByRole('button', { name: /رهگیری|پیگیری|استعلام/i }).or(
page.locator('button').filter({ hasText: /رهگیری|پیگیری/i })
).first();
const trackBtn = page.getByRole('button', { name: 'رهگیری آنی' });
await expect(trackBtn).toBeVisible();
// 3. تست Edge Case: ورود کد پیگیری نامعتبر
// 3. تست منفی (Negative Test): استعلام کد رهگیری نامعتبر/ساختگی
await trackingInput.fill('INVALID-TRACK-99999');
await trackBtn.click();
await page.waitForTimeout(500);
// 4. تست ورود کد رهگیری ساختگی یا بررسی ساختار تایم‌لاین وضعیت
await trackingInput.fill('CN-10001');
// راستی‌آزمایی پیام صریح خطای عدم یافت سفارش (نه فقط پاس شدن بدون بررسی)
const notFoundMessage = page.locator('p').filter({ hasText: 'سفارشی یافت نشد. لطفاً شماره سفارش صحیح را وارد کنید.' });
await expect(notFoundMessage).toBeVisible({ timeout: 10000 });
// 4. تزریق یک سفارش به استیت لوکال zustand (کلید canina-cart)
await page.evaluate(() => {
const mockOrder = {
id: 'CN-88888',
trackingNumber: 'IR-POST-88888',
date: new Date().toISOString(),
items: [{ product: { id: 'p1', name: 'مکمل کلسیم و مفاصل سگ Canina' }, quantity: 2 }],
total: 1500000,
status: 'processing',
};
const cartState = {
state: {
items: [],
orders: [mockOrder],
isOpen: false,
isSubscribed: false,
charityDonation: 0,
coupon: null,
},
version: 0,
};
localStorage.setItem('canina-cart', JSON.stringify(cartState));
});
// بارگذاری مجدد صفحه برای لود سفارش تزریق شده در zustand
await page.reload({ waitUntil: 'domcontentloaded' });
// 5. استعلام شماره سفارش معتبر و بررسی تایم‌لاین و محتویات فاکتور
await trackingInput.fill('CN-88888');
await trackBtn.click();
// 5. بررسی تایم‌لاین مراحل تحویل (ثبت سفارش، آماده‌سازی، ارسال)
const timelineStep = page.locator('div, h4, span').filter({ hasText: /ثبت سفارش|آماده‌سازی|تحویل|وضعیت/i }).first();
await expect(timelineStep).toBeVisible({ timeout: 10000 });
// راستی‌آزمایی تایم‌لاین مراحل
await expect(page.locator('h4').filter({ hasText: 'ثبت سفارش' })).toBeVisible({ timeout: 10000 });
await expect(page.locator('h4').filter({ hasText: 'آماده‌سازی در انبار' })).toBeVisible();
// راستی‌آزمایی محتویات اقلام فاکتور و کد مرسوله
await expect(page.locator('p').filter({ hasText: 'IR-POST-88888' })).toBeVisible();
await expect(page.locator('span').filter({ hasText: 'مکمل کلسیم و مفاصل سگ Canina' })).toBeVisible();
});
});
+17 -36
View File
@@ -1,48 +1,29 @@
import { test, expect } from '../../fixtures';
test.describe('سناریوی جستجو، فیلترها و مرتب‌سازی در فروشگاه (Shop Filter, Search & Edge Cases)', () => {
test('جستجوی محصول، فیلتر بر اساس علائم و دسته‌ها، و مدیریت حالت بدون نتیجه', async ({ page }) => {
// 1. ورود به صفحه فروشگاه
test('جستجوی محصول -> فیلتر علائم و دسته‌ها -> راستی‌آزمایی وضعیت خالی بدون فالبک', async ({ page }) => {
// 1. ورود به صفحه فروشگاه و راستی‌آزمایی URL
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);
// 2. راستی‌آزمایی اجباری وجود کارت‌های اولیه کاتالوگ
const productCard = page.locator('a[href^="/shop/"]').first();
await expect(productCard).toBeVisible({ timeout: 20000 });
// پاک کردن و جستجوی عبارت ناموجود برای تست Edge Case (بدون نتیجه)
await searchInput.fill('عبارت_ناموجود_تستی_۱۲۳۴۵۶');
await page.waitForTimeout(500);
// 3. جستجوی عبارت ناموجود از طریق URL query parameter
await page.goto('/shop?search=%D8%B9%D8%A8%D8%A7%D8%B1%D8%AA_%D9%86%D8%A7%D9%85%D9%88%D8%AC%D9%88%D8%AF_99999', { waitUntil: 'domcontentloaded' });
// بررسی وضعیت خالی / عدم یافت محصول یا پاک کردن فیلتر
const clearSearchOrEmpty = page.locator('text=یافت نشد').or(
page.locator('button').filter({ hasText: /پاک کردن|نمایش همه/i })
).or(searchInput);
await expect(clearSearchOrEmpty.first()).toBeVisible();
// راستی‌آزمایی پیام صریح عدم یافت محصول
const emptyStateHeading = page.locator('h3').filter({ hasText: 'محصولی یافت نشد!' });
await expect(emptyStateHeading).toBeVisible({ timeout: 15000 });
// بازگردانی جستجو به حالت عادی
await searchInput.fill('');
}
// 4. بازگشت به صفحه اصلی فروشگاه و راستی‌آزمایی بارگذاری مجدد کاتالوگ
await page.goto('/shop', { waitUntil: 'domcontentloaded' });
await expect(productCard).toBeVisible({ timeout: 15000 });
// 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 });
// 5. تست فیلتر دسته‌بندی و راستی‌آزمایی تغییر URL به دسته‌بندی جدید
await page.goto('/shop?category=joints', { waitUntil: 'domcontentloaded' });
await expect(page).toHaveURL(/category=joints/);
await expect(productCard).toBeVisible({ timeout: 10000 });
});
});