Public Access
Show the stat groups on /stats, the pile trend on the dashboard card, one switch per group in the settings, and the shared groups on the public profile.
78 lines
2.9 KiB
React
78 lines
2.9 KiB
React
// @vitest-environment jsdom
|
|
import {afterEach, describe, expect, it, vi} from 'vitest';
|
|
import {cleanup, fireEvent, render, screen} from '@testing-library/react';
|
|
import {MemoryRouter} from 'react-router-dom';
|
|
import PileOfShameCard from './PileOfShameCard.jsx';
|
|
|
|
vi.mock('react-i18next', () => import('../test/i18n-mock.js'));
|
|
|
|
const summary = (backlog, extra = {}) => ({
|
|
total: backlog + 3,
|
|
neverPlayed: 1,
|
|
byStatus: {BACKLOG: backlog, PLAYING: 3, FINISHED: 0, COMPLETED: 0, DROPPED: 0},
|
|
suggestion: backlog > 0 ? {appid: 220, name: 'Half-Life 2'} : null,
|
|
...extra,
|
|
});
|
|
|
|
const renderCard = (props) => render(<MemoryRouter><PileOfShameCard onShuffle={() => {}} {...props}/></MemoryRouter>);
|
|
|
|
describe('PileOfShameCard', () => {
|
|
afterEach(cleanup);
|
|
|
|
it('shows the first-sync text instead of empty numbers while the first sync runs', () => {
|
|
renderCard({summary: {...summary(0), total: 0, byStatus: {BACKLOG: 0}}, syncing: true});
|
|
|
|
expect(screen.getByText('LIBRARY.SYNCING_FIRST_TIME')).toBeTruthy();
|
|
expect(screen.queryByText('DASHBOARD.BACKLOG_EMPTY')).toBeNull();
|
|
});
|
|
|
|
it('hides the shuffle button when there is nothing else to pick', () => {
|
|
renderCard({summary: summary(1)});
|
|
|
|
expect(screen.getByText('Half-Life 2')).toBeTruthy();
|
|
expect(screen.queryByRole('button', {name: /DASHBOARD.OTHER_SUGGESTION/})).toBeNull();
|
|
});
|
|
|
|
it('shuffles when the backlog has more than one game', () => {
|
|
const onShuffle = vi.fn();
|
|
renderCard({summary: summary(2), onShuffle});
|
|
|
|
fireEvent.click(screen.getByRole('button', {name: /DASHBOARD.OTHER_SUGGESTION/}));
|
|
|
|
expect(onShuffle).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it('shows the pile trend and the moves of this month once they are loaded', () => {
|
|
const trend = {days: [{day: '2026-09-26', backlogGames: 3}, {day: '2026-09-27', backlogGames: 2}],
|
|
thisMonth: {added: 1, done: 2}};
|
|
renderCard({summary: summary(2), trend});
|
|
|
|
expect(screen.getByText('STATS.TREND.THIS_MONTH')).toBeTruthy();
|
|
expect(screen.getByTestId('pile-trend')).toBeTruthy();
|
|
});
|
|
|
|
it('shows no trend while it is not loaded', () => {
|
|
renderCard({summary: summary(2)});
|
|
|
|
expect(screen.queryByText('STATS.TREND.THIS_MONTH')).toBeNull();
|
|
});
|
|
|
|
it('says the backlog is empty when there is no suggestion', () => {
|
|
renderCard({summary: summary(0)});
|
|
|
|
expect(screen.getByText('DASHBOARD.BACKLOG_EMPTY')).toBeTruthy();
|
|
});
|
|
|
|
it('shows the backlog hours when IGDB knows some', () => {
|
|
renderCard({summary: summary(2, {backlogMinutes: 7440})});
|
|
|
|
expect(screen.getByText('DASHBOARD.BACKLOG_HOURS')).toBeTruthy();
|
|
});
|
|
|
|
it('hides the backlog hours without data', () => {
|
|
renderCard({summary: summary(2, {backlogMinutes: 0})});
|
|
|
|
expect(screen.queryByText('DASHBOARD.BACKLOG_HOURS')).toBeNull();
|
|
});
|
|
});
|