Skip to content

Commit

Permalink
test(countdown): add tests for each formatted duration
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdickerson committed Jan 22, 2025
1 parent 1d5de76 commit 6775cd6
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/components/Countdown/Countdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,40 @@ describe('Countdown', () => {
expect(screen.getByText('seconds')).toBeInTheDocument();
expect(screen.queryByText('Lots Close in 2-minute intervals')).not.toBeInTheDocument();
});

const chineseHours = '小时';
const chineseMinutes = '分钟';
const chineseDays = '天';
const chineseSeconds = '秒';
it('renders with chinese minutes', () => {
const tenSecondsFromNow = addSeconds(new Date(), 10);
render(
<Countdown endDateTime={tenSecondsFromNow} variant={CountdownVariants.compact} locale={SupportedLanguages.zh} />,
);
expect(screen.getByText('分钟')).toBeInTheDocument();
expect(screen.getByText('秒')).toBeInTheDocument();
expect(screen.getByText(chineseMinutes)).toBeInTheDocument();
expect(screen.getByText(chineseSeconds)).toBeInTheDocument();
expect(screen.queryByText('Lots Close in 2-minute intervals')).not.toBeInTheDocument();
});
it('renders with chinese hours', () => {
const twentyFourHoursFromNow = addDays(new Date(), 1);
render(
<Countdown
endDateTime={twentyFourHoursFromNow}
variant={CountdownVariants.compact}
locale={SupportedLanguages.zh}
/>,
);
expect(screen.getByText(chineseHours)).toBeInTheDocument();
expect(screen.getByText(chineseMinutes)).toBeInTheDocument();
expect(screen.queryByText('Lots Close in 2-minute intervals')).not.toBeInTheDocument();
});
it('renders with chinese days', () => {
const twoDaysFromNow = addDays(new Date(), 2);
render(
<Countdown endDateTime={twoDaysFromNow} variant={CountdownVariants.compact} locale={SupportedLanguages.zh} />,
);
expect(screen.getByText(chineseDays)).toBeInTheDocument();
expect(screen.getByText(chineseHours)).toBeInTheDocument();
expect(screen.queryByText('Lots Close in 2-minute intervals')).not.toBeInTheDocument();
});
});

0 comments on commit 6775cd6

Please sign in to comment.