view data fixes
This commit is contained in:
@@ -1,111 +1,139 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { DriverViewModel } from './DriverViewModel';
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { DriverViewModel } from "./DriverViewModel";
|
||||
import type { DriverData } from "../view-data/LeagueStandingsViewData";
|
||||
|
||||
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',
|
||||
describe("DriverViewModel", () => {
|
||||
it("should create instance with all properties", () => {
|
||||
const viewData: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: "https://example.com/avatar.jpg",
|
||||
iracingId: "iracing-456",
|
||||
rating: 1500,
|
||||
country: "US",
|
||||
};
|
||||
|
||||
const viewModel = new DriverViewModel(dto);
|
||||
const viewModel = new DriverViewModel(viewData);
|
||||
|
||||
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.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);
|
||||
expect(viewModel.country).toBe("US");
|
||||
});
|
||||
|
||||
it('should create instance with only required properties', () => {
|
||||
const dto = {
|
||||
id: 'driver-123',
|
||||
name: 'John Doe',
|
||||
it("should create instance with only required properties", () => {
|
||||
const viewData: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
};
|
||||
|
||||
const viewModel = new DriverViewModel(dto);
|
||||
const viewModel = new DriverViewModel(viewData);
|
||||
|
||||
expect(viewModel.id).toBe('driver-123');
|
||||
expect(viewModel.name).toBe('John Doe');
|
||||
expect(viewModel.id).toBe("driver-123");
|
||||
expect(viewModel.name).toBe("John Doe");
|
||||
expect(viewModel.avatarUrl).toBeNull();
|
||||
expect(viewModel.iracingId).toBeUndefined();
|
||||
expect(viewModel.rating).toBeUndefined();
|
||||
expect(viewModel.country).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return true for hasIracingId when iracingId exists', () => {
|
||||
const viewModel = new DriverViewModel({
|
||||
id: 'driver-123',
|
||||
name: 'John Doe',
|
||||
iracingId: 'iracing-456',
|
||||
});
|
||||
it("should return true for hasIracingId when iracingId exists", () => {
|
||||
const viewData: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
iracingId: "iracing-456",
|
||||
};
|
||||
|
||||
const viewModel = new DriverViewModel(viewData);
|
||||
|
||||
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',
|
||||
});
|
||||
it("should return false for hasIracingId when iracingId is undefined", () => {
|
||||
const viewData: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
};
|
||||
|
||||
const viewModel = new DriverViewModel(viewData);
|
||||
|
||||
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: '',
|
||||
});
|
||||
it("should return false for hasIracingId when iracingId is empty string", () => {
|
||||
const viewData: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
iracingId: "",
|
||||
};
|
||||
|
||||
const viewModel = new DriverViewModel(viewData);
|
||||
|
||||
expect(viewModel.hasIracingId).toBe(false);
|
||||
});
|
||||
|
||||
it('should format rating correctly when rating exists', () => {
|
||||
const viewModel = new DriverViewModel({
|
||||
id: 'driver-123',
|
||||
name: 'John Doe',
|
||||
it("should format rating correctly when rating exists", () => {
|
||||
const viewData: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
rating: 1547.89,
|
||||
});
|
||||
};
|
||||
|
||||
expect(viewModel.formattedRating).toBe('1548');
|
||||
const viewModel = new DriverViewModel(viewData);
|
||||
|
||||
expect(viewModel.formattedRating).toBe("1548");
|
||||
});
|
||||
|
||||
it('should return "Unrated" when rating is undefined', () => {
|
||||
const viewModel = new DriverViewModel({
|
||||
id: 'driver-123',
|
||||
name: 'John Doe',
|
||||
});
|
||||
it("should return \"Unrated\" when rating is undefined", () => {
|
||||
const viewData: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
};
|
||||
|
||||
expect(viewModel.formattedRating).toBe('Unrated');
|
||||
const viewModel = new DriverViewModel(viewData);
|
||||
|
||||
expect(viewModel.formattedRating).toBe("Unrated");
|
||||
});
|
||||
|
||||
it('should handle zero rating', () => {
|
||||
const viewModel = new DriverViewModel({
|
||||
id: 'driver-123',
|
||||
name: 'John Doe',
|
||||
it("should handle zero rating", () => {
|
||||
const viewData: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
rating: 0,
|
||||
});
|
||||
};
|
||||
|
||||
expect(viewModel.formattedRating).toBe('Unrated');
|
||||
const viewModel = new DriverViewModel(viewData);
|
||||
|
||||
expect(viewModel.formattedRating).toBe("Unrated");
|
||||
});
|
||||
|
||||
it('should round rating to nearest integer', () => {
|
||||
const viewModel1 = new DriverViewModel({
|
||||
id: 'driver-123',
|
||||
name: 'John Doe',
|
||||
it("should round rating to nearest integer", () => {
|
||||
const viewData1: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
rating: 1500.4,
|
||||
});
|
||||
const viewModel2 = new DriverViewModel({
|
||||
id: 'driver-123',
|
||||
name: 'John Doe',
|
||||
};
|
||||
const viewData2: DriverData = {
|
||||
id: "driver-123",
|
||||
name: "John Doe",
|
||||
avatarUrl: null,
|
||||
rating: 1500.6,
|
||||
});
|
||||
};
|
||||
|
||||
expect(viewModel1.formattedRating).toBe('1500');
|
||||
expect(viewModel2.formattedRating).toBe('1501');
|
||||
const viewModel1 = new DriverViewModel(viewData1);
|
||||
const viewModel2 = new DriverViewModel(viewData2);
|
||||
|
||||
expect(viewModel1.formattedRating).toBe("1500");
|
||||
expect(viewModel2.formattedRating).toBe("1501");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user