47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { afterEach, describe, expect, it } from "vitest";
|
|
import {
|
|
CREATE_FLOW_LAST_PUBLISHED_KEY,
|
|
clearLastPublishedRule,
|
|
finishedAtIso,
|
|
writeLastPublishedRule,
|
|
} from "../../lib/create/lastPublishedRule";
|
|
|
|
describe("finishedAtIso", () => {
|
|
it("normalizes strings and dates", () => {
|
|
expect(finishedAtIso("2026-11-08T12:00:00.000Z")).toBe(
|
|
"2026-11-08T12:00:00.000Z",
|
|
);
|
|
expect(finishedAtIso(new Date("2026-11-08T12:00:00.000Z"))).toBe(
|
|
"2026-11-08T12:00:00.000Z",
|
|
);
|
|
});
|
|
|
|
it("returns undefined for empty or invalid values", () => {
|
|
expect(finishedAtIso("")).toBeUndefined();
|
|
expect(finishedAtIso("not-a-date")).toBeUndefined();
|
|
expect(finishedAtIso(null)).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("clearLastPublishedRule", () => {
|
|
afterEach(() => {
|
|
sessionStorage.removeItem(CREATE_FLOW_LAST_PUBLISHED_KEY);
|
|
});
|
|
|
|
it("removes the stored finished Rule", () => {
|
|
writeLastPublishedRule({
|
|
id: "rule-1",
|
|
title: "Garden coop",
|
|
document: { sections: [] },
|
|
});
|
|
expect(sessionStorage.getItem(CREATE_FLOW_LAST_PUBLISHED_KEY)).not.toBeNull();
|
|
clearLastPublishedRule();
|
|
expect(sessionStorage.getItem(CREATE_FLOW_LAST_PUBLISHED_KEY)).toBeNull();
|
|
});
|
|
|
|
it("does nothing when the key is already missing", () => {
|
|
expect(() => clearLastPublishedRule()).not.toThrow();
|
|
expect(sessionStorage.getItem(CREATE_FLOW_LAST_PUBLISHED_KEY)).toBeNull();
|
|
});
|
|
});
|