Add tests for formatDuration
This commit is contained in:
@@ -127,7 +127,7 @@ export const formatDuration = (
|
|||||||
if (settingTimeTrackingHHMM) {
|
if (settingTimeTrackingHHMM) {
|
||||||
const hours = Math.floor(durationInSeconds / 3600)
|
const hours = Math.floor(durationInSeconds / 3600)
|
||||||
const minutes = Math.floor((durationInSeconds % 3600) / 60)
|
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) {
|
if (!showSeconds) {
|
||||||
return result
|
return result
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
defaultTask,
|
defaultTask,
|
||||||
groupedProjectOptions,
|
groupedProjectOptions,
|
||||||
extractAndSetTag,
|
extractAndSetTag,
|
||||||
|
formatDuration,
|
||||||
} from "../../src/js/utils"
|
} from "../../src/js/utils"
|
||||||
import { map, compose } from "lodash/fp"
|
import { map, compose } from "lodash/fp"
|
||||||
|
|
||||||
@@ -142,4 +143,21 @@ describe("utils", () => {
|
|||||||
expect(extractAndSetTag(changeset)).toEqual(changeset)
|
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")
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user