test(e2e): setup Playwright testing infrastructure and comprehensive storefront & admin suites
This commit is contained in:
1 parent
7b89e141c5
commit
270e491d08
11 files changed
+643
-4
No files matched your search
@@ -0,0 +1,160 @@
|
||||
import { test, expect } from '../../fixtures';
|
||||
|
||||
test.describe('سناریوی مدیریت محصول در پنل ادمین (Admin Products CRUD & SEO)', () => {
|
||||
test('ورود به بخش محصولات -> باز کردن فرم ایجاد -> پر کردن فیلدها و سئو -> ذخیره', async ({ page }) => {
|
||||
// Intercept and mock Admin Auth & Product 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_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_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/products*', async (route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
id: 'prod-1',
|
||||
artNo: 'ART-001',
|
||||
nameFa: 'مکمل کلسیم و مفاصل سگ',
|
||||
category: { id: 'cat-1', nameFa: 'مفاصل' },
|
||||
priceValue: 450000,
|
||||
stockStatus: 'IN_STOCK',
|
||||
},
|
||||
],
|
||||
meta: { total: 1, lastPage: 1 },
|
||||
}),
|
||||
});
|
||||
} else if (route.request().method() === 'POST') {
|
||||
await route.fulfill({
|
||||
status: 201,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: { id: 'pw-mock-id', nameFa: 'محصول تستی پلیرایت', artNo: 'PW-TEST-001' },
|
||||
message: 'محصول با موفقیت ایجاد شد',
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
await page.route('**/api/admin/categories*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: [{ id: 'cat-1', nameFa: 'مفاصل و استخوان' }],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/orders/stats*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ success: true, data: { pending: 0, processing: 0 } }),
|
||||
});
|
||||
});
|
||||
|
||||
// 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('/products', { waitUntil: 'domcontentloaded' });
|
||||
|
||||
// 2. بررسی لود شدن ساختار صفحه مدیریت محصولات یا دکمه ایجاد محصول
|
||||
const addProductBtn = page.getByRole('button', { name: /محصول جدید/i }).or(
|
||||
page.locator('button').filter({ hasText: /محصول جدید/i })
|
||||
).first();
|
||||
await expect(addProductBtn).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// 3. کلیک روی دکمه افزودن محصول جدید
|
||||
await addProductBtn.click();
|
||||
|
||||
// 4. بررسی باز شدن مودال فرم ایجاد محصول
|
||||
const modalTitle = page.locator('h2, h3, div').filter({ hasText: /محصول جدید|افزودن محصول|اطلاعات پایه/i }).first();
|
||||
await expect(modalTitle).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// 5. پر کردن اطلاعات پایه محصول
|
||||
const nameFaInput = page.locator('input[placeholder*="نام فارسی"], input[name*="nameFa"]').or(
|
||||
page.locator('input[type="text"]').first()
|
||||
).first();
|
||||
if (await nameFaInput.isVisible()) {
|
||||
await nameFaInput.fill('محصول تستی پلیرایت برای بررسی سئو');
|
||||
}
|
||||
|
||||
// 6. سوئیچ به تب یا بخش تنظیمات سئو (SEO)
|
||||
const seoTab = page.locator('button, div').filter({ hasText: /سئو|SEO/i }).first();
|
||||
if (await seoTab.isVisible()) {
|
||||
await seoTab.click();
|
||||
|
||||
// پر کردن فیلدهای سئو
|
||||
const metaTitleInput = page.locator('input[placeholder*="عنوان سئو"], input[name*="metaTitle"]').first();
|
||||
const metaDescInput = page.locator('textarea[placeholder*="توضیحات سئو"], textarea[name*="metaDescription"]').first();
|
||||
|
||||
if (await metaTitleInput.isVisible()) {
|
||||
await metaTitleInput.fill('خرید آنلاین محصول تستی با بهترین قیمت | کنینا ایران');
|
||||
}
|
||||
if (await metaDescInput.isVisible()) {
|
||||
await metaDescInput.fill('توضیحات متای تستی برای ارزیابی رندرینگ پیشنمایش SERP گوگل در پنل مدیریت پروژه کنینا.');
|
||||
}
|
||||
}
|
||||
|
||||
// 7. کلیک روی دکمه ذخیره / ثبت
|
||||
const saveBtn = page.getByRole('button', { name: /ذخیره|ثبت نهایی|ایجاد محصول/i }).or(
|
||||
page.locator('button').filter({ hasText: /ذخیره|ثبت/i })
|
||||
).first();
|
||||
if (await saveBtn.isVisible()) {
|
||||
await saveBtn.click();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user