|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | + |
| 3 | +import convertToNewDurationType, { MINUTES_IN_HOUR, MINUTES_IN_DAY, HOURS_IN_DAY } from "./convertToNewDurationType"; |
| 4 | + |
| 5 | +describe("convertToNewDurationType", () => { |
| 6 | + describe("identity conversions", () => { |
| 7 | + it("should return the same value when converting minutes to minutes", () => { |
| 8 | + expect(convertToNewDurationType("minutes", "minutes", 120)).toBe(120); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should return the same value when converting hours to hours", () => { |
| 12 | + expect(convertToNewDurationType("hours", "hours", 5)).toBe(5); |
| 13 | + }); |
| 14 | + |
| 15 | + it("should return the same value when converting days to days", () => { |
| 16 | + expect(convertToNewDurationType("days", "days", 3)).toBe(3); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + describe("minutes to other types", () => { |
| 21 | + it("should convert minutes to hours", () => { |
| 22 | + expect(convertToNewDurationType("minutes", "hours", 120)).toBe(2); |
| 23 | + expect(convertToNewDurationType("minutes", "hours", 60)).toBe(1); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should convert minutes to days", () => { |
| 27 | + expect(convertToNewDurationType("minutes", "days", 2880)).toBe(2); |
| 28 | + expect(convertToNewDurationType("minutes", "days", 1440)).toBe(1); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe("hours to other types", () => { |
| 33 | + it("should convert hours to minutes", () => { |
| 34 | + expect(convertToNewDurationType("hours", "minutes", 2)).toBe(120); |
| 35 | + expect(convertToNewDurationType("hours", "minutes", 1)).toBe(60); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should convert hours to days", () => { |
| 39 | + expect(convertToNewDurationType("hours", "days", 24)).toBe(1); |
| 40 | + expect(convertToNewDurationType("hours", "days", 48)).toBe(2); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe("days to other types", () => { |
| 45 | + it("should convert days to minutes", () => { |
| 46 | + expect(convertToNewDurationType("days", "minutes", 1)).toBe(1440); |
| 47 | + expect(convertToNewDurationType("days", "minutes", 2)).toBe(2880); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should convert days to hours", () => { |
| 51 | + expect(convertToNewDurationType("days", "hours", 1)).toBe(24); |
| 52 | + expect(convertToNewDurationType("days", "hours", 2)).toBe(48); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe("rounding", () => { |
| 57 | + it("should round up fractional results with Math.ceil", () => { |
| 58 | + // 90 minutes = 1.5 hours, should ceil to 2 |
| 59 | + expect(convertToNewDurationType("minutes", "hours", 90)).toBe(2); |
| 60 | + // 100 minutes = 0.069 days, should ceil to 1 |
| 61 | + expect(convertToNewDurationType("minutes", "days", 100)).toBe(1); |
| 62 | + // 5 hours = 0.208 days, should ceil to 1 |
| 63 | + expect(convertToNewDurationType("hours", "days", 5)).toBe(1); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe("zero values", () => { |
| 68 | + it("should handle zero correctly for all conversions", () => { |
| 69 | + expect(convertToNewDurationType("minutes", "hours", 0)).toBe(0); |
| 70 | + expect(convertToNewDurationType("minutes", "days", 0)).toBe(0); |
| 71 | + expect(convertToNewDurationType("hours", "minutes", 0)).toBe(0); |
| 72 | + expect(convertToNewDurationType("hours", "days", 0)).toBe(0); |
| 73 | + expect(convertToNewDurationType("days", "minutes", 0)).toBe(0); |
| 74 | + expect(convertToNewDurationType("days", "hours", 0)).toBe(0); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + describe("exported constants", () => { |
| 79 | + it("should export correct constant values", () => { |
| 80 | + expect(MINUTES_IN_HOUR).toBe(60); |
| 81 | + expect(MINUTES_IN_DAY).toBe(1440); |
| 82 | + expect(HOURS_IN_DAY).toBe(24); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments