view data fixes
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { AnalyticsDashboardViewModel } from './AnalyticsDashboardViewModel';
|
||||
import { AnalyticsDashboardInputViewData } from '../view-data/AnalyticsDashboardInputViewData';
|
||||
|
||||
describe('AnalyticsDashboardViewModel', () => {
|
||||
it('maps core fields from data', () => {
|
||||
const vm = new AnalyticsDashboardViewModel({
|
||||
it('maps core fields from AnalyticsDashboardInputViewData', () => {
|
||||
const viewData: AnalyticsDashboardInputViewData = {
|
||||
totalUsers: 100,
|
||||
activeUsers: 40,
|
||||
totalRaces: 10,
|
||||
totalLeagues: 5,
|
||||
});
|
||||
};
|
||||
|
||||
const vm = new AnalyticsDashboardViewModel(viewData);
|
||||
|
||||
expect(vm.totalUsers).toBe(100);
|
||||
expect(vm.activeUsers).toBe(40);
|
||||
@@ -17,24 +20,28 @@ describe('AnalyticsDashboardViewModel', () => {
|
||||
});
|
||||
|
||||
it('computes engagement rate and formatted engagement rate', () => {
|
||||
const vm = new AnalyticsDashboardViewModel({
|
||||
const viewData: AnalyticsDashboardInputViewData = {
|
||||
totalUsers: 200,
|
||||
activeUsers: 50,
|
||||
totalRaces: 0,
|
||||
totalLeagues: 0,
|
||||
});
|
||||
};
|
||||
|
||||
const vm = new AnalyticsDashboardViewModel(viewData);
|
||||
|
||||
expect(vm.userEngagementRate).toBeCloseTo(25);
|
||||
expect(vm.formattedEngagementRate).toBe('25.0%');
|
||||
});
|
||||
|
||||
it('handles zero users safely', () => {
|
||||
const vm = new AnalyticsDashboardViewModel({
|
||||
const viewData: AnalyticsDashboardInputViewData = {
|
||||
totalUsers: 0,
|
||||
activeUsers: 0,
|
||||
totalRaces: 0,
|
||||
totalLeagues: 0,
|
||||
});
|
||||
};
|
||||
|
||||
const vm = new AnalyticsDashboardViewModel(viewData);
|
||||
|
||||
expect(vm.userEngagementRate).toBe(0);
|
||||
expect(vm.formattedEngagementRate).toBe('0.0%');
|
||||
|
||||
Reference in New Issue
Block a user