Files
ToBePlayed-Frontend/src/components/ComingBadge.test.jsx
T
lobo c158909083
Build, Test & Push Frontend / quality-check (push) Successful in 32s
Build, Test & Push Frontend / docker (push) Successful in 22s
feat(games): add coming badge for unreleased games
2026-10-05 20:33:25 +02:00

50 lines
1.5 KiB
React

// @vitest-environment jsdom
import {afterEach, describe, expect, it, vi} from 'vitest';
import {cleanup, render, screen} from '@testing-library/react';
import ComingBadge from './ComingBadge.jsx';
const i18n = vi.hoisted(() => ({language: 'en'}));
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key, options) => (options?.date ? `${key} ${options.date}` : key),
i18n,
}),
}));
describe('ComingBadge', () => {
afterEach(cleanup);
it('shows the release date in English', () => {
i18n.language = 'en';
render(<ComingBadge game={{coming: true, comingOn: '2026-12-04'}}/>);
expect(screen.getByText('LIBRARY.COMING Dec 4, 2026')).toBeTruthy();
});
it('shows the release date in German', () => {
i18n.language = 'de';
render(<ComingBadge game={{coming: true, comingOn: '2026-12-04'}}/>);
expect(screen.getByText('LIBRARY.COMING 04.12.2026')).toBeTruthy();
});
it('says "coming soon" when the date is unknown', () => {
render(<ComingBadge game={{coming: true, comingOn: null}}/>);
expect(screen.getByText('LIBRARY.COMING_SOON')).toBeTruthy();
});
it('shows nothing for a released game', () => {
const {container} = render(<ComingBadge game={{coming: false, comingOn: null}}/>);
expect(container.firstChild).toBeNull();
});
it('shows nothing when an older Core sends no field', () => {
const {container} = render(<ComingBadge game={{appid: 220}}/>);
expect(container.firstChild).toBeNull();
});
});