Files
HIPCTF2/tests/frontend/event-status.store.spec.ts
T
2026-07-23 03:11:16 +00:00

50 lines
1.6 KiB
TypeScript

import {
formatDdHhMm,
deriveCountdownText,
EventState,
} from '../../frontend/src/app/core/services/event-status.pure';
describe('formatDdHhMm', () => {
it('formats 90_061 seconds as 01:01:01:01', () => {
expect(formatDdHhMm(90_061)).toBe('01:01:01:01');
});
it('formats 800 seconds as 00:00:13:20', () => {
expect(formatDdHhMm(800)).toBe('00:00:13:20');
});
it('formats 0 seconds as 00:00:00:00', () => {
expect(formatDdHhMm(0)).toBe('00:00:00:00');
});
it('returns 00:00:00:00 for negative or non-finite values', () => {
expect(formatDdHhMm(-5)).toBe('00:00:00:00');
expect(formatDdHhMm(Number.NaN)).toBe('00:00:00:00');
});
});
describe('deriveCountdownText', () => {
const states: EventState[] = ['countdown', 'running', 'stopped', 'unconfigured'];
states.forEach((state) => {
it(`returns empty string for ${state} when respective seconds are null`, () => {
if (state === 'stopped' || state === 'unconfigured') {
expect(deriveCountdownText(state, null, null)).toBe(state === 'unconfigured' ? '' : 'Event ended');
} else {
expect(deriveCountdownText(state, null, null)).toBe('00:00:00:00');
}
});
});
it('returns DD:HH:mm:ss to start when countdown and secondsToStart provided', () => {
expect(deriveCountdownText('countdown', 3600, null)).toBe('00:01:00:00');
});
it('returns DD:HH:mm:ss to end when running and secondsToEnd provided', () => {
expect(deriveCountdownText('running', null, 800)).toBe('00:00:13:20');
});
it('returns "Event ended" when stopped', () => {
expect(deriveCountdownText('stopped', 0, 0)).toBe('Event ended');
});
});