AI Implementation feature(859): Admin Area General Settings and Categories (#21)
This commit was merged in pull request #21.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { deriveEventState, endAfterStartValidator, toDatetimeLocal, toIsoUtc } from '../../frontend/src/app/features/admin/general.pure';
|
||||
|
||||
describe('deriveEventState', () => {
|
||||
const start = '2026-01-01T00:00:00Z';
|
||||
const end = '2026-01-02T00:00:00Z';
|
||||
|
||||
it('returns "unconfigured" when start or end is missing', () => {
|
||||
expect(deriveEventState('', '')).toBe('unconfigured');
|
||||
expect(deriveEventState(start, '')).toBe('unconfigured');
|
||||
expect(deriveEventState('', end)).toBe('unconfigured');
|
||||
});
|
||||
|
||||
it('returns "unconfigured" when dates cannot be parsed', () => {
|
||||
expect(deriveEventState('not-a-date', end)).toBe('unconfigured');
|
||||
});
|
||||
|
||||
it('returns "countdown" when now is before start', () => {
|
||||
const s = new Date(Date.now() + 60_000).toISOString();
|
||||
const e = new Date(Date.now() + 120_000).toISOString();
|
||||
expect(deriveEventState(s, e)).toBe('countdown');
|
||||
});
|
||||
|
||||
it('returns "running" when now is between start and end', () => {
|
||||
const s = new Date(Date.now() - 60_000).toISOString();
|
||||
const e = new Date(Date.now() + 60_000).toISOString();
|
||||
expect(deriveEventState(s, e)).toBe('running');
|
||||
});
|
||||
|
||||
it('returns "stopped" when now is after end', () => {
|
||||
const s = new Date(Date.now() - 120_000).toISOString();
|
||||
const e = new Date(Date.now() - 60_000).toISOString();
|
||||
expect(deriveEventState(s, e)).toBe('stopped');
|
||||
});
|
||||
});
|
||||
|
||||
describe('endAfterStartValidator', () => {
|
||||
const ctrl = (start: string, end: string) => ({
|
||||
get: (k: string) =>
|
||||
k === 'eventStartUtc'
|
||||
? { value: start }
|
||||
: k === 'eventEndUtc'
|
||||
? { value: end }
|
||||
: { value: '' },
|
||||
});
|
||||
|
||||
it('returns null when either field is empty', () => {
|
||||
expect(endAfterStartValidator(ctrl('', '2026-01-01T00:00:00Z'))).toBeNull();
|
||||
expect(endAfterStartValidator(ctrl('2026-01-01T00:00:00Z', ''))).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when end is strictly after start', () => {
|
||||
expect(endAfterStartValidator(ctrl('2026-01-01T00:00:00Z', '2026-01-02T00:00:00Z'))).toBeNull();
|
||||
});
|
||||
|
||||
it('returns { endBeforeStart: true } when end equals start', () => {
|
||||
expect(endAfterStartValidator(ctrl('2026-01-01T00:00:00Z', '2026-01-01T00:00:00Z'))).toEqual({ endBeforeStart: true });
|
||||
});
|
||||
|
||||
it('returns { endBeforeStart: true } when end is before start', () => {
|
||||
expect(endAfterStartValidator(ctrl('2026-01-02T00:00:00Z', '2026-01-01T00:00:00Z'))).toEqual({ endBeforeStart: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe('datetime helpers', () => {
|
||||
it('toDatetimeLocal formats an ISO timestamp with UTC components', () => {
|
||||
expect(toDatetimeLocal('2026-01-02T03:04:00Z')).toBe('2026-01-02T03:04');
|
||||
});
|
||||
|
||||
it('toDatetimeLocal returns empty string for invalid input', () => {
|
||||
expect(toDatetimeLocal('')).toBe('');
|
||||
expect(toDatetimeLocal('garbage')).toBe('');
|
||||
});
|
||||
|
||||
it('toIsoUtc converts a local datetime back to UTC ISO', () => {
|
||||
const iso = toIsoUtc('2026-01-02T03:04');
|
||||
expect(iso).toMatch(/^2026-01-02T03:04:00\.000Z$/);
|
||||
});
|
||||
|
||||
it('toIsoUtc returns input verbatim when empty', () => {
|
||||
expect(toIsoUtc('')).toBe('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user