Skip to content

Commit a3b3bdc

Browse files
committed
Updating tests to match what we expect the code to return now.
1 parent 80c6950 commit a3b3bdc

File tree

2 files changed

+62
-60
lines changed

2 files changed

+62
-60
lines changed

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-table/time-plannings-table.component.spec.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe('TimePlanningsTableComponent', () => {
171171
}
172172
};
173173

174-
expect(component.getCellClass(row, '0')).toBe('grey-background');
174+
expect(component.getCellClass(row, '0')).toBe('red-background');
175175
});
176176

177177
it('should return green-background for cell with work started and ended', () => {
@@ -274,7 +274,7 @@ describe('TimePlanningsTableComponent', () => {
274274
}
275275
};
276276

277-
expect(component.getCellClass(row, '0')).toBe('grey-background');
277+
expect(component.getCellClass(row, '0')).toBe('red-background');
278278
});
279279

280280
it('should return grey-background when message is set', () => {
@@ -316,42 +316,42 @@ describe('TimePlanningsTableComponent', () => {
316316
});
317317
});
318318

319-
describe('isInOlderThanToday', () => {
320-
it('should return false for null date', () => {
321-
expect(component.isInOlderThanToday(null as any)).toBe(false);
322-
});
323-
324-
it('should return false for undefined date', () => {
325-
expect(component.isInOlderThanToday(undefined as any)).toBe(false);
326-
});
327-
328-
it('should return true for date in the past', () => {
329-
const pastDate = new Date();
330-
pastDate.setDate(pastDate.getDate() - 5);
331-
expect(component.isInOlderThanToday(pastDate)).toBe(true);
332-
});
333-
334-
it('should return false for today', () => {
335-
const today = new Date();
336-
expect(component.isInOlderThanToday(today)).toBe(false);
337-
});
338-
339-
it('should return false for future date', () => {
340-
const futureDate = new Date();
341-
futureDate.setDate(futureDate.getDate() + 5);
342-
expect(component.isInOlderThanToday(futureDate)).toBe(false);
343-
});
344-
345-
it('should handle string dates', () => {
346-
const pastDateString = '2020-01-01';
347-
expect(component.isInOlderThanToday(pastDateString as any)).toBe(true);
348-
});
349-
350-
it('should return false for invalid date string', () => {
351-
const invalidDate = 'invalid-date';
352-
expect(component.isInOlderThanToday(invalidDate as any)).toBe(false);
353-
});
354-
});
319+
// describe('isInOlderThanToday', () => {
320+
// it('should return false for null date', () => {
321+
// expect(component.isInOlderThanToday(null as any)).toBe(false);
322+
// });
323+
//
324+
// it('should return false for undefined date', () => {
325+
// expect(component.isInOlderThanToday(undefined as any)).toBe(false);
326+
// });
327+
//
328+
// it('should return true for date in the past', () => {
329+
// const pastDate = new Date();
330+
// pastDate.setDate(pastDate.getDate() - 5);
331+
// expect(component.isInOlderThanToday(pastDate)).toBe(true);
332+
// });
333+
//
334+
// it('should return false for today', () => {
335+
// const today = new Date();
336+
// expect(component.isInOlderThanToday(today)).toBe(false);
337+
// });
338+
//
339+
// it('should return false for future date', () => {
340+
// const futureDate = new Date();
341+
// futureDate.setDate(futureDate.getDate() + 5);
342+
// expect(component.isInOlderThanToday(futureDate)).toBe(false);
343+
// });
344+
//
345+
// it('should handle string dates', () => {
346+
// const pastDateString = '2020-01-01';
347+
// expect(component.isInOlderThanToday(pastDateString as any)).toBe(true);
348+
// });
349+
//
350+
// it('should return false for invalid date string', () => {
351+
// const invalidDate = 'invalid-date';
352+
// expect(component.isInOlderThanToday(invalidDate as any)).toBe(false);
353+
// });
354+
// });
355355

356356
describe('getStopTimeDisplay', () => {
357357
it('should return empty string when startedAt is null', () => {

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-table/time-plannings-table.component.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,30 +205,32 @@ export class TimePlanningsTableComponent implements OnInit, OnChanges {
205205

206206
protected readonly JSON = JSON;
207207

208-
isInOlderThanToday(date: Date): boolean {
209-
// take the midnight of the date to compare ot today's midnight
210-
if (!date) {
211-
return false;
212-
}
213-
// Convert the date to a string to ensure it's in a valid format
214-
if (typeof date === 'string') {
215-
date = new Date(date);
216-
}
217-
// Compare the date with today's date
218-
if (isNaN(date.getTime())) {
219-
console.error('Invalid date:', date);
220-
return false; // or handle the error as needed
221-
}
222-
// Create a new Date object for today at midnight
223-
const todayMidnight = new Date();
224-
todayMidnight.setHours(0, 0, 0, 0); // Set to midnight
225-
const dateMidnight = new Date(date);
226-
dateMidnight.setHours(0, 0, 0, 0); // Set to midnight
227-
return dateMidnight <todayMidnight;
228-
}
208+
// isInOlderThanToday(date: Date): boolean {
209+
// // take the midnight of the date to compare ot today's midnight
210+
// if (!date) {
211+
// return false;
212+
// }
213+
// // Convert the date to a string to ensure it's in a valid format
214+
// if (typeof date === 'string') {
215+
// date = new Date(date);
216+
// }
217+
// // Compare the date with today's date
218+
// if (isNaN(date.getTime())) {
219+
// console.error('Invalid date:', date);
220+
// return false; // or handle the error as needed
221+
// }
222+
// // Create a new Date object for today at midnight
223+
// const todayMidnight = new Date();
224+
// todayMidnight.setHours(0, 0, 0, 0); // Set to midnight
225+
// const dateMidnight = new Date(date);
226+
// dateMidnight.setHours(0, 0, 0, 0); // Set to midnight
227+
// return dateMidnight <todayMidnight;
228+
// }
229229

230230
getStopTimeDisplay(startedAt: string | null, stoppedAt: string | null): string {
231-
if (!startedAt || !stoppedAt) return '';
231+
if (!startedAt || !stoppedAt) {
232+
return '';
233+
}
232234
const startDate = new Date(startedAt);
233235
const stopDate = new Date(stoppedAt);
234236
if (

0 commit comments

Comments
 (0)