75 lines
1.8 KiB
TypeScript
Executable File
75 lines
1.8 KiB
TypeScript
Executable File
import { describe, it, expect } from "vitest";
|
|
import {
|
|
hasMeaningfulReflectionContent,
|
|
shouldAwardReflectionXp,
|
|
} from "../reflection-utils";
|
|
|
|
describe("hasMeaningfulReflectionContent", () => {
|
|
it("returns false for all empty fields", () => {
|
|
expect(
|
|
hasMeaningfulReflectionContent({
|
|
wentWell: "",
|
|
learned: "",
|
|
improveTomorrow: "",
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns false for whitespace-only fields", () => {
|
|
expect(
|
|
hasMeaningfulReflectionContent({
|
|
wentWell: " ",
|
|
learned: "\t",
|
|
improveTomorrow: " \n ",
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns true when any field has content", () => {
|
|
expect(
|
|
hasMeaningfulReflectionContent({
|
|
wentWell: "",
|
|
learned: "Read for 20 minutes",
|
|
improveTomorrow: "",
|
|
})
|
|
).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("shouldAwardReflectionXp", () => {
|
|
const empty = { wentWell: "", learned: "", improveTomorrow: "" };
|
|
const filled = {
|
|
wentWell: "Good day",
|
|
learned: "Something new",
|
|
improveTomorrow: "Sleep earlier",
|
|
};
|
|
|
|
it("does not award for empty content", () => {
|
|
expect(shouldAwardReflectionXp(null, empty)).toBe(false);
|
|
});
|
|
|
|
it("does not award for whitespace-only content", () => {
|
|
expect(
|
|
shouldAwardReflectionXp(null, {
|
|
wentWell: " ",
|
|
learned: "",
|
|
improveTomorrow: "",
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
it("awards on first meaningful save", () => {
|
|
expect(shouldAwardReflectionXp(null, filled)).toBe(true);
|
|
});
|
|
|
|
it("does not award when updating already meaningful reflection", () => {
|
|
expect(shouldAwardReflectionXp(filled, { ...filled, learned: "More" })).toBe(
|
|
false
|
|
);
|
|
});
|
|
|
|
it("awards when empty row exists and user adds meaningful content", () => {
|
|
expect(shouldAwardReflectionXp(empty, filled)).toBe(true);
|
|
});
|
|
});
|