Compare commits

..
2 changed files with 21 additions and 49 deletions

No files matched your search

@@ -2,12 +2,10 @@ 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<UserInput>;
let userInputService: UserInputService;
beforeEach(async () => {
await TestBed.configureTestingModule({
@@ -17,7 +15,6 @@ describe('UserInput', () => {
fixture = TestBed.createComponent(UserInput);
component = fixture.componentInstance;
userInputService = TestBed.inject(UserInputService);
fixture.detectChanges();
});
@@ -25,22 +22,20 @@ describe('UserInput', () => {
expect(component).toBeTruthy();
});
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 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 add a new vacation day', () => {
const initialLength = userInputService.vacationNumberSignal().length;
component.addDay();
expect(userInputService.vacationNumberSignal().length).toBe(initialLength + 1);
});
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 remove a vacation day', () => {
const initialLength = userInputService.vacationNumberSignal().length;
component.removeFromList(0);
expect(userInputService.vacationNumberSignal().length).toBe(initialLength - 1);
expect(cpControl).toBeTruthy();
expect(rttControl).toBeTruthy();
expect(othersControl).toBeTruthy();
});
});
+9 -32
View File
@@ -1,9 +1,8 @@
import { TestBed } from '@angular/core/testing';
import { provideZonelessChangeDetection } from '@angular/core';
import { UserInputService } from './user-input-service';
import { SelectableDayType, VacDay } from './calendar-service';
describe('UserInputService', () => {
describe('UserInput', () => {
let service: UserInputService;
beforeEach(() => {
@@ -17,41 +16,19 @@ describe('UserInputService', () => {
expect(service).toBeTruthy();
});
it('should initialize with vacation days array', () => {
it('should initialize with random vacation numbers', () => {
const vacations = service.vacationNumberSignal();
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);
});
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);
});
it('should update vacation number signal', () => {
const newVacations: VacDay[] = [
{
id: 'test-id',
type: SelectableDayType.CP,
numberOfDays: 5,
expiryDate: new Date(),
},
];
const newVacations = { cp: 5, rtt: 3, other: 2 };
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);
});
});