QLFW-44: тесты ссылок на магазины
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 3с
peppa/test test: success за 1с
peppa/build build: success за 43с
ci / checks (pull_request) Successful in 1m15s
deploy / deploy (pull_request) Successful in 1m58s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Peppa 2026-11-17 18:38:02 +05:00
parent 78f995a0b1
commit 1a21531c17

View File

@ -2,28 +2,33 @@ import { createElement } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it } from 'vitest'
import { getDict } from '@/i18n'
import { bookUrl, marwinUrl } from '@/lib/home-model'
import { BookWhere } from './BookWhere'
const render = (l: 'ru' | 'kk' | 'en') => {
const d = getDict(l)
return renderToStaticMarkup(createElement(BookWhere, { t: d.book, tbc: d.tbc }))
}
const link = (href: string, name: string) =>
`<a href="${href.replace(/&/g, '&amp;')}" target="_blank" rel="noopener noreferrer" class="underline">${name}</a>`
describe('Сценарий: где купить книгу', () => {
it('русский текст целиком, площадки списком без ссылок', () => {
const html = render('ru')
expect(html).toContain('Где купить книгу')
expect(html).toContain('можно приобрести онлайн на платформах:')
expect(html).toContain('<li>Marwin</li><li>Flip.kz</li>')
expect(html).toContain('<p class="mt-3 text-muted">Наличие и стоимость книги уточняйте непосредственно у продавцов.</p>')
expect(html).not.toContain('<a')
})
it.each(['kk', 'en'] as const)('язык %s: те же магазины, без пометок', (l) => {
it.each(['ru', 'kk', 'en'] as const)('язык %s: Marwin и Flip.kz — ссылки в новой вкладке, без пометок', (l) => {
const html = render(l)
expect(html).toContain('<li>Marwin</li><li>Flip.kz</li>')
expect(html).toContain(link(marwinUrl, 'Marwin'))
expect(html).toContain(link(bookUrl, 'Flip.kz'))
expect(html).toContain('Эрудит')
expect(html).toContain('Книжный мир')
expect(html).not.toContain(getDict(l).tbc)
expect(html).not.toContain('<a')
})
it('русский текст: подпись и фраза про наличие на месте', () => {
const html = render('ru')
expect(html).toContain('Где купить книгу')
expect(html).toContain('Наличие и стоимость книги уточняйте непосредственно у продавцов.')
})
it('без адреса магазина ссылка не показывается, название остаётся', () => {
const d = getDict('ru')
const html = renderToStaticMarkup(createElement(BookWhere, { t: { ...d.book, buy: { ...d.book.buy!, platforms: ['Неизвестный'] } } }))
expect(html).toContain('<li>Неизвестный</li>')
})
})