Adjust null input response, and tests
This commit is contained in:
@@ -31,19 +31,17 @@ describe("DeviceHoursPipe", () => {
|
|||||||
{
|
{
|
||||||
input: null,
|
input: null,
|
||||||
configuration: "device_hours",
|
configuration: "device_hours",
|
||||||
result: "null hours",
|
result: "Unknown",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: null,
|
input: null,
|
||||||
configuration: "humanize",
|
configuration: "humanize",
|
||||||
result: "0 seconds",
|
result: "Unknown",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
testCases.forEach((test, index) => {
|
testCases.forEach((test, index) => {
|
||||||
it(`should format input ${test.input} with configuration '${
|
it(`format input '${test.input}' with configuration '${test.configuration}', should be '${test.result}' (testcase: ${index + 1})`, () => {
|
||||||
test.configuration
|
|
||||||
}' (testcase: ${index + 1})`, () => {
|
|
||||||
// test
|
// test
|
||||||
const pipe = new DeviceHoursPipe();
|
const pipe = new DeviceHoursPipe();
|
||||||
const formatted = pipe.transform(test.input, test.configuration);
|
const formatted = pipe.transform(test.input, test.configuration);
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import humanizeDuration from 'humanize-duration';
|
|||||||
@Pipe({ name: 'deviceHours' })
|
@Pipe({ name: 'deviceHours' })
|
||||||
export class DeviceHoursPipe implements PipeTransform {
|
export class DeviceHoursPipe implements PipeTransform {
|
||||||
static format(hoursOfRunTime: number, unit: string, humanizeConfig: object): string {
|
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 `${hoursOfRunTime} hours`;
|
||||||
}
|
}
|
||||||
return humanizeDuration(hoursOfRunTime * 60 * 60 * 1000, humanizeConfig);
|
return humanizeDuration(hoursOfRunTime * 60 * 60 * 1000, humanizeConfig);
|
||||||
|
|||||||
Reference in New Issue
Block a user