qazaq-legacy-foundation-web/src/lib/news-model.test.ts
Peppa 0a330feb89
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 3с
peppa/test test: success за 1с
peppa/build build: success за 42с
ci / checks (pull_request) Successful in 1m14s
deploy / deploy (pull_request) Successful in 2m2s
QLFW-51: «События и новости» только с датой, фото и текстом; контакты с партнёрством
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 19:07:55 +05:00

21 lines
1.6 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 { describe, it, expect } from 'vitest'
import { visibleNews, safeWebUrl } from './news-model'
describe('Материалы новостей', () => {
it('Материал опубликован: сохраняет дату и полный текст', () => {
const item = { id: 1, title: 'Презентация книги', date: '2026-11-17', body: 'Полный текст', imageUrl: 'https://example.org/a.jpg' }
expect(visibleNews([item])).toEqual([item])
})
it('Нет перевода: скрывает материал без заголовка текущего языка', () => {
expect(visibleNews([{ id: 1, title: '', date: '2026-11-17' }])).toEqual([])
})
it('Нет фото или текста: материал скрыт', () => {
expect(visibleNews([{ id: 1, title: 'Н', date: '2026-11-17', body: 'Текст' }])).toEqual([])
expect(visibleNews([{ id: 1, title: 'Н', date: '2026-11-17', imageUrl: 'https://example.org/a.jpg' }])).toEqual([])
})
it('Пустой раздел остаётся пустым', () => expect(visibleNews([])).toEqual([]))
it('Повреждённая дата не ломает страницу', () => expect(visibleNews([{ id: 1, title: 'Новость', date: 'bad' }])).toEqual([]))
it.each(['javascript:alert(1)', 'data:text/html,test', '/relative', 'https://user:password@example.org'])('Небезопасная ссылка %s скрыта', value => expect(safeWebUrl(value)).toBeNull())
it('Источник открывает обычную веб-страницу', () => expect(safeWebUrl('https://example.org/article')).toBe('https://example.org/article'))
})