Witam, mam problem napisanie unit testu dla funkcji loadTime,. Funkcja ta przerabia mape (timeTable) która: wygląda tak:
na tablice result która składa sie z (0,1) - od indexu 3-5(03:00-05:00) to są jedynki i i od 12-14(12:00-14:00) to tez są jedynki dla reszty to są 0. I wtedy teblica result jest przypisywana do tablicy rowTable. Jak ja mogę napisać do tego unit test?
rowTable wyglada tak:
rowTable: Row[] = [
{ name: this.allDays.monday, items: new Array(24).fill(1), active: true },
{ name: this.allDays.tuesday, items: new Array(24).fill(1), active: true },
{ name: this.allDays.wednesday, items: new Array(24).fill(1), active: true },
{ name: this.allDays.thursday, items: new Array(24).fill(1), active: true },
{ name: this.allDays.friday, items: new Array(24).fill(1), active: true },
{ name: this.allDays.saturday, items: new Array(24).fill(1), active: true },
{ name: this.allDays.sunday, items: new Array(24).fill(1), active: true }
];
a funkcja docelowa: loadTime
loadingTime(): void {
if (this.inputObject?.timeTable) {
let result = [...this.inputObject.timeTable].reduce((r, [key, value], i) => {
r[i] = Array(24).fill(0);
value.forEach(o => {
let start = getHours(o.from);
const end = getHours(o.to);
while (start <= end) {
r[i][start] = 1;
start++;
}
})
return r;
}, []);
this.rowTable.forEach((el, i) => {
el.items = result[i];
el.active = false;
})
}
}
Kombinowalem jakos tak:
it("should loading Time"), () => {
const timetableMock = new Map<number, Array<HourScheduleDefinitionModel>>()
timetableMock.set(0, [{ from: '00:00', to: '23:00' }]);
component.loadingTime = () => {};
const onSaveSpy = spyOn(component, "loadingTime")
component.loadingTime();
expect(onSaveSpy).toEqual([........]);
}
Ale mam wrażenie, ze robie to bez sensu. Prosze o pomoc