view data fixes
This commit is contained in:
@@ -1,35 +1,189 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { CompleteOnboardingViewModel } from './CompleteOnboardingViewModel';
|
||||
import type { CompleteOnboardingOutputDTO } from '../types/generated/CompleteOnboardingOutputDTO';
|
||||
import type { CompleteOnboardingViewData } from '../builders/view-data/CompleteOnboardingViewData';
|
||||
|
||||
describe('CompleteOnboardingViewModel', () => {
|
||||
it('should create instance with success flag', () => {
|
||||
const dto: CompleteOnboardingOutputDTO = {
|
||||
success: true,
|
||||
};
|
||||
describe('constructor', () => {
|
||||
it('should create instance with success flag', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(dto);
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.success).toBe(true);
|
||||
expect(viewModel.success).toBe(true);
|
||||
});
|
||||
|
||||
it('should create instance with driverId', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
driverId: 'driver-123',
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.driverId).toBe('driver-123');
|
||||
});
|
||||
|
||||
it('should create instance with errorMessage', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: false,
|
||||
errorMessage: 'Failed to complete onboarding',
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.errorMessage).toBe('Failed to complete onboarding');
|
||||
});
|
||||
|
||||
it('should create instance with all fields', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
driverId: 'driver-123',
|
||||
errorMessage: undefined,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.success).toBe(true);
|
||||
expect(viewModel.driverId).toBe('driver-123');
|
||||
expect(viewModel.errorMessage).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should expose isSuccessful as true when success is true', () => {
|
||||
const dto: CompleteOnboardingOutputDTO = {
|
||||
success: true,
|
||||
};
|
||||
describe('UI-specific getters', () => {
|
||||
it('should expose isSuccessful as true when success is true', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(dto);
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.isSuccessful).toBe(true);
|
||||
expect(viewModel.isSuccessful).toBe(true);
|
||||
});
|
||||
|
||||
it('should expose isSuccessful as false when success is false', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: false,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.isSuccessful).toBe(false);
|
||||
});
|
||||
|
||||
it('should expose hasError as true when errorMessage is present', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: false,
|
||||
errorMessage: 'Error occurred',
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.hasError).toBe(true);
|
||||
});
|
||||
|
||||
it('should expose hasError as false when errorMessage is not present', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.hasError).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('should expose isSuccessful as false when success is false', () => {
|
||||
const dto: CompleteOnboardingOutputDTO = {
|
||||
success: false,
|
||||
};
|
||||
describe('Display Object composition', () => {
|
||||
it('should derive statusLabel from success', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(dto);
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.isSuccessful).toBe(false);
|
||||
expect(viewModel.statusLabel).toBe('Onboarding Complete');
|
||||
});
|
||||
|
||||
it('should derive statusLabel from failure', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: false,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.statusLabel).toBe('Onboarding Failed');
|
||||
});
|
||||
|
||||
it('should derive statusVariant from success', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.statusVariant).toBe('performance-green');
|
||||
});
|
||||
|
||||
it('should derive statusVariant from failure', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: false,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.statusVariant).toBe('racing-red');
|
||||
});
|
||||
|
||||
it('should derive statusIcon from success', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.statusIcon).toBe('✅');
|
||||
});
|
||||
|
||||
it('should derive statusIcon from failure', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: false,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.statusIcon).toBe('❌');
|
||||
});
|
||||
|
||||
it('should derive statusMessage from success', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: true,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.statusMessage).toBe('Your onboarding has been completed successfully.');
|
||||
});
|
||||
|
||||
it('should derive statusMessage from failure with default message', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: false,
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.statusMessage).toBe('Failed to complete onboarding. Please try again.');
|
||||
});
|
||||
|
||||
it('should derive statusMessage from failure with custom error message', () => {
|
||||
const viewData: CompleteOnboardingViewData = {
|
||||
success: false,
|
||||
errorMessage: 'Custom error message',
|
||||
};
|
||||
|
||||
const viewModel = new CompleteOnboardingViewModel(viewData);
|
||||
|
||||
expect(viewModel.statusMessage).toBe('Custom error message');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user