feat: migrate DateField and shared date input group
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
CalendarDate,
|
||||
CalendarDateTime,
|
||||
parseZonedDateTime,
|
||||
toCalendar,
|
||||
PersianCalendar,
|
||||
} from "@internationalized/date";
|
||||
import {
|
||||
dateForLocale,
|
||||
copyDateValue,
|
||||
dateValueKey,
|
||||
sameDateValue,
|
||||
copyDateValues,
|
||||
serializeDateValue,
|
||||
calendarDayState,
|
||||
copyDateRange,
|
||||
calendarRangeStatus,
|
||||
} from "../packages/vue/src/components/date/value";
|
||||
const day = new CalendarDate(2024, 2, 29);
|
||||
describe("private calendar date boundary", () => {
|
||||
it("copies dates without mutating caller or losing date class", () => {
|
||||
const copy = copyDateValue(day);
|
||||
expect(copy).not.toBe(day);
|
||||
expect(copy).toBeInstanceOf(CalendarDate);
|
||||
expect(copy.add({ years: 1 }).toString()).toBe("2025-02-28");
|
||||
expect(day.toString()).toBe("2024-02-29");
|
||||
});
|
||||
it("keeps null/undefined empty and distinguishes date from midnight datetime", () => {
|
||||
expect(copyDateValue(null)).toBeNull();
|
||||
expect(copyDateValue(undefined)).toBeUndefined();
|
||||
expect(sameDateValue(null, undefined)).toBe(true);
|
||||
expect(sameDateValue(day, new CalendarDateTime(2024, 2, 29))).toBe(false);
|
||||
});
|
||||
it("retains sub-minute precision independently from display granularity", () => {
|
||||
const value = new CalendarDateTime(2024, 2, 29, 13, 14, 15, 123);
|
||||
expect(serializeDateValue(copyDateValue(value))).toBe(
|
||||
"2024-02-29T13:14:15.123",
|
||||
);
|
||||
});
|
||||
it("retains DST offset, zone and wall-clock value", () => {
|
||||
const value = parseZonedDateTime(
|
||||
"2024-03-10T01:30-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const copy = copyDateValue(value);
|
||||
expect(copy.timeZone).toBe(value.timeZone);
|
||||
expect(copy.offset).toBe(-28800000);
|
||||
expect(copy.add({ hours: 1 }).hour).toBe(3);
|
||||
expect(serializeDateValue(copy)).toContain("-08:00[America/Los_Angeles]");
|
||||
});
|
||||
it("keeps alternate calendar identity even when ISO serialization is equal", () => {
|
||||
const persian = toCalendar(day, new PersianCalendar());
|
||||
expect(persian.toString()).toBe(day.toString());
|
||||
expect(sameDateValue(day, persian)).toBe(false);
|
||||
expect(copyDateValue(persian).calendar.identifier).toBe("persian");
|
||||
});
|
||||
it("deduplicates copied values without sharing mutable date objects", () => {
|
||||
const values = copyDateValues([day, day.copy(), day.add({ days: 1 })]);
|
||||
expect(values).toHaveLength(2);
|
||||
expect(values[0]).not.toBe(day);
|
||||
expect(dateValueKey(values[0])).toBe(dateValueKey(day));
|
||||
});
|
||||
it("keeps unavailable distinct from disabled calendar days", () => {
|
||||
expect(calendarDayState(day, { isDateUnavailable: () => true })).toEqual({
|
||||
isDisabled: false,
|
||||
isUnavailable: true,
|
||||
isSelectable: false,
|
||||
});
|
||||
expect(calendarDayState(day, { isDateDisabled: () => true })).toEqual({
|
||||
isDisabled: true,
|
||||
isUnavailable: false,
|
||||
isSelectable: false,
|
||||
});
|
||||
});
|
||||
it("compares calendar bounds by local day including equivalent alternate calendars", () => {
|
||||
expect(
|
||||
calendarDayState(toCalendar(day, new PersianCalendar()), {
|
||||
minValue: day,
|
||||
maxValue: day,
|
||||
}).isSelectable,
|
||||
).toBe(true);
|
||||
expect(
|
||||
calendarDayState(day, { minValue: day.add({ days: 1 }) }).isDisabled,
|
||||
).toBe(true);
|
||||
});
|
||||
it("copies ranges and preserves incomplete drafts", () => {
|
||||
const range = copyDateRange({ start: day, end: null });
|
||||
expect(range.start).not.toBe(day);
|
||||
expect(calendarRangeStatus(range)).toBe("incomplete");
|
||||
expect(calendarRangeStatus({ start: null, end: null })).toBe("empty");
|
||||
expect(
|
||||
calendarRangeStatus({ start: day, end: day.subtract({ days: 1 }) }),
|
||||
).toBe("inverted");
|
||||
expect(calendarRangeStatus({ start: day, end: day })).toBe("valid");
|
||||
});
|
||||
});
|
||||
|
||||
it("converts the calendar for locale display without altering the incoming model or instant", () => {
|
||||
const original = parseZonedDateTime(
|
||||
"2024-03-10T01:30-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const indian = dateForLocale(original, "hi-IN-u-ca-indian");
|
||||
expect(indian.calendar.identifier).toBe("indian");
|
||||
expect(indian.timeZone).toBe(original.timeZone);
|
||||
expect(indian.toString()).toBe(original.toString());
|
||||
expect(original.calendar.identifier).toBe("gregory");
|
||||
});
|
||||
Reference in New Issue
Block a user