// The FAQPage node of a FAQ block (D-43): one Question per item with the // answer as plain text, @id #faq. import { test } from 'node:test' import assert from 'node:assert/strict' import { faqAnswerText, faqSchema } from '../app/utils/faqSchema.ts' const FAQ = { name: 'Acme questions', slug: 'acme', locale: 'en', description: '

About Acme.

', content: [ { question: 'How long does shipping take?', answer: '

Two days.

' }, { question: 'Can I return it?', answer: '

Yes & free of charge <30 days>.

' }, ], } test('faqSchema: a FAQPage with a Question and acceptedAnswer per item', () => { assert.deepEqual(faqSchema(FAQ, 'https://acme.test/help'), { '@type': 'FAQPage', '@id': 'https://acme.test/help#faq', url: 'https://acme.test/help', mainEntity: [ { '@type': 'Question', name: 'How long does shipping take?', acceptedAnswer: { '@type': 'Answer', text: 'Two days. Poland Europe' } }, { '@type': 'Question', name: 'Can I return it?', acceptedAnswer: { '@type': 'Answer', text: 'Yes & free of charge <30 days>.' } }, ], }) }) test('faqSchema: no FAQ, no items or blank questions give null or skip the item', () => { assert.equal(faqSchema(null, 'https://acme.test/'), null) assert.equal(faqSchema({ ...FAQ, content: [] }, 'https://acme.test/'), null) const node = faqSchema({ ...FAQ, content: [{ question: ' ', answer: '

x

' }, { question: 'Q', answer: '' }] }, 'https://acme.test/x#top') assert.equal(node?.['@id'], 'https://acme.test/x#faq') assert.deepEqual(node?.mainEntity, [{ '@type': 'Question', name: 'Q', acceptedAnswer: { '@type': 'Answer', text: '' } }]) }) test('faqAnswerText: markup stripped, entities decoded, scripts and styles dropped, whitespace collapsed', () => { assert.equal(faqAnswerText('

a

\n

b
c

'), 'a b c') assert.equal(faqAnswerText('

ok

'), 'ok') assert.equal(faqAnswerText('"x" 'y' A B'), '"x" \'y\' A B') assert.equal(faqAnswerText(null), '') })