|
| 1 | +import '@testing-library/jest-dom'; |
| 2 | +import { fireEvent, render, screen } from '@testing-library/react'; |
| 3 | +import { Round } from '@wca/helpers'; |
| 4 | +import { MemoryRouter } from 'react-router-dom'; |
| 5 | +import { CutoffTimeLimitPanel } from './CutoffTimeLimitPanel'; |
| 6 | + |
| 7 | +jest.mock('react-tiny-popover', () => ({ |
| 8 | + Popover: ({ |
| 9 | + children, |
| 10 | + content, |
| 11 | + isOpen, |
| 12 | + }: { |
| 13 | + children: React.ReactNode; |
| 14 | + content: React.ReactNode; |
| 15 | + isOpen: boolean; |
| 16 | + }) => ( |
| 17 | + <div> |
| 18 | + {children} |
| 19 | + {isOpen ? content : null} |
| 20 | + </div> |
| 21 | + ), |
| 22 | +})); |
| 23 | + |
| 24 | +jest.mock('react-i18next', () => ({ |
| 25 | + Trans: ({ i18nKey }: { i18nKey: string }) => i18nKey, |
| 26 | + useTranslation: () => ({ |
| 27 | + t: (key: string) => key, |
| 28 | + }), |
| 29 | +})); |
| 30 | + |
| 31 | +jest.mock('@/providers/WCIFProvider', () => ({ |
| 32 | + useWCIF: () => ({ |
| 33 | + competitionId: 'TestComp2026', |
| 34 | + wcif: { |
| 35 | + id: 'TestComp2026', |
| 36 | + schedule: { venues: [] }, |
| 37 | + }, |
| 38 | + setTitle: () => {}, |
| 39 | + }), |
| 40 | +})); |
| 41 | + |
| 42 | +const round = { |
| 43 | + id: '333-r1', |
| 44 | + cutoff: { |
| 45 | + numberOfAttempts: 2, |
| 46 | + attemptResult: 1200, |
| 47 | + }, |
| 48 | + timeLimit: null, |
| 49 | + advancementCondition: null, |
| 50 | +} as unknown as Round; |
| 51 | + |
| 52 | +function renderPanel() { |
| 53 | + return render( |
| 54 | + <MemoryRouter> |
| 55 | + <CutoffTimeLimitPanel round={round} /> |
| 56 | + </MemoryRouter>, |
| 57 | + ); |
| 58 | +} |
| 59 | + |
| 60 | +describe('CutoffTimeLimitPanel', () => { |
| 61 | + it('uses theme-aware popover classes for help content', () => { |
| 62 | + renderPanel(); |
| 63 | + |
| 64 | + fireEvent.click(screen.getByRole('button', { name: /help/i })); |
| 65 | + |
| 66 | + const popoverContent = screen |
| 67 | + .getByText(/common\.cutoffTimeLimitPopover\.timeLimits/i) |
| 68 | + .closest('div'); |
| 69 | + |
| 70 | + expect(popoverContent).toHaveClass('bg-panel'); |
| 71 | + expect(popoverContent).toHaveClass('text-default'); |
| 72 | + expect(popoverContent).not.toHaveClass('bg-white'); |
| 73 | + }); |
| 74 | +}); |
0 commit comments