|
| 1 | +import { render, screen } from '@testing-library/react' |
| 2 | +import CommerceAnnouncement from '@/themes/commerce/components/Announcement' |
| 3 | +import ExampleAnnouncement from '@/themes/example/components/Announcement' |
| 4 | +import FukasawaAnnouncement from '@/themes/fukasawa/components/Announcement' |
| 5 | +import FuwariAnnouncement from '@/themes/fuwari/components/Announcement' |
| 6 | +import HexoAnnouncement from '@/themes/hexo/components/Announcement' |
| 7 | +import MateryAnnouncement from '@/themes/matery/components/Announcement' |
| 8 | +import MovieAnnouncement from '@/themes/movie/components/Announcement' |
| 9 | +import NextAnnouncement from '@/themes/next/components/Announcement' |
| 10 | +import ThoughtliteAnnouncement from '@/themes/thoughtlite/components/Announcement' |
| 11 | +import XuhomeAnnouncement from '@/themes/xuhome/components/Announcement' |
| 12 | + |
| 13 | +jest.mock('@/lib/global', () => ({ |
| 14 | + useGlobal: () => ({ |
| 15 | + locale: { |
| 16 | + COMMON: { |
| 17 | + ANNOUNCEMENT: 'Announcement fallback' |
| 18 | + } |
| 19 | + } |
| 20 | + }) |
| 21 | +})) |
| 22 | + |
| 23 | +const notice = { |
| 24 | + title: 'Custom notice title', |
| 25 | + blockMap: { block: {} } |
| 26 | +} |
| 27 | + |
| 28 | +describe('announcement titles', () => { |
| 29 | + test.each([ |
| 30 | + ['commerce', CommerceAnnouncement, 'post'], |
| 31 | + ['example', ExampleAnnouncement, 'post'], |
| 32 | + ['fukasawa', FukasawaAnnouncement, 'post'], |
| 33 | + ['hexo', HexoAnnouncement, 'post'], |
| 34 | + ['matery', MateryAnnouncement, 'notice'], |
| 35 | + ['movie', MovieAnnouncement, 'post'], |
| 36 | + ['next', NextAnnouncement, 'post'], |
| 37 | + ['thoughtlite', ThoughtliteAnnouncement, 'post'], |
| 38 | + ['xuhome', XuhomeAnnouncement, 'post'] |
| 39 | + ])('%s uses the Notion Notice page title', (_name, Component, propName) => { |
| 40 | + render(<Component {...{ [propName]: notice }} />) |
| 41 | + |
| 42 | + expect(screen.getByText(/Custom notice title/)).toBeInTheDocument() |
| 43 | + }) |
| 44 | + |
| 45 | + it('fuwari prefers the Notion Notice page title over its fallback title prop', () => { |
| 46 | + render(<FuwariAnnouncement post={notice} title='Announcement fallback' />) |
| 47 | + |
| 48 | + expect(screen.getByText(/Custom notice title/)).toBeInTheDocument() |
| 49 | + expect(screen.queryByText('Announcement fallback')).not.toBeInTheDocument() |
| 50 | + }) |
| 51 | + |
| 52 | + it('keeps the localized fallback when the Notice page has no title', () => { |
| 53 | + render(<HexoAnnouncement post={{ blockMap: { block: {} } }} />) |
| 54 | + |
| 55 | + expect(screen.getByText('Announcement fallback')).toBeInTheDocument() |
| 56 | + }) |
| 57 | +}) |
0 commit comments