feat(game): play confetti for finished games

This commit is contained in:
lobo committed 2026-09-28 13:36:36 +02:00
1 parent 09e1f767d8
commit a5458b3f86
9 files changed
+260 -9

No files matched your search

+32
View File
@@ -282,3 +282,35 @@ describe('GameDetail of a game added by hand', () => {
});
});
});
describe('GameDetail confetti', () => {
// jsdom has no canvas drawing.
beforeEach(() => {
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue(null);
});
afterEach(() => {
vi.restoreAllMocks();
});
const opened = async (entry) => {
globalThis.fetch = vi.fn(async () => ({ok: true, status: 200, json: async () => ({...game, ...entry})}));
const {container} = renderDetail();
await screen.findByText('Half-Life 2');
return container.querySelector('canvas[data-size]');
};
it('plays a small one for a finished game', async () => {
expect((await opened({status: 'FINISHED'})).dataset.size).toBe('small');
});
it('plays a big one when every achievement is unlocked too', async () => {
const canvas = await opened({status: 'COMPLETED', hasAchievements: true, statsVisible: true,
achievementsTotal: 3, achievementsUnlocked: 3});
expect(canvas.dataset.size).toBe('big');
});
it('plays nothing for a game not finished', async () => {
expect(await opened({status: 'PLAYING'})).toBeNull();
});
});