189 lines
5.5 KiB
TypeScript
189 lines
5.5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { CompleteOnboardingViewModel } from './CompleteOnboardingViewModel';
|
|
import type { CompleteOnboardingViewData } from '../builders/view-data/CompleteOnboardingViewData';
|
|
|
|
describe('CompleteOnboardingViewModel', () => {
|
|
describe('constructor', () => {
|
|
it('should create instance with success flag', () => {
|
|
const viewData: CompleteOnboardingViewData = {
|
|
success: true,
|
|
};
|
|
|
|
const viewModel = new CompleteOnboardingViewModel(viewData);
|
|
|
|
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();
|
|
});
|
|
});
|
|
|
|
describe('UI-specific getters', () => {
|
|
it('should expose isSuccessful as true when success is true', () => {
|
|
const viewData: CompleteOnboardingViewData = {
|
|
success: true,
|
|
};
|
|
|
|
const viewModel = new CompleteOnboardingViewModel(viewData);
|
|
|
|
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);
|
|
});
|
|
});
|
|
|
|
describe('Display Object composition', () => {
|
|
it('should derive statusLabel from success', () => {
|
|
const viewData: CompleteOnboardingViewData = {
|
|
success: true,
|
|
};
|
|
|
|
const viewModel = new CompleteOnboardingViewModel(viewData);
|
|
|
|
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');
|
|
});
|
|
});
|
|
}); |