Skip to content

Commit

Permalink
Readd unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
malte-laukoetter committed Dec 8, 2023
1 parent 0665bac commit e6b13c6
Show file tree
Hide file tree
Showing 5 changed files with 656 additions and 5 deletions.
10 changes: 6 additions & 4 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ fileignoreconfig:
- filename: SECURITY.md
checksum: b1743150cdd537be3a66f5308f887d130f0f320ab21628b63713808090a84e3f
- filename: app/routes/login.tsx
checksum: 71439f7a400334caeb550ee897753dec4b8d36ded11952b3b81594b745aaa18b
allowed_patterns: [password]
- filename: app/components/troi.client.tsx
checksum: f8a42a7eaf66377662298793bb806905a807dd5ab2388e629345db80029197e4
allowed_patterns: [password, /wiki/spaces/DIGITALSER/pages/\d+]
- filename: app/routes/projects.tsx
checksum: 68dde5f568d7d4a01c207d5bc6fb95976b1bfe469ad7614ad71241fce8820130
allowed_patterns: [password]
- filename: app/troi/useTroi.hook.tsx
checksum: a0139b548ba37a46ac023bef5f71a6b9a41aa4486a5b59dd97fdc3408c2b7972
allowed_patterns: [password]
- filename: tests/unit/transformCalendarEvents.test.ts
allowed_patterns: [key]
version: ""
scopeconfig:
- scope: node
Expand Down
2 changes: 1 addition & 1 deletion globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare module "troi-library" {
};
export type CalenderEventType = "R" | "H" | "G" | "P" | "T";
export type CalenderEvent = {
id: number;
id: string;
startDate: string;
endDate: string;
subject: string;
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/calendarEventUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
getDescriptionForEventType,
getItemForEventType,
} from "~/utils/calendarEventUtils";

test("getItemForEventType should return correct icons", () => {
expect(getItemForEventType("Holiday")).toBe("wb_sunny");
expect(getItemForEventType("Training")).toBe("school");
expect(getItemForEventType("PaidVacation")).toBe("beach_access");
expect(getItemForEventType("UnpaidVacation")).toBe("beach_access");
expect(getItemForEventType("CompensatoryTimeOff")).toBe("beach_access");
expect(getItemForEventType("Sick")).toBe("sick");
expect(getItemForEventType("NonExistentEventType" as any)).toBe("close");
});

test("getDescriptionForEventType should return correct descriptions", () => {
expect(getDescriptionForEventType("Holiday")).toBe(
"Public holiday, working impossible",
);
expect(getDescriptionForEventType("Training")).toBe("Learning");
expect(getDescriptionForEventType("PaidVacation")).toBe(
"You are on paid vacation",
);
expect(getDescriptionForEventType("UnpaidVacation")).toBe(
"You are on unpaid vacation",
);
expect(getDescriptionForEventType("CompensatoryTimeOff")).toBe(
"Looks like you had some over hours",
);
expect(getDescriptionForEventType("Sick")).toBe("Sick leave");
expect(getDescriptionForEventType("NonExistentEventType" as any)).toBe(
"Unknown",
);
});
88 changes: 88 additions & 0 deletions tests/unit/timeConverter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
convertFloatTimeToHHMM,
convertTimeStringToFloat,
} from "~/utils/timeConverter";

describe("convertFloatTimeToHHMM", () => {
test("1 returns 1:00", () => {
expect(convertFloatTimeToHHMM(1)).toBe("1:00");
});

test("5 returns 5:00", () => {
expect(convertFloatTimeToHHMM(5)).toBe("5:00");
});

test("1.5 returns 1:30", () => {
expect(convertFloatTimeToHHMM(1.5)).toBe("1:30");
});

test("0.2 returns 0:20", () => {
expect(convertFloatTimeToHHMM(0.2)).toBe("0:12");
});

test("0.33333 returns 0:20", () => {
expect(convertFloatTimeToHHMM(0.33333)).toBe("0:20");
});

test("2.05 returns 2:03", () => {
expect(convertFloatTimeToHHMM(2.05)).toBe("2:03");
});

test("0.0166 returns 0:01", () => {
expect(convertFloatTimeToHHMM(0.0166)).toBe("0:01");
});
});

describe("convertTimeStringToFloat", () => {
test("1:00 returns 1", () => {
expect(convertTimeStringToFloat("1:00")).toBe(1);
});

test("5:00 returns 5", () => {
expect(convertTimeStringToFloat("5:00")).toBe(5);
});

test("1:30 returns 1.5", () => {
expect(convertTimeStringToFloat("1:30")).toBe(1.5);
});

test("0:20 returns 0.2", () => {
expect(convertTimeStringToFloat("0:12")).toBe(0.2);
});

test("0:20 returns 0.33333", () => {
expect(convertTimeStringToFloat("0:20")).toBe(1 / 3);
});

test("2:03 returns 2.05", () => {
expect(convertTimeStringToFloat("2:03")).toBe(2.05);
});

test("0:01 returns 0.0166", () => {
expect(convertTimeStringToFloat("0:01")).toBe(1 / 60);
});

test("1:3 returns 1.5", () => {
expect(convertTimeStringToFloat("1:3")).toBe(1.5);
});

test("0,5 returns 0.5", () => {
expect(convertTimeStringToFloat("0,5")).toBe(0.5);
});

test("1,34563 returns 1.34563", () => {
expect(convertTimeStringToFloat("1,34563")).toBe(1.34563);
});

test("21,34563 returns 21.34563", () => {
expect(convertTimeStringToFloat("21,34563")).toBe(21.34563);
});

test("1.34563 returns 1.34563", () => {
expect(convertTimeStringToFloat("1.34563")).toBe(1.34563);
});

test("21.34563 returns 21.34563", () => {
expect(convertTimeStringToFloat("21.34563")).toBe(21.34563);
});
});
Loading

0 comments on commit e6b13c6

Please sign in to comment.