73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { RaceResultViewModel } from './RaceResultViewModel';
|
|
import { RaceResultDTO } from '../types/generated/RaceResultDTO';
|
|
|
|
describe('RaceResultViewModel', () => {
|
|
const mockDTO: RaceResultDTO = {
|
|
driverId: '1',
|
|
driverName: 'Test Driver',
|
|
avatarUrl: 'http://example.com/avatar.jpg',
|
|
position: 3,
|
|
startPosition: 5,
|
|
incidents: 2,
|
|
fastestLap: 90.5,
|
|
positionChange: 2,
|
|
isPodium: true,
|
|
isClean: false
|
|
};
|
|
|
|
it('should create instance from DTO', () => {
|
|
const viewModel = new RaceResultViewModel(mockDTO);
|
|
|
|
expect(viewModel.driverId).toBe('1');
|
|
expect(viewModel.position).toBe(3);
|
|
});
|
|
|
|
it('should show positive position change', () => {
|
|
const viewModel = new RaceResultViewModel(mockDTO);
|
|
|
|
expect(viewModel.positionChangeDisplay).toBe('+2');
|
|
expect(viewModel.positionChangeColor).toBe('green');
|
|
});
|
|
|
|
it('should show negative position change', () => {
|
|
const dto = { ...mockDTO, positionChange: -3 };
|
|
const viewModel = new RaceResultViewModel(dto);
|
|
|
|
expect(viewModel.positionChangeDisplay).toBe('-3');
|
|
expect(viewModel.positionChangeColor).toBe('red');
|
|
});
|
|
|
|
it('should detect winner', () => {
|
|
const dto = { ...mockDTO, position: 1 };
|
|
const viewModel = new RaceResultViewModel(dto);
|
|
|
|
expect(viewModel.isWinner).toBe(true);
|
|
});
|
|
|
|
it('should detect fastest lap', () => {
|
|
const viewModel = new RaceResultViewModel(mockDTO);
|
|
|
|
expect(viewModel.hasFastestLap).toBe(true);
|
|
});
|
|
|
|
it('should format lap time correctly', () => {
|
|
const viewModel = new RaceResultViewModel(mockDTO);
|
|
|
|
expect(viewModel.lapTimeFormatted).toBe('1:30.500');
|
|
});
|
|
|
|
it('should show correct incidents badge color', () => {
|
|
const cleanDTO = { ...mockDTO, incidents: 0 };
|
|
const viewModel = new RaceResultViewModel(cleanDTO);
|
|
|
|
expect(viewModel.incidentsBadgeColor).toBe('green');
|
|
});
|
|
|
|
it('should handle no lap time', () => {
|
|
const dto = { ...mockDTO, fastestLap: 0 };
|
|
const viewModel = new RaceResultViewModel(dto);
|
|
|
|
expect(viewModel.lapTimeFormatted).toBe('--:--.---');
|
|
});
|
|
}); |