qazaq-legacy-foundation-web/src/components/contact-email-fallback.test.ts

26 lines
1.1 KiB
TypeScript

import { createElement } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it } from 'vitest'
import { getDict } from '@/i18n'
import { ContactEmailFallback } from './ContactEmailFallback'
describe('Запасная почта', () => {
for (const locale of ['ru', 'kk', 'en'] as const) {
const render = (email: string) => renderToStaticMarkup(createElement(ContactEmailFallback, { text: getDict(locale).form.fallback, email }))
it(`Почта видна: ${locale}`, () => {
const html = render('qazaqlegacy@gmail.com')
expect(html).toContain(getDict(locale).form.fallback)
expect(html).toContain('<!--email_off--><a href="mailto:qazaqlegacy@gmail.com"')
expect(html).toContain('>qazaqlegacy@gmail.com</a><!--/email_off-->')
expect(html).not.toContain('[email protected]')
})
it(`Адрес отсутствует: ${locale}`, () => {
expect(render('')).toBe('')
expect(render(' ')).toBe('')
})
it(`Адрес экранируется: ${locale}`, () => {
expect(render('<script>alert(1)</script>')).not.toContain('<script>')
})
}
})