Add tests for formatDuration

This commit is contained in:
manubo
2019-10-10 14:55:21 +02:00
parent 6de449ed85
commit a6956b3a01
2 changed files with 19 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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")
})
})
})