104 lines
3.2 KiB
TypeScript
104 lines
3.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { StepId } from 'apps/companion/main/automation/domain/value-objects/StepId';
|
|
|
|
describe('StepId Value Object', () => {
|
|
describe('create', () => {
|
|
it('should create a valid StepId for step 1', () => {
|
|
const stepId = StepId.create(1);
|
|
expect(stepId.value).toBe(1);
|
|
});
|
|
|
|
it('should create a valid StepId for step 17', () => {
|
|
const stepId = StepId.create(17);
|
|
expect(stepId.value).toBe(17);
|
|
});
|
|
|
|
it('should throw error for step 0 (below minimum)', () => {
|
|
expect(() => StepId.create(0)).toThrow('StepId must be between 1 and 17');
|
|
});
|
|
|
|
it('should throw error for step 18 (above maximum)', () => {
|
|
expect(() => StepId.create(18)).toThrow('StepId must be between 1 and 17');
|
|
});
|
|
|
|
it('should throw error for negative step', () => {
|
|
expect(() => StepId.create(-1)).toThrow('StepId must be between 1 and 17');
|
|
});
|
|
|
|
it('should throw error for non-integer step', () => {
|
|
expect(() => StepId.create(5.5)).toThrow('StepId must be an integer');
|
|
});
|
|
});
|
|
|
|
describe('equals', () => {
|
|
it('should return true for equal StepIds', () => {
|
|
const stepId1 = StepId.create(5);
|
|
const stepId2 = StepId.create(5);
|
|
expect(stepId1.equals(stepId2)).toBe(true);
|
|
});
|
|
|
|
it('should return false for different StepIds', () => {
|
|
const stepId1 = StepId.create(5);
|
|
const stepId2 = StepId.create(6);
|
|
expect(stepId1.equals(stepId2)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('isModalStep', () => {
|
|
it('should return true for step 6 (add admin modal)', () => {
|
|
const stepId = StepId.create(6);
|
|
expect(stepId.isModalStep()).toBe(true);
|
|
});
|
|
|
|
it('should return true for step 9 (add car modal)', () => {
|
|
const stepId = StepId.create(9);
|
|
expect(stepId.isModalStep()).toBe(true);
|
|
});
|
|
|
|
it('should return true for step 12 (add track modal)', () => {
|
|
const stepId = StepId.create(12);
|
|
expect(stepId.isModalStep()).toBe(true);
|
|
});
|
|
|
|
it('should return false for non-modal step', () => {
|
|
const stepId = StepId.create(1);
|
|
expect(stepId.isModalStep()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('isFinalStep', () => {
|
|
it('should return true for step 17', () => {
|
|
const stepId = StepId.create(17);
|
|
expect(stepId.isFinalStep()).toBe(true);
|
|
});
|
|
|
|
it('should return false for step 16', () => {
|
|
const stepId = StepId.create(16);
|
|
expect(stepId.isFinalStep()).toBe(false);
|
|
});
|
|
|
|
it('should return false for step 1', () => {
|
|
const stepId = StepId.create(1);
|
|
expect(stepId.isFinalStep()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('next', () => {
|
|
it('should return next step for step 1', () => {
|
|
const stepId = StepId.create(1);
|
|
const nextStep = stepId.next();
|
|
expect(nextStep.value).toBe(2);
|
|
});
|
|
|
|
it('should return next step for step 16', () => {
|
|
const stepId = StepId.create(16);
|
|
const nextStep = stepId.next();
|
|
expect(nextStep.value).toBe(17);
|
|
});
|
|
|
|
it('should throw error when calling next on step 17', () => {
|
|
const stepId = StepId.create(17);
|
|
expect(() => stepId.next()).toThrow('Cannot advance beyond final step');
|
|
});
|
|
});
|
|
}); |