view data fixes
Some checks failed
Contract Testing / contract-snapshot (pull_request) Has been cancelled
Contract Testing / contract-tests (pull_request) Has been cancelled

This commit is contained in:
2026-01-25 00:12:30 +01:00
parent 1b0a1f4aee
commit 6c07abe5e7
37 changed files with 400 additions and 185 deletions

View File

@@ -5,17 +5,32 @@ import { StandingEntryViewModel } from './StandingEntryViewModel';
describe('StandingEntryViewModel', () => {
const createMockStanding = (overrides?: Partial<LeagueStandingDTO>): LeagueStandingDTO => ({
driverId: 'driver-1',
driver: {
id: 'driver-1',
iracingId: '12345',
name: 'Test Driver',
country: 'US',
joinedAt: '2025-01-01T00:00:00Z',
},
position: 1,
points: 100,
wins: 3,
podiums: 5,
races: 8,
positionChange: 0,
lastRacePoints: 0,
droppedRaceIds: [],
...overrides,
});
it('should create instance with all properties', () => {
const dto = createMockStanding();
const viewModel = new StandingEntryViewModel(dto, 100, 85, 'driver-1');
const viewModel = new StandingEntryViewModel({
...dto,
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
});
expect(viewModel.driverId).toBe('driver-1');
expect(viewModel.position).toBe(1);
@@ -26,159 +41,159 @@ describe('StandingEntryViewModel', () => {
});
it('should return position as badge string', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 5 }),
100,
85,
'driver-1'
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 5 }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
});
expect(viewModel.positionBadge).toBe('5');
expect(viewModel.positionBadge).toBe('P5');
});
it('should calculate points gap to leader correctly', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 2, points: 85 }),
100, // leader points
70, // next points
'driver-2'
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 2, points: 85 }),
leaderPoints: 100, // leader points
nextPoints: 70, // next points
currentUserId: 'driver-2',
});
expect(viewModel.pointsGapToLeader).toBe(-15);
});
it('should show zero gap when driver is leader', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 1, points: 100 }),
100, // leader points
85, // next points
'driver-1'
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 1, points: 100 }),
leaderPoints: 100, // leader points
nextPoints: 85, // next points
currentUserId: 'driver-1',
});
expect(viewModel.pointsGapToLeader).toBe(0);
});
it('should calculate points gap to next position correctly', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 2, points: 85 }),
100, // leader points
70, // next points
'driver-2'
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 2, points: 85 }),
leaderPoints: 100, // leader points
nextPoints: 70, // next points
currentUserId: 'driver-2',
});
expect(viewModel.pointsGapToNext).toBe(15);
});
it('should identify current user correctly', () => {
const viewModel1 = new StandingEntryViewModel(
createMockStanding({ driverId: 'driver-1' }),
100,
85,
'driver-1'
);
const viewModel1 = new StandingEntryViewModel({
...createMockStanding({ driverId: 'driver-1' }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
});
const viewModel2 = new StandingEntryViewModel(
createMockStanding({ driverId: 'driver-1' }),
100,
85,
'driver-2'
);
const viewModel2 = new StandingEntryViewModel({
...createMockStanding({ driverId: 'driver-1' }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-2',
});
expect(viewModel1.isCurrentUser).toBe(true);
expect(viewModel2.isCurrentUser).toBe(false);
});
it('should return "same" trend when no previous position', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 1 }),
100,
85,
'driver-1'
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 1 }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
});
expect(viewModel.trend).toBe('same');
});
it('should return "up" trend when position improved', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 1 }),
100,
85,
'driver-1',
3 // previous position was 3rd
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 1 }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
previousPosition: 3, // previous position was 3rd
});
expect(viewModel.trend).toBe('up');
});
it('should return "down" trend when position worsened', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 5 }),
100,
85,
'driver-1',
2 // previous position was 2nd
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 5 }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
previousPosition: 2, // previous position was 2nd
});
expect(viewModel.trend).toBe('down');
});
it('should return "same" trend when position unchanged', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 3 }),
100,
85,
'driver-1',
3 // same position
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 3 }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
previousPosition: 3, // same position
});
expect(viewModel.trend).toBe('same');
});
it('should return correct trend arrow for up', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 1 }),
100,
85,
'driver-1',
3
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 1 }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
previousPosition: 3,
});
expect(viewModel.trendArrow).toBe('↑');
});
it('should return correct trend arrow for down', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 5 }),
100,
85,
'driver-1',
2
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 5 }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
previousPosition: 2,
});
expect(viewModel.trendArrow).toBe('↓');
});
it('should return correct trend arrow for same', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 3 }),
100,
85,
'driver-1'
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 3 }),
leaderPoints: 100,
nextPoints: 85,
currentUserId: 'driver-1',
});
expect(viewModel.trendArrow).toBe('-');
});
it('should handle edge case of last place with no one behind', () => {
const viewModel = new StandingEntryViewModel(
createMockStanding({ position: 10, points: 20 }),
100, // leader points
20, // same points (last place)
'driver-10'
);
const viewModel = new StandingEntryViewModel({
...createMockStanding({ position: 10, points: 20 }),
leaderPoints: 100, // leader points
nextPoints: 20, // same points (last place)
currentUserId: 'driver-10',
});
expect(viewModel.pointsGapToNext).toBe(0);
expect(viewModel.pointsGapToLeader).toBe(-80);
});
});
});