devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
258 lines (257 loc) • 8.9 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/utils/options/utils.test.js)
* Version: 25.2.5
* Build date: Fri Feb 20 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
describe,
expect,
it
} from "@jest/globals";
import {
getCurrentView,
getViewOption,
getViews,
parseCurrentDate,
parseDateOption
} from "./utils";
describe("views utils", (() => {
describe("getViews", (() => {
it("should filter view with incorrect name", (() => {
expect(getViews(["unknown"])).toEqual([])
}));
it("should filter view with incorrect type", (() => {
expect(getViews([{
type: "unknown"
}])).toEqual([])
}));
it("should not override view options by default options", (() => {
const input = {
groupOrientation: "vertical",
type: "day",
intervalCount: 2,
name: "MyDay",
groups: ["a", "b"]
};
expect(getViews([input])).toEqual([Object.assign({}, input, {
skippedDays: []
})])
}));
it.each([{
input: {
type: "day",
intervalCount: void 0,
groupOrientation: void 0
},
output: {
groupOrientation: "horizontal",
intervalCount: 1,
type: "day"
}
}, {
input: {
type: "agenda",
intervalCount: void 0,
agendaDuration: void 0
},
output: {
agendaDuration: 7,
intervalCount: 1,
type: "agenda"
}
}])("should set default for undefined props ($input.type)", (_ref => {
let {
input: input,
output: output
} = _ref;
expect(getViews([input])).toEqual([Object.assign({}, output, {
skippedDays: []
})])
}));
it.each([{
input: "day",
output: {
groupOrientation: "horizontal",
intervalCount: 1,
type: "day"
}
}, {
input: "week",
output: {
groupOrientation: "horizontal",
intervalCount: 1,
type: "week"
}
}, {
input: "month",
output: {
groupOrientation: "horizontal",
intervalCount: 1,
type: "month"
}
}, {
input: "timelineDay",
output: {
groupOrientation: "vertical",
intervalCount: 1,
type: "timelineDay"
}
}, {
input: "timelineWeek",
output: {
groupOrientation: "vertical",
intervalCount: 1,
type: "timelineWeek"
}
}, {
input: "timelineMonth",
output: {
groupOrientation: "vertical",
intervalCount: 1,
type: "timelineMonth"
}
}, {
input: "agenda",
output: {
agendaDuration: 7,
intervalCount: 1,
type: "agenda"
}
}])("should return normalized $input.type view", (_ref2 => {
let {
input: input,
output: output
} = _ref2;
expect(getViews([input])).toEqual([Object.assign({}, output, {
skippedDays: []
})])
}));
it.each([{
input: "workWeek",
output: {
groupOrientation: "horizontal",
intervalCount: 1,
type: "workWeek"
}
}, {
input: "timelineWorkWeek",
output: {
groupOrientation: "vertical",
intervalCount: 1,
type: "timelineWorkWeek"
}
}])("should return normalized $input.type view", (_ref3 => {
let {
input: input,
output: output
} = _ref3;
expect(getViews([input])).toEqual([Object.assign({}, output, {
skippedDays: [0, 6]
})])
}))
}));
describe("getCurrentView", (() => {
it("should return normalized object", (() => {
expect(getCurrentView("agenda", ["agenda"])).toEqual({
agendaDuration: 7,
intervalCount: 1,
type: "agenda",
skippedDays: []
})
}));
it("should return view by type", (() => {
expect(getCurrentView("agenda", ["month", {
type: "agenda"
}])).toEqual({
agendaDuration: 7,
intervalCount: 1,
type: "agenda",
skippedDays: []
})
}));
it("should return view by name", (() => {
expect(getCurrentView("SuperAgenda", ["month", {
name: "SuperAgenda",
type: "agenda"
}])).toEqual({
agendaDuration: 7,
intervalCount: 1,
name: "SuperAgenda",
type: "agenda",
skippedDays: []
})
}));
it("should return default view out of the views list", (() => {
expect(getCurrentView("agenda", ["month"])).toEqual({
agendaDuration: 7,
intervalCount: 1,
type: "agenda",
skippedDays: []
})
}));
it("should return first view if nothing found", (() => {
expect(getCurrentView("agendaShort", ["month", "agenda"])).toEqual({
groupOrientation: "horizontal",
intervalCount: 1,
type: "month",
skippedDays: []
})
}));
it("should return first known view if wrong current view requested", (() => {
expect(getCurrentView("blabla", [{
type: "blabla",
name: "blabla",
unknown: "incorrect view"
}])).toEqual({
groupOrientation: "horizontal",
intervalCount: 1,
type: "day",
skippedDays: []
})
}))
}));
describe("parseDateOption", (() => {
const expectedDate = new Date(2025, 3, 23, 12, 1, 54);
it("should return deserialized date from string", (() => {
expect(parseDateOption("2025/04/23 12:01:54")).toEqual(expectedDate)
}));
it("should return deserialized date from number", (() => {
expect(parseDateOption(expectedDate.getTime())).toEqual(new Date(expectedDate))
}));
it("should return deserialized date from date", (() => {
expect(parseDateOption(expectedDate)).toEqual(expectedDate)
}))
}));
describe("parseCurrentDate", (() => {
const inputDate = new Date(2025, 3, 23, 12, 1, 54);
const expectedDate = new Date(2025, 3, 23);
it("should return trimmed deserialized date from string", (() => {
expect(parseCurrentDate("2025/04/23 12:01:54")).toEqual(expectedDate)
}));
it("should return trimmed deserialized date from number", (() => {
expect(parseCurrentDate(inputDate.getTime())).toEqual(expectedDate)
}));
it("should return trimmed deserialized date from date", (() => {
expect(parseCurrentDate(inputDate)).toEqual(expectedDate)
}))
}));
describe("getViewOption", (() => {
const inputDate = new Date(2025, 3, 23, 12, 1, 54);
const expectedDate = new Date(2025, 3, 23);
it("should return currentDate", (() => {
expect(getViewOption("currentDate", inputDate)).toEqual(expectedDate)
}));
it("should return min", (() => {
expect(getViewOption("min", inputDate)).toEqual(inputDate)
}));
it("should return max", (() => {
expect(getViewOption("max", inputDate)).toEqual(inputDate)
}));
it("should return views", (() => {
expect(getViewOption("views", ["month", "agenda"])).toEqual(["month", "agenda"])
}))
}))
}));