qazaq-legacy-foundation-web/src/lib/news-model.test.ts
Peppa 1a58c2a4d9
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 2с
peppa/test test: success за 1с
peppa/build build: success за 41с
ci / checks (pull_request) Successful in 1m22s
deploy / deploy (pull_request) Successful in 17s
QLFW-6: панель управления: проекты, фото, контакты и текст «О фонде»
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 23:33:54 +05:00

32 lines
2.3 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, newsImage } 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'))
})
describe('Фото новости из панели', () => {
it('Загруженное фото важнее адреса и делает материал видимым', () => {
const item = { id: 1, title: 'Н', date: '2026-11-17', body: 'Текст', cover: { url: '/api/media/file/a.jpg' }, imageUrl: 'javascript:x' }
expect(newsImage(item)).toBe('/api/media/file/a.jpg')
expect(visibleNews([item])).toEqual([item])
})
it('Без загруженного фото берётся безопасный адрес', () => {
expect(newsImage({ id: 1, title: 'Н', date: '2026-11-17', imageUrl: 'https://example.org/a.jpg' })).toBe('https://example.org/a.jpg')
})
})