From a6956b3a014040bc092c56c5d8c10075deaacb35 Mon Sep 17 00:00:00 2001 From: manubo Date: Thu, 10 Oct 2019 14:55:21 +0200 Subject: [PATCH] Add tests for formatDuration --- src/js/utils/index.js | 2 +- test/utils/index.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/js/utils/index.js b/src/js/utils/index.js index 69c58a7..c207d9d 100644 --- a/src/js/utils/index.js +++ b/src/js/utils/index.js @@ -127,7 +127,7 @@ export const formatDuration = ( if (settingTimeTrackingHHMM) { const hours = Math.floor(durationInSeconds / 3600) const minutes = Math.floor((durationInSeconds % 3600) / 60) - const result = `${padCharsStart("0", 2, hours)}:${padCharsStart("0", 2, minutes)}` + const result = `${hours}:${padCharsStart("0", 2, minutes)}` if (!showSeconds) { return result } else { diff --git a/test/utils/index.test.js b/test/utils/index.test.js index 01fcffe..156bdf7 100644 --- a/test/utils/index.test.js +++ b/test/utils/index.test.js @@ -6,6 +6,7 @@ import { defaultTask, groupedProjectOptions, extractAndSetTag, + formatDuration, } from "../../src/js/utils" import { map, compose } from "lodash/fp" @@ -142,4 +143,21 @@ describe("utils", () => { expect(extractAndSetTag(changeset)).toEqual(changeset) }) }) + + describe("formatDuration", () => { + it("format with defaults", () => { + expect(formatDuration(3600)).toBe("1:00:00") + expect(formatDuration(3661)).toBe("1:01:01") + }) + + it("format without seconds", () => { + expect(formatDuration(3600, { showSeconds: false })).toBe("1:00") + expect(formatDuration(3661, { showSeconds: false })).toBe("1:01") + }) + + it("format in decimals", () => { + expect(formatDuration(3600, { settingTimeTrackingHHMM: false })).toBe("1.00") + expect(formatDuration(3661, { settingTimeTrackingHHMM: false })).toBe("1.02") + }) + }) })