Files
gridpilot.gg/apps/website/lib/view-models/ProtestViewModel.test.ts
2025-12-20 00:31:31 +01:00

53 lines
1.8 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { ProtestViewModel } from './ProtestViewModel';
import type { ProtestDTO } from '../types/generated/ProtestDTO';
const createProtestDto = (overrides: Partial<ProtestDTO> = {}): ProtestDTO => ({
id: 'protest-123',
raceId: 'race-456',
protestingDriverId: 'driver-111',
accusedDriverId: 'driver-222',
description: 'Unsafe driving in turn 3',
submittedAt: '2023-01-15T10:30:00Z',
...overrides,
});
describe('ProtestViewModel', () => {
it('maps core fields from ProtestDTO', () => {
const dto: ProtestDTO = createProtestDto();
const viewModel = new ProtestViewModel(dto);
expect(viewModel.id).toBe('protest-123');
expect(viewModel.raceId).toBe('race-456');
expect(viewModel.protestingDriverId).toBe('driver-111');
expect(viewModel.accusedDriverId).toBe('driver-222');
expect(viewModel.description).toBe('Unsafe driving in turn 3');
expect(viewModel.submittedAt).toBe('2023-01-15T10:30:00Z');
});
it('defaults status and review fields for new protests', () => {
const viewModel = new ProtestViewModel(createProtestDto());
expect(viewModel.status).toBe('pending');
expect(viewModel.reviewedAt).toBeUndefined();
expect(viewModel.decisionNotes).toBeUndefined();
});
it('formats submittedAt as a locale string', () => {
const viewModel = new ProtestViewModel(createProtestDto({
submittedAt: '2023-01-15T10:30:00Z',
}));
const formatted = viewModel.formattedSubmittedAt;
expect(typeof formatted).toBe('string');
expect(formatted.length).toBeGreaterThan(0);
});
it('exposes a fixed status display label for pending protests', () => {
const viewModel = new ProtestViewModel(createProtestDto());
expect(viewModel.statusDisplay).toBe('Pending');
});
});