69 lines
3.4 KiB
TypeScript
69 lines
3.4 KiB
TypeScript
import { test, expect } from '../../fixtures';
|
|
|
|
test.describe('سناریوی همکاری تجاری B2B (B2B Portal Flow)', () => {
|
|
test('ورود به /b2b -> بررسی تیتر H1 و متنهای ارزش پیشنهادی -> ارسال فرم با اعتبارسنجی', async ({ page }) => {
|
|
// 1. ورود به /b2b
|
|
await page.goto('/b2b');
|
|
await expect(page).toHaveURL(/\/b2b/);
|
|
|
|
// 2. بررسی وجود تیتر H1
|
|
const heading = page.locator('h1');
|
|
await expect(heading).toBeVisible();
|
|
await expect(heading).toContainText(/تأمین عمده|همکاری تجاری|کنینا/i);
|
|
|
|
// بررسی متنهای ارزش پیشنهادی (ارسال فاکتور رسمی، تخفیف، گواهی اصالت)
|
|
const valueProps = page.locator('section, div').filter({ hasText: /تخفیف|کلینیک|دامپزشکی|گواهی اصالت/i });
|
|
await expect(valueProps.first()).toBeVisible();
|
|
|
|
// 3. ارسال فرم با دادههای خالی و بررسی نمایش خطاهای اعتبارسنجی
|
|
const submitButton = page.getByRole('button', { name: /ارسال درخواست|ثبت درخواست|درخواست همکاری/i }).first();
|
|
await expect(submitButton).toBeVisible();
|
|
|
|
// ارسال بدون وارد کردن فیلدها
|
|
await submitButton.click();
|
|
|
|
// بررسی پیام خطا یا اعتبارسنجی (toast یا متن ارور)
|
|
const toastError = page.locator('[data-sonner-toast], .toast, [role="alert"]').or(
|
|
page.getByText(/لطفاً نام مجموعه و شماره تماس را وارد کنید|الزامی است/i)
|
|
).first();
|
|
await expect(toastError).toBeVisible({ timeout: 5000 });
|
|
|
|
// 4. ارسال فرم با دادههای معتبر (Mock کردن درخواست API برای جلوگیری از دیتای هرز)
|
|
await page.route('**/api/wholesale/apply', async (route) => {
|
|
await route.fulfill({
|
|
status: 201,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ success: true, message: 'درخواست همکاری با موفقیت ثبت شد' }),
|
|
});
|
|
});
|
|
|
|
// پر کردن فیلدهای فرم
|
|
const businessNameInput = page.locator('input[placeholder*="نام کلینیک"], input[placeholder*="مجموعه"]').first();
|
|
const contactNameInput = page.locator('input[placeholder*="نام و نام خانوادگی"], input[placeholder*="رابط"]').first();
|
|
const phoneInput = page.locator('input[placeholder*="۰۹"], input[placeholder*="تماس"]').first();
|
|
const cityInput = page.locator('input[placeholder*="شهر"]').first();
|
|
|
|
if (await businessNameInput.isVisible()) {
|
|
await businessNameInput.fill('پت شاپ آزمایشی پایتخت');
|
|
}
|
|
if (await contactNameInput.isVisible()) {
|
|
await contactNameInput.fill('دکتر حسینی');
|
|
}
|
|
if (await phoneInput.isVisible()) {
|
|
await phoneInput.fill('09121112233');
|
|
}
|
|
if (await cityInput.isVisible()) {
|
|
await cityInput.fill('تهران');
|
|
}
|
|
|
|
// ارسال مجدد با دادههای پر شده
|
|
await submitButton.click();
|
|
|
|
// 5. بررسی دریافت پیام موفقیتآمیز
|
|
const successFeedback = page.locator('[data-sonner-toast], [role="alert"]').or(
|
|
page.getByText(/با موفقیت ثبت شد|درخواست شما ثبت شد/i)
|
|
).first();
|
|
await expect(successFeedback).toBeVisible({ timeout: 7000 });
|
|
});
|
|
});
|