view data fixes
This commit is contained in:
@@ -1,24 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { AvailableLeaguesViewModel, AvailableLeagueViewModel } from './AvailableLeaguesViewModel';
|
||||
import { AvailableLeaguesViewData, AvailableLeagueViewData } from '../view-data/AvailableLeaguesViewData';
|
||||
|
||||
describe('AvailableLeaguesViewModel', () => {
|
||||
const baseLeague = {
|
||||
const baseLeague: AvailableLeagueViewData = {
|
||||
id: 'league-1',
|
||||
name: 'Pro Series',
|
||||
game: 'iRacing',
|
||||
description: 'Competitive league for serious drivers',
|
||||
drivers: 24,
|
||||
avgViewsPerRace: 12_500,
|
||||
formattedAvgViews: '12.5k',
|
||||
mainSponsorSlot: { available: true, price: 5_000 },
|
||||
secondarySlots: { available: 2, total: 3, price: 1_500 },
|
||||
cpm: 400,
|
||||
formattedCpm: '$400',
|
||||
hasAvailableSlots: true,
|
||||
rating: 4.7,
|
||||
tier: 'premium' as const,
|
||||
tierConfig: {
|
||||
color: '#FFD700',
|
||||
bgColor: '#FFF8DC',
|
||||
border: '2px solid #FFD700',
|
||||
icon: '⭐',
|
||||
},
|
||||
nextRace: 'Next Sunday',
|
||||
seasonStatus: 'active' as const,
|
||||
description: 'Competitive league for serious drivers',
|
||||
statusConfig: {
|
||||
color: '#10B981',
|
||||
bg: '#D1FAE5',
|
||||
label: 'Active Season',
|
||||
},
|
||||
};
|
||||
|
||||
const baseViewData: AvailableLeaguesViewData = {
|
||||
leagues: [baseLeague],
|
||||
};
|
||||
|
||||
it('maps league array into view models', () => {
|
||||
const vm = new AvailableLeaguesViewModel([baseLeague]);
|
||||
const vm = new AvailableLeaguesViewModel(baseViewData);
|
||||
|
||||
expect(vm.leagues).toHaveLength(1);
|
||||
expect(vm.leagues[0]).toBeInstanceOf(AvailableLeagueViewModel);
|
||||
@@ -30,11 +50,11 @@ describe('AvailableLeaguesViewModel', () => {
|
||||
it('exposes formatted average views and CPM for main sponsor slot', () => {
|
||||
const leagueVm = new AvailableLeagueViewModel(baseLeague);
|
||||
|
||||
expect(leagueVm.formattedAvgViews).toBe(`${(baseLeague.avgViewsPerRace / 1000).toFixed(1)}k`);
|
||||
expect(leagueVm.formattedAvgViews).toBe('12.5k');
|
||||
|
||||
const expectedCpm = Math.round((baseLeague.mainSponsorSlot.price / baseLeague.avgViewsPerRace) * 1000);
|
||||
expect(leagueVm.cpm).toBe(expectedCpm);
|
||||
expect(leagueVm.formattedCpm).toBe(`$${expectedCpm}`);
|
||||
expect(leagueVm.formattedCpm).toBe('$400');
|
||||
});
|
||||
|
||||
it('detects available sponsor slots from main or secondary slots', () => {
|
||||
@@ -75,4 +95,5 @@ describe('AvailableLeaguesViewModel', () => {
|
||||
expect(upcoming.statusConfig.label).toBe('Starting Soon');
|
||||
expect(completed.statusConfig.label).toBe('Season Ended');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user