Deploy Canina / deploy (push) Successful in 2m10s
- SEO-P1-07: extract FAQs and accordion items from blog content and inject JSON-LD FAQPage schema - SEO-P1-10: add dynamic sub-sitemaps /sitemap-blog.xml and /sitemap-wiki.xml and register in robots.ts - SEO-P2-16: host Lalezar font locally as optimized WOFF2 with preload enabled in lib/fonts.ts - Add full regression test suites with 100% pass rate
65 lines
3.4 KiB
TypeScript
65 lines
3.4 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { extractFaqsFromHtml, generateFAQPageSchema } from '../extractFaqs';
|
|
|
|
describe('extractFaqsFromHtml and generateFAQPageSchema (SEO-P1-07)', () => {
|
|
it('extracts FAQs from HTML5 details and summary tags', () => {
|
|
const html = `
|
|
<article>
|
|
<h1>مراقبت از مفاصل سگ</h1>
|
|
<details>
|
|
<summary>آیا این مکمل برای سگ نژاد بزرگ مناسب است؟</summary>
|
|
<p>بله، دوز مشخص بر اساس وزن روی بستهبندی درج شده است.</p>
|
|
</details>
|
|
<details>
|
|
<summary>مدت دوره درمان چقدر است؟</summary>
|
|
حداقل ۴ الی ۶ هفته مصرف مداوم توصیه میشود.
|
|
</details>
|
|
</article>
|
|
`;
|
|
const faqs = extractFaqsFromHtml(html);
|
|
expect(faqs).toHaveLength(2);
|
|
expect(faqs[0].question).toBe('آیا این مکمل برای سگ نژاد بزرگ مناسب است؟');
|
|
expect(faqs[0].answer).toBe('بله، دوز مشخص بر اساس وزن روی بستهبندی درج شده است.');
|
|
expect(faqs[1].question).toBe('مدت دوره درمان چقدر است؟');
|
|
expect(faqs[1].answer).toBe('حداقل ۴ الی ۶ هفته مصرف مداوم توصیه میشود.');
|
|
|
|
const schema = generateFAQPageSchema(faqs);
|
|
expect(schema).not.toBeNull();
|
|
expect(schema?.['@type']).toBe('FAQPage');
|
|
expect(schema?.mainEntity).toHaveLength(2);
|
|
expect(schema?.mainEntity[0].name).toBe('آیا این مکمل برای سگ نژاد بزرگ مناسب است؟');
|
|
expect(schema?.mainEntity[0].acceptedAnswer.text).toBe('بله، دوز مشخص بر اساس وزن روی بستهبندی درج شده است.');
|
|
});
|
|
|
|
it('extracts FAQs from accordion or FAQ class structures', () => {
|
|
const html = `
|
|
<div class="faq-item">
|
|
<h4 class="accordion-title">چگونه اصالت محصول را بررسی کنیم؟</h4>
|
|
<div class="accordion-content">با اسکن کد QR و استعلام شماره بچ در سایت شرکت کنینا.</div>
|
|
</div>
|
|
`;
|
|
const faqs = extractFaqsFromHtml(html);
|
|
expect(faqs).toHaveLength(1);
|
|
expect(faqs[0].question).toBe('چگونه اصالت محصول را بررسی کنیم؟');
|
|
expect(faqs[0].answer).toBe('با اسکن کد QR و استعلام شماره بچ در سایت شرکت کنینا.');
|
|
});
|
|
|
|
it('extracts FAQs from heading questions followed by paragraph answers', () => {
|
|
const html = `
|
|
<h2>پرسش: آیا کنینا محصولات ساخت آلمان هستند؟</h2>
|
|
<p>تمامی محصولات در کشور آلمان تحت استانداردهای دارویی اروپا تولید و بستهبندی میشوند.</p>
|
|
`;
|
|
const faqs = extractFaqsFromHtml(html);
|
|
expect(faqs).toHaveLength(1);
|
|
expect(faqs[0].question).toBe('پرسش: آیا کنینا محصولات ساخت آلمان هستند؟');
|
|
expect(faqs[0].answer).toContain('تمامی محصولات در کشور آلمان');
|
|
});
|
|
|
|
it('returns empty array and null schema when no FAQs are found', () => {
|
|
const html = `<p>یک مقاله بدون هرگونه بخش پرسش و پاسخ.</p>`;
|
|
const faqs = extractFaqsFromHtml(html);
|
|
expect(faqs).toHaveLength(0);
|
|
expect(generateFAQPageSchema(faqs)).toBeNull();
|
|
});
|
|
});
|