Public Access
50 lines
1.5 KiB
React
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();
|
|
});
|
|
});
|