diff --git a/src/app/components/user-input/user-input.spec.ts b/src/app/components/user-input/user-input.spec.ts index 31f28a9..2f79fd8 100644 --- a/src/app/components/user-input/user-input.spec.ts +++ b/src/app/components/user-input/user-input.spec.ts @@ -2,10 +2,12 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { provideZonelessChangeDetection } from '@angular/core'; import { UserInput } from './user-input'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; +import { UserInputService } from '../../services/user-input-service'; describe('UserInput', () => { let component: UserInput; let fixture: ComponentFixture; + let userInputService: UserInputService; beforeEach(async () => { await TestBed.configureTestingModule({ @@ -15,6 +17,7 @@ describe('UserInput', () => { fixture = TestBed.createComponent(UserInput); component = fixture.componentInstance; + userInputService = TestBed.inject(UserInputService); fixture.detectChanges(); }); @@ -22,20 +25,22 @@ describe('UserInput', () => { expect(component).toBeTruthy(); }); - it('should initialize form with values from service', () => { - expect(component.userInputForm).toBeDefined(); - expect(component.userInputForm.get('CP')).toBeDefined(); - expect(component.userInputForm.get('RTT')).toBeDefined(); - expect(component.userInputForm.get('Others')).toBeDefined(); + it('should initialize with vacation days from service', () => { + const vacationDays = userInputService.vacationNumberSignal(); + expect(vacationDays).toBeDefined(); + expect(Array.isArray(vacationDays)).toBe(true); + expect(vacationDays.length).toBeGreaterThan(0); }); - it('should have valid form controls', () => { - const cpControl = component.userInputForm.get('CP'); - const rttControl = component.userInputForm.get('RTT'); - const othersControl = component.userInputForm.get('Others'); + it('should add a new vacation day', () => { + const initialLength = userInputService.vacationNumberSignal().length; + component.addDay(); + expect(userInputService.vacationNumberSignal().length).toBe(initialLength + 1); + }); - expect(cpControl).toBeTruthy(); - expect(rttControl).toBeTruthy(); - expect(othersControl).toBeTruthy(); + it('should remove a vacation day', () => { + const initialLength = userInputService.vacationNumberSignal().length; + component.removeFromList(0); + expect(userInputService.vacationNumberSignal().length).toBe(initialLength - 1); }); }); diff --git a/src/app/services/user-input-service.spec.ts b/src/app/services/user-input-service.spec.ts index abaafdf..365ffad 100644 --- a/src/app/services/user-input-service.spec.ts +++ b/src/app/services/user-input-service.spec.ts @@ -1,8 +1,9 @@ import { TestBed } from '@angular/core/testing'; import { provideZonelessChangeDetection } from '@angular/core'; import { UserInputService } from './user-input-service'; +import { SelectableDayType, VacDay } from './calendar-service'; -describe('UserInput', () => { +describe('UserInputService', () => { let service: UserInputService; beforeEach(() => { @@ -16,19 +17,41 @@ describe('UserInput', () => { expect(service).toBeTruthy(); }); - it('should initialize with random vacation numbers', () => { + it('should initialize with vacation days array', () => { const vacations = service.vacationNumberSignal(); - expect(vacations.cp).toBeGreaterThanOrEqual(1); - expect(vacations.cp).toBeLessThanOrEqual(9); - expect(vacations.rtt).toBeGreaterThanOrEqual(1); - expect(vacations.rtt).toBeLessThanOrEqual(9); - expect(vacations.other).toBeGreaterThanOrEqual(1); - expect(vacations.other).toBeLessThanOrEqual(9); + expect(Array.isArray(vacations)).toBe(true); + expect(vacations.length).toBeGreaterThan(0); + }); + + it('should have vacation days with valid properties', () => { + const vacations = service.vacationNumberSignal(); + vacations.forEach((day) => { + expect(day.id).toBeDefined(); + expect(day.type).toBeDefined(); + expect(day.numberOfDays).toBeGreaterThanOrEqual(1); + expect(day.numberOfDays).toBeLessThanOrEqual(9); + expect(day.expiryDate).toBeInstanceOf(Date); + }); }); it('should update vacation number signal', () => { - const newVacations = { cp: 5, rtt: 3, other: 2 }; + const newVacations: VacDay[] = [ + { + id: 'test-id', + type: SelectableDayType.CP, + numberOfDays: 5, + expiryDate: new Date(), + }, + ]; service.vacationNumberSignal.set(newVacations); expect(service.vacationNumberSignal()).toEqual(newVacations); }); + + it('should create a new vacation day', () => { + const newDay = service.createVacationDay(); + expect(newDay.id).toBeDefined(); + expect(newDay.type).toBe(SelectableDayType.CP); + expect(newDay.numberOfDays).toBe(1); + expect(newDay.expiryDate).toBeInstanceOf(Date); + }); });