From a5893f0bf9fdff47ee7202e7824b7b64629dffea Mon Sep 17 00:00:00 2001 From: Brice Bauer Date: Mon, 22 Jul 2024 14:02:27 -0400 Subject: [PATCH] Add tests for DeviceHoursPipe --- .../src/app/shared/device-hours.pipe.spec.ts | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 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 cd9f1bc..86b3aa6 100644 --- a/webapp/frontend/src/app/shared/device-hours.pipe.spec.ts +++ b/webapp/frontend/src/app/shared/device-hours.pipe.spec.ts @@ -1,9 +1,54 @@ -import { DeviceHoursPipe } from './device-hours.pipe'; +import { DeviceHoursPipe } from "./device-hours.pipe"; - -describe('DeviceHoursPipe', () => { - it('create an instance', () => { +describe("DeviceHoursPipe", () => { + it("create an instance", () => { const pipe = new DeviceHoursPipe(); expect(pipe).toBeTruthy(); }); + + describe("#transform", () => { + const testCases = [ + { + input: 12345, + configuration: "device_hours", + result: "12345 hours", + }, + { + input: 15273, + configuration: "humanize", + result: "1 year, 8 months, 3 weeks, 6 days, 15 hours", + }, + { + input: 48, + configuration: null, + result: "2 days", + }, + { + input: 168, + configuration: "scrutiny", + result: "1 week", + }, + { + input: null, + configuration: "device_hours", + result: "null hours", + }, + { + input: null, + configuration: "humanize", + result: "0 seconds", + }, + ]; + + testCases.forEach((test, index) => { + it(`should format input ${test.input} with configuration '${ + test.configuration + }' (testcase: ${index + 1})`, () => { + // test + const pipe = new DeviceHoursPipe(); + const formatted = pipe.transform(test.input, test.configuration); + expect(formatted).toEqual(test.result); + }); + }); + }); });