Initial Commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { DATE_FORMAT_PRESETS, PRESET_MAP, resolvePreset } from "./presets.js";
|
||||
|
||||
describe("PRESET_MAP", () => {
|
||||
it("contains all 8 entries", { timeout: 5000 }, () => {
|
||||
const keys = Object.keys(PRESET_MAP).sort();
|
||||
expect(keys).toEqual(
|
||||
[
|
||||
"date-long",
|
||||
"date-short",
|
||||
"full",
|
||||
"long",
|
||||
"medium",
|
||||
"short",
|
||||
"time-long",
|
||||
"time-short",
|
||||
].sort()
|
||||
);
|
||||
});
|
||||
|
||||
it("short includes year, month, day, hour, minute", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
expect(PRESET_MAP.short).toMatchObject({
|
||||
year: "numeric",
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
});
|
||||
});
|
||||
|
||||
it("full includes weekday + timeZoneName long", { timeout: 5000 }, () => {
|
||||
expect(PRESET_MAP.full).toMatchObject({
|
||||
weekday: "long",
|
||||
timeZoneName: "long",
|
||||
});
|
||||
});
|
||||
|
||||
it("date-short omits time fields", { timeout: 5000 }, () => {
|
||||
const keys = Object.keys(PRESET_MAP["date-short"]);
|
||||
expect(keys).not.toContain("hour");
|
||||
expect(keys).not.toContain("minute");
|
||||
});
|
||||
});
|
||||
|
||||
describe("DATE_FORMAT_PRESETS", () => {
|
||||
it("lists all 8 preset names", { timeout: 5000 }, () => {
|
||||
expect(DATE_FORMAT_PRESETS).toHaveLength(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolvePreset", () => {
|
||||
it("returns undefined for undefined options", { timeout: 5000 }, () => {
|
||||
expect(resolvePreset()).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns rest options when no preset present", { timeout: 5000 }, () => {
|
||||
const r = resolvePreset({ year: "numeric" });
|
||||
expect(r).toMatchObject({ year: "numeric" });
|
||||
});
|
||||
|
||||
it("merges preset map with rest options", { timeout: 5000 }, () => {
|
||||
const r = resolvePreset({ preset: "short", month: "long" });
|
||||
expect(r).toMatchObject({
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
});
|
||||
});
|
||||
|
||||
it("strips locale from rest options", { timeout: 5000 }, () => {
|
||||
const r = resolvePreset({ preset: "short", locale: "en-GB" });
|
||||
expect(r).not.toHaveProperty("locale");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user