test(dayjs): relocate dayjs tests into commons

This commit is contained in:
Elian Doran 2025-12-03 20:54:35 +02:00
parent af2f6246e8
commit 94d015789d
No known key found for this signature in database
2 changed files with 21 additions and 31 deletions

View File

@ -59,7 +59,7 @@ describe("Script", () => {
}); });
}); });
describe("dayjs", () => { describe("dayjs in backend scripts", () => {
const scriptNote = note("dayjs", { const scriptNote = note("dayjs", {
type: "code", type: "code",
mime: "application/javascript;env=backend", mime: "application/javascript;env=backend",
@ -74,7 +74,7 @@ describe("Script", () => {
}); });
}); });
it("dayjs is-same-or-before", () => { it("dayjs is-same-or-before plugin exists", () => {
cls.init(() => { cls.init(() => {
const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-01").isSameOrBefore(api.dayjs("2023-10-02"));`); const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-01").isSameOrBefore(api.dayjs("2023-10-02"));`);
expect(bundle).toBeDefined(); expect(bundle).toBeDefined();
@ -82,33 +82,5 @@ describe("Script", () => {
expect(result).toBe(true); expect(result).toBe(true);
}); });
}); });
it("dayjs is-same-or-after", () => {
cls.init(() => {
const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-02").isSameOrAfter(api.dayjs("2023-10-01"));`);
expect(bundle).toBeDefined();
const result = executeBundle(bundle!);
expect(result).toBe(true);
});
});
it("dayjs is-between", () => {
cls.init(() => {
const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-02").isBetween(api.dayjs("2023-10-01"), api.dayjs("2023-10-03"));`);
expect(bundle).toBeDefined();
const result = executeBundle(bundle!);
expect(result).toBe(true);
});
});
// advanced format
it("dayjs advanced format", () => {
cls.init(() => {
const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-01").format("Q");`);
expect(bundle).toBeDefined();
const result = executeBundle(bundle!);
expect(result).not.toBe("Q");
});
});
}); });
}); });

View File

@ -1,5 +1,5 @@
import { LOCALES } from "./i18n.js"; import { LOCALES } from "./i18n.js";
import { DAYJS_LOADER } from "./dayjs.js"; import { DAYJS_LOADER, dayjs } from "./dayjs.js";
describe("dayjs", () => { describe("dayjs", () => {
it("all dayjs locales are valid", async () => { it("all dayjs locales are valid", async () => {
@ -10,4 +10,22 @@ describe("dayjs", () => {
await dayjsLoader(); await dayjsLoader();
} }
}); });
describe("Plugins", () => {
it("is-same-or-before is available", () => {
expect(dayjs("2023-10-01").isSameOrBefore(dayjs("2023-10-02"))).toBe(true);
});
it("is-same-or-after is available", () => {
expect(dayjs("2023-10-02").isSameOrAfter(dayjs("2023-10-01"))).toBe(true);
});
it("is-between is available", () => {
expect(dayjs("2023-10-02").isBetween(dayjs("2023-10-01"), dayjs("2023-10-03"))).toBe(true);
});
it("advanced format is available", () => {
expect(dayjs("2023-10-01").format("Q")).not.toBe("Q");
});
});
}); });