qazaq-legacy-foundation-web/src/lib/legal-publication.test.ts

35 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createElement } from 'react'
import { describe, expect, it, vi } from 'vitest'
import { renderToStaticMarkup } from 'react-dom/server'
import { Footer } from '@/components/Footer'
import { LegalPage } from '@/components/LegalPage'
import { getDict, locales } from '@/i18n'
import { loadLegal } from './content'
vi.mock('./content', () => ({ loadContent: vi.fn().mockResolvedValue({ home: null, news: [] }), loadLegal: vi.fn() }))
vi.mock('next/navigation', () => ({ notFound: () => { throw new Error('mock-not-found') } }))
const mockLegal = { privacy: { body: '1. Общие положения\n\nТекст фонда', updated: '2026-11-17T00:00:00.000Z' } }
describe('Ссылки и прямые адреса юридических документов', () => {
it.each(locales)('Ссылки в подвале: %s, документы независимы', locale => {
const html = renderToStaticMarkup(createElement(Footer, { t: getDict(locale), locale, legal: mockLegal }))
expect(html).toContain(`/${locale}/privacy`)
expect(html).not.toContain(`/${locale}/terms`)
const empty = renderToStaticMarkup(createElement(Footer, { t: getDict(locale), locale, legal: null }))
expect(empty).not.toContain(`/${locale}/privacy`)
expect(empty).not.toContain(`/${locale}/terms`)
})
it.each(locales)('Документ ещё не предоставлен: %s', async locale => {
vi.mocked(loadLegal).mockResolvedValue(null)
await expect(LegalPage({ params: Promise.resolve({ locale }), kind: 'privacy' })).rejects.toThrow('mock-not-found')
})
it.each(locales)('Фонд добавил текст: %s', async locale => {
vi.mocked(loadLegal).mockResolvedValue(mockLegal)
const html = renderToStaticMarkup(await LegalPage({ params: Promise.resolve({ locale }), kind: 'privacy' }))
expect(html).toContain('Текст фонда')
expect(html).toContain(getDict(locale).legal.updated)
expect(html).toContain('dateTime="2026-11-17T00:00:00.000Z"')
expect(html).not.toContain(getDict(locale).tbc)
})
})