111 lines
2.9 KiB
TypeScript
111 lines
2.9 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { DriverViewModel } from './DriverViewModel';
|
|
|
|
describe('DriverViewModel', () => {
|
|
it('should create instance with all properties', () => {
|
|
const dto = {
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
avatarUrl: 'https://example.com/avatar.jpg',
|
|
iracingId: 'iracing-456',
|
|
rating: 1500,
|
|
};
|
|
|
|
const viewModel = new DriverViewModel(dto);
|
|
|
|
expect(viewModel.id).toBe('driver-123');
|
|
expect(viewModel.name).toBe('John Doe');
|
|
expect(viewModel.avatarUrl).toBe('https://example.com/avatar.jpg');
|
|
expect(viewModel.iracingId).toBe('iracing-456');
|
|
expect(viewModel.rating).toBe(1500);
|
|
});
|
|
|
|
it('should create instance with only required properties', () => {
|
|
const dto = {
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
};
|
|
|
|
const viewModel = new DriverViewModel(dto);
|
|
|
|
expect(viewModel.id).toBe('driver-123');
|
|
expect(viewModel.name).toBe('John Doe');
|
|
expect(viewModel.avatarUrl).toBeUndefined();
|
|
expect(viewModel.iracingId).toBeUndefined();
|
|
expect(viewModel.rating).toBeUndefined();
|
|
});
|
|
|
|
it('should return true for hasIracingId when iracingId exists', () => {
|
|
const viewModel = new DriverViewModel({
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
iracingId: 'iracing-456',
|
|
});
|
|
|
|
expect(viewModel.hasIracingId).toBe(true);
|
|
});
|
|
|
|
it('should return false for hasIracingId when iracingId is undefined', () => {
|
|
const viewModel = new DriverViewModel({
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
});
|
|
|
|
expect(viewModel.hasIracingId).toBe(false);
|
|
});
|
|
|
|
it('should return false for hasIracingId when iracingId is empty string', () => {
|
|
const viewModel = new DriverViewModel({
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
iracingId: '',
|
|
});
|
|
|
|
expect(viewModel.hasIracingId).toBe(false);
|
|
});
|
|
|
|
it('should format rating correctly when rating exists', () => {
|
|
const viewModel = new DriverViewModel({
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
rating: 1547.89,
|
|
});
|
|
|
|
expect(viewModel.formattedRating).toBe('1548');
|
|
});
|
|
|
|
it('should return "Unrated" when rating is undefined', () => {
|
|
const viewModel = new DriverViewModel({
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
});
|
|
|
|
expect(viewModel.formattedRating).toBe('Unrated');
|
|
});
|
|
|
|
it('should handle zero rating', () => {
|
|
const viewModel = new DriverViewModel({
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
rating: 0,
|
|
});
|
|
|
|
expect(viewModel.formattedRating).toBe('Unrated');
|
|
});
|
|
|
|
it('should round rating to nearest integer', () => {
|
|
const viewModel1 = new DriverViewModel({
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
rating: 1500.4,
|
|
});
|
|
const viewModel2 = new DriverViewModel({
|
|
id: 'driver-123',
|
|
name: 'John Doe',
|
|
rating: 1500.6,
|
|
});
|
|
|
|
expect(viewModel1.formattedRating).toBe('1500');
|
|
expect(viewModel2.formattedRating).toBe('1501');
|
|
});
|
|
}); |