mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 00:06:35 +00:00
Unit Test for shiftDateRange (#23324)
Unit Test for Pull 23228 Co-authored-by: Wendelin <12148533+wendevlin@users.noreply.github.com>
This commit is contained in:
parent
973fd51639
commit
b84e00b312
68
test/common/datetime/shift_date_range.test.ts
Normal file
68
test/common/datetime/shift_date_range.test.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { shiftDateRange } from "../../../src/common/datetime/calc_date";
|
||||
import {
|
||||
NumberFormat,
|
||||
TimeFormat,
|
||||
FirstWeekday,
|
||||
DateFormat,
|
||||
TimeZone,
|
||||
} from "../../../src/data/translation";
|
||||
|
||||
const mockConfig = {
|
||||
time_zone: "America/New_York",
|
||||
};
|
||||
|
||||
describe("shiftDateRange", () => {
|
||||
const locale = {
|
||||
language: "en",
|
||||
number_format: NumberFormat.language,
|
||||
time_format: TimeFormat.language,
|
||||
date_format: DateFormat.language,
|
||||
time_zone: TimeZone.local,
|
||||
first_weekday: FirstWeekday.language,
|
||||
};
|
||||
|
||||
it("shifts date range forward month", () => {
|
||||
const startDate = new Date(2024, 0, 1);
|
||||
const endDate = new Date(2024, 0, 31);
|
||||
const result = shiftDateRange(startDate, endDate, true, locale, mockConfig);
|
||||
expect(result.start).toEqual(new Date(2024, 1, 1));
|
||||
expect(result.end).toEqual(new Date(2024, 1, 29, 23, 59, 59, 999));
|
||||
});
|
||||
|
||||
it("shifts date range backward month", () => {
|
||||
const startDate = new Date(2025, 0, 1);
|
||||
const endDate = new Date(2025, 0, 31);
|
||||
const result = shiftDateRange(
|
||||
startDate,
|
||||
endDate,
|
||||
false,
|
||||
locale,
|
||||
mockConfig
|
||||
);
|
||||
expect(result.start).toEqual(new Date(2024, 11, 1));
|
||||
expect(result.end).toEqual(new Date(2024, 11, 31, 23, 59, 59, 999));
|
||||
});
|
||||
|
||||
it("shifts date range forward day", () => {
|
||||
const startDate = new Date(2025, 0, 1);
|
||||
const endDate = new Date(new Date(2025, 0, 1, 23, 59, 59, 999));
|
||||
const result = shiftDateRange(startDate, endDate, true, locale, mockConfig);
|
||||
expect(result.start).toEqual(new Date(2025, 0, 2));
|
||||
expect(result.end).toEqual(new Date(2025, 0, 2, 23, 59, 59, 999));
|
||||
});
|
||||
|
||||
it("shifts date range backward day", () => {
|
||||
const startDate = new Date(2025, 0, 2);
|
||||
const endDate = new Date(new Date(2025, 0, 2, 23, 59, 59, 999));
|
||||
const result = shiftDateRange(
|
||||
startDate,
|
||||
endDate,
|
||||
false,
|
||||
locale,
|
||||
mockConfig
|
||||
);
|
||||
expect(result.start).toEqual(new Date(2025, 0, 1));
|
||||
expect(result.end).toEqual(new Date(2025, 0, 1, 23, 59, 59, 999));
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user