canina/tests/e2e/storefront/blog-wiki.spec.ts

46 lines
2.1 KiB
TypeScript

import { test, expect } from '../../fixtures';
test.describe('سناریوی وبلاگ و دانشنامه (Blog & Wiki Flow)', () => {
test('ورود به /blog -> باز کردن مقاله -> بررسی اجزا -> رفتن به /wiki/[slug] و تست لینک‌ها', async ({ page }) => {
// 1. ورود به روت /blog
await page.goto('/blog');
await expect(page).toHaveURL(/\/blog/);
const blogHeading = page.locator('h1, h2').filter({ hasText: /مقالات|مجله|وبلاگ|سلامت/i }).first();
await expect(blogHeading).toBeVisible({ timeout: 10000 });
// 2. کلیک روی اولین مقاله در لیست
const firstArticleLink = page.locator('a[href^="/blog/"]').filter({ hasNotText: 'وبلاگ' }).first();
if (await firstArticleLink.isVisible()) {
await firstArticleLink.click();
// 3. بررسی لود صفحه جزئیات مقاله
await expect(page).toHaveURL(/\/blog\/.+/);
const articleHeading = page.locator('h1').first();
await expect(articleHeading).toBeVisible();
// بررسی وجود بخش‌های محتوایی یا سرفصل‌ها
const contentSection = page.locator('article, .prose, main').first();
await expect(contentSection).toBeVisible();
}
// 4. رفتن به دانشنامه /wiki
// ابتدا روت wiki را باز می‌کنیم
await page.goto('/wiki/glucosamine');
// اگر اصطلاح پیدا نشود یا نام دیگری داشته باشد، چک می‌کنیم صفحه خطای 500 نداده باشد
const wikiHeading = page.locator('h1, h2').first();
await expect(wikiHeading).toBeVisible();
// 5. بررسی وجود لینک مکمل‌ها یا محصولات مرتبط با ماده
const relatedProducts = page.locator('a[href^="/shop/"]').or(
page.locator('text=مکمل‌های حاوی').or(page.locator('text=محصولات مرتبط'))
);
if (await relatedProducts.count() > 0) {
await expect(relatedProducts.first()).toBeVisible();
}
});
});