114 lines
3.2 KiB
TypeScript
114 lines
3.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { ProtestViewModel } from './ProtestViewModel';
|
|
import type { ProtestDTO } from '../types/generated/ProtestDTO';
|
|
|
|
describe('ProtestViewModel', () => {
|
|
it('should create instance with all properties', () => {
|
|
const dto: ProtestDTO = {
|
|
id: 'protest-123',
|
|
raceId: 'race-456',
|
|
complainantId: 'driver-111',
|
|
defendantId: 'driver-222',
|
|
description: 'Unsafe driving in turn 3',
|
|
status: 'pending',
|
|
createdAt: '2023-01-15T10:30:00Z',
|
|
};
|
|
|
|
const viewModel = new ProtestViewModel(dto);
|
|
|
|
expect(viewModel.id).toBe('protest-123');
|
|
expect(viewModel.raceId).toBe('race-456');
|
|
expect(viewModel.complainantId).toBe('driver-111');
|
|
expect(viewModel.defendantId).toBe('driver-222');
|
|
expect(viewModel.description).toBe('Unsafe driving in turn 3');
|
|
expect(viewModel.status).toBe('pending');
|
|
expect(viewModel.createdAt).toBe('2023-01-15T10:30:00Z');
|
|
});
|
|
|
|
it('should format createdAt as locale string', () => {
|
|
const dto: ProtestDTO = {
|
|
id: 'protest-123',
|
|
raceId: 'race-456',
|
|
complainantId: 'driver-111',
|
|
defendantId: 'driver-222',
|
|
description: 'Test',
|
|
status: 'pending',
|
|
createdAt: '2023-01-15T10:30:00Z',
|
|
};
|
|
|
|
const viewModel = new ProtestViewModel(dto);
|
|
const formatted = viewModel.formattedCreatedAt;
|
|
|
|
expect(formatted).toContain('2023');
|
|
expect(formatted).toContain('1/15');
|
|
});
|
|
|
|
it('should capitalize status for display', () => {
|
|
const statuses = ['pending', 'approved', 'rejected', 'reviewing'];
|
|
|
|
statuses.forEach(status => {
|
|
const dto: ProtestDTO = {
|
|
id: 'protest-123',
|
|
raceId: 'race-456',
|
|
complainantId: 'driver-111',
|
|
defendantId: 'driver-222',
|
|
description: 'Test',
|
|
status,
|
|
createdAt: '2023-01-15T10:30:00Z',
|
|
};
|
|
|
|
const viewModel = new ProtestViewModel(dto);
|
|
const expected = status.charAt(0).toUpperCase() + status.slice(1);
|
|
|
|
expect(viewModel.statusDisplay).toBe(expected);
|
|
});
|
|
});
|
|
|
|
it('should handle already capitalized status', () => {
|
|
const dto: ProtestDTO = {
|
|
id: 'protest-123',
|
|
raceId: 'race-456',
|
|
complainantId: 'driver-111',
|
|
defendantId: 'driver-222',
|
|
description: 'Test',
|
|
status: 'Pending',
|
|
createdAt: '2023-01-15T10:30:00Z',
|
|
};
|
|
|
|
const viewModel = new ProtestViewModel(dto);
|
|
|
|
expect(viewModel.statusDisplay).toBe('Pending');
|
|
});
|
|
|
|
it('should handle single character status', () => {
|
|
const dto: ProtestDTO = {
|
|
id: 'protest-123',
|
|
raceId: 'race-456',
|
|
complainantId: 'driver-111',
|
|
defendantId: 'driver-222',
|
|
description: 'Test',
|
|
status: 'p',
|
|
createdAt: '2023-01-15T10:30:00Z',
|
|
};
|
|
|
|
const viewModel = new ProtestViewModel(dto);
|
|
|
|
expect(viewModel.statusDisplay).toBe('P');
|
|
});
|
|
|
|
it('should handle empty status', () => {
|
|
const dto: ProtestDTO = {
|
|
id: 'protest-123',
|
|
raceId: 'race-456',
|
|
complainantId: 'driver-111',
|
|
defendantId: 'driver-222',
|
|
description: 'Test',
|
|
status: '',
|
|
createdAt: '2023-01-15T10:30:00Z',
|
|
};
|
|
|
|
const viewModel = new ProtestViewModel(dto);
|
|
|
|
expect(viewModel.statusDisplay).toBe('');
|
|
});
|
|
}); |