qazaq-legacy-foundation-web/src/components/contact-form-consent.test.ts

54 lines
2.8 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 { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { getDict } from '@/i18n'
import { ContactForm } from './ContactForm'
import { PrivacyNote } from './PrivacyNote'
vi.mock('@/app/actions/inquiry', () => ({ submitInquiry: async () => ({ status: 'idle' }) }))
const render = (l: 'ru' | 'kk' | 'en', privacyLink: boolean) =>
renderToStaticMarkup(createElement(ContactForm, { t: getDict(l), locale: l, email: 'a@example.com', privacyLink }))
describe('Сценарий: фраза согласия в форме', () => {
it.each(['ru', 'kk', 'en'] as const)('язык %s: политики нет — без упоминания и ссылки', (l) => {
const html = render(l, false)
expect(html).toContain(getDict(l).form.consent)
expect(html).not.toContain('/privacy')
expect(html).not.toMatch(/политик|саясат|policy/i)
})
it.each(['ru', 'kk', 'en'] as const)('язык %s: политика есть — ссылка на неё', (l) => {
const html = render(l, true)
expect(html).toContain(`href="/${l}/privacy"`)
expect(html).toContain(getDict(l).form.consentPolicyLink)
})
})
const visibleText = (html: string) => html.replace(/<[^>]*>/g, '')
describe('QLFW-38: согласие на казахском', () => {
it('Политика опубликована: согласие от первого лица со ссылкой', () => {
const html = render('kk', true)
const label = html.match(/<label[^>]*><input[^>]*name="consent"[\s\S]*?<\/label>/)?.[0]
expect(label).toBeDefined()
expect(visibleText(label!)).toBe('Жеке деректерімді өңдеуге құпиялылық саясатына сәйкес келісемін.')
expect(label).toContain('href="/kk/privacy"')
expect(label).not.toContain('келісесіз')
})
it('Политика отсутствует: согласие от первого лица без ссылки', () => {
const html = render('kk', false)
expect(visibleText(html)).toContain('Жеке деректерімді өңдеуге келісемін.')
expect(html).not.toContain('/privacy')
})
it.each([
['kk', 'Өтінішті жіберу арқылы сіз құпиялылық саясатымен келісесіз.'],
['ru', 'Отправляя обращение, вы соглашаетесь с политикой конфиденциальности.'],
] as const)('Подпись об отправке сохранена на языке %s', (locale, expected) => {
const html = renderToStaticMarkup(createElement(PrivacyNote, { t: getDict(locale), locale }))
expect(visibleText(html)).toBe(expected)
expect(html).toContain(`href="/${locale}/privacy"`)
})
})