UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

70 lines (69 loc) 2.62 kB
/** * DevExtreme (esm/__internal/scheduler/m_utils_time_zone.test.js) * Version: 25.1.3 * Build date: Wed Jun 25 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { afterAll, beforeAll, describe, expect, it, jest } from "@jest/globals"; import { macroTaskArray } from "../scheduler/utils/index"; import timeZoneUtils from "./m_utils_time_zone"; import timeZoneList from "./timezones/timezone_list"; const defaultTimeZones = timeZoneList.value; describe("timezone utils", (() => { describe("cacheTimeZones / getTimeZonesCache", (() => { beforeAll((() => { timeZoneList.value = ["Etc/GMT+12", "Etc/GMT+11"] })); afterAll((() => { timeZoneList.value = defaultTimeZones })); it("should cache timezones only once and save into global variable", (async () => { const mock = jest.spyOn(macroTaskArray, "map"); expect(timeZoneUtils.getTimeZonesCache()).toEqual([]); await timeZoneUtils.cacheTimeZones(); expect(timeZoneUtils.getTimeZonesCache()).toEqual([{ id: "Etc/GMT+12", title: "(GMT -12:00) Etc - GMT+12" }, { id: "Etc/GMT+11", title: "(GMT -11:00) Etc - GMT+11" }]); await timeZoneUtils.cacheTimeZones(); await timeZoneUtils.cacheTimeZones(); expect(mock).toHaveBeenCalledTimes(1) })) })); describe("getTimeZones", (() => { it("should return timezones with offsets of default timezones list", (() => { timeZoneList.value = ["Etc/GMT+12", "Etc/GMT+11"]; expect(timeZoneUtils.getTimeZones(new Date("2025-04-23T10:00:00Z"))).toEqual([{ id: "Etc/GMT+12", title: "(GMT -12:00) Etc - GMT+12", offset: -12 }, { id: "Etc/GMT+11", title: "(GMT -11:00) Etc - GMT+11", offset: -11 }]); timeZoneList.value = defaultTimeZones })); it("should return timezones with offsets of custom timezones list", (() => { expect(timeZoneUtils.getTimeZones(new Date("2025-04-23T10:00:00Z"), ["Canada/Pacific"])).toEqual([{ id: "Canada/Pacific", title: "(GMT -07:00) Canada - Pacific", offset: -7 }]) })) })) }));