From c5943a1ca4d07789235797dc1d0b59b03e10ab38 Mon Sep 17 00:00:00 2001 From: Brice Bauer Date: Thu, 25 Jul 2024 15:40:28 -0400 Subject: [PATCH] Adjust null input response, and tests --- webapp/frontend/src/app/shared/device-hours.pipe.spec.ts | 8 +++----- webapp/frontend/src/app/shared/device-hours.pipe.ts | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/webapp/frontend/src/app/shared/device-hours.pipe.spec.ts b/webapp/frontend/src/app/shared/device-hours.pipe.spec.ts index 86b3aa6..cabad90 100644 --- a/webapp/frontend/src/app/shared/device-hours.pipe.spec.ts +++ b/webapp/frontend/src/app/shared/device-hours.pipe.spec.ts @@ -31,19 +31,17 @@ describe("DeviceHoursPipe", () => { { input: null, configuration: "device_hours", - result: "null hours", + result: "Unknown", }, { input: null, configuration: "humanize", - result: "0 seconds", + result: "Unknown", }, ]; testCases.forEach((test, index) => { - it(`should format input ${test.input} with configuration '${ - test.configuration - }' (testcase: ${index + 1})`, () => { + it(`format input '${test.input}' with configuration '${test.configuration}', should be '${test.result}' (testcase: ${index + 1})`, () => { // test const pipe = new DeviceHoursPipe(); const formatted = pipe.transform(test.input, test.configuration); diff --git a/webapp/frontend/src/app/shared/device-hours.pipe.ts b/webapp/frontend/src/app/shared/device-hours.pipe.ts index f6b5e1f..1170c8a 100644 --- a/webapp/frontend/src/app/shared/device-hours.pipe.ts +++ b/webapp/frontend/src/app/shared/device-hours.pipe.ts @@ -4,7 +4,10 @@ import humanizeDuration from 'humanize-duration'; @Pipe({ name: 'deviceHours' }) export class DeviceHoursPipe implements PipeTransform { static format(hoursOfRunTime: number, unit: string, humanizeConfig: object): string { - if (unit === 'device_hours') { + if (hoursOfRunTime === null) { + return 'Unknown'; + } + if (unit === 'device_hours') { return `${hoursOfRunTime} hours`; } return humanizeDuration(hoursOfRunTime * 60 * 60 * 1000, humanizeConfig);