devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
249 lines (248 loc) • 9.74 kB
JavaScript
/**
* DevExtreme (cjs/__internal/scheduler/utils/options/utils.test.js)
* Version: 25.2.3
* Build date: Fri Dec 12 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
"use strict";
var _globals = require("@jest/globals");
var _utils = require("./utils");
(0, _globals.describe)("views utils", (() => {
(0, _globals.describe)("getViews", (() => {
(0, _globals.it)("should filter view with incorrect name", (() => {
(0, _globals.expect)((0, _utils.getViews)(["unknown"])).toEqual([])
}));
(0, _globals.it)("should filter view with incorrect type", (() => {
(0, _globals.expect)((0, _utils.getViews)([{
type: "unknown"
}])).toEqual([])
}));
(0, _globals.it)("should not override view options by default options", (() => {
const input = {
groupOrientation: "vertical",
type: "day",
intervalCount: 2,
name: "MyDay",
groups: ["a", "b"]
};
(0, _globals.expect)((0, _utils.getViews)([input])).toEqual([Object.assign({}, input, {
skippedDays: []
})])
}));
_globals.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;
(0, _globals.expect)((0, _utils.getViews)([input])).toEqual([Object.assign({}, output, {
skippedDays: []
})])
}));
_globals.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;
(0, _globals.expect)((0, _utils.getViews)([input])).toEqual([Object.assign({}, output, {
skippedDays: []
})])
}));
_globals.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;
(0, _globals.expect)((0, _utils.getViews)([input])).toEqual([Object.assign({}, output, {
skippedDays: [0, 6]
})])
}))
}));
(0, _globals.describe)("getCurrentView", (() => {
(0, _globals.it)("should return normalized object", (() => {
(0, _globals.expect)((0, _utils.getCurrentView)("agenda", ["agenda"])).toEqual({
agendaDuration: 7,
intervalCount: 1,
type: "agenda",
skippedDays: []
})
}));
(0, _globals.it)("should return view by type", (() => {
(0, _globals.expect)((0, _utils.getCurrentView)("agenda", ["month", {
type: "agenda"
}])).toEqual({
agendaDuration: 7,
intervalCount: 1,
type: "agenda",
skippedDays: []
})
}));
(0, _globals.it)("should return view by name", (() => {
(0, _globals.expect)((0, _utils.getCurrentView)("SuperAgenda", ["month", {
name: "SuperAgenda",
type: "agenda"
}])).toEqual({
agendaDuration: 7,
intervalCount: 1,
name: "SuperAgenda",
type: "agenda",
skippedDays: []
})
}));
(0, _globals.it)("should return default view out of the views list", (() => {
(0, _globals.expect)((0, _utils.getCurrentView)("agenda", ["month"])).toEqual({
agendaDuration: 7,
intervalCount: 1,
type: "agenda",
skippedDays: []
})
}));
(0, _globals.it)("should return first view if nothing found", (() => {
(0, _globals.expect)((0, _utils.getCurrentView)("agendaShort", ["month", "agenda"])).toEqual({
groupOrientation: "horizontal",
intervalCount: 1,
type: "month",
skippedDays: []
})
}));
(0, _globals.it)("should return first known view if wrong current view requested", (() => {
(0, _globals.expect)((0, _utils.getCurrentView)("blabla", [{
type: "blabla",
name: "blabla",
unknown: "incorrect view"
}])).toEqual({
groupOrientation: "horizontal",
intervalCount: 1,
type: "day",
skippedDays: []
})
}))
}));
(0, _globals.describe)("parseDateOption", (() => {
const expectedDate = new Date(2025, 3, 23, 12, 1, 54);
(0, _globals.it)("should return deserialized date from string", (() => {
(0, _globals.expect)((0, _utils.parseDateOption)("2025/04/23 12:01:54")).toEqual(expectedDate)
}));
(0, _globals.it)("should return deserialized date from number", (() => {
(0, _globals.expect)((0, _utils.parseDateOption)(expectedDate.getTime())).toEqual(new Date(expectedDate))
}));
(0, _globals.it)("should return deserialized date from date", (() => {
(0, _globals.expect)((0, _utils.parseDateOption)(expectedDate)).toEqual(expectedDate)
}))
}));
(0, _globals.describe)("parseCurrentDate", (() => {
const inputDate = new Date(2025, 3, 23, 12, 1, 54);
const expectedDate = new Date(2025, 3, 23);
(0, _globals.it)("should return trimmed deserialized date from string", (() => {
(0, _globals.expect)((0, _utils.parseCurrentDate)("2025/04/23 12:01:54")).toEqual(expectedDate)
}));
(0, _globals.it)("should return trimmed deserialized date from number", (() => {
(0, _globals.expect)((0, _utils.parseCurrentDate)(inputDate.getTime())).toEqual(expectedDate)
}));
(0, _globals.it)("should return trimmed deserialized date from date", (() => {
(0, _globals.expect)((0, _utils.parseCurrentDate)(inputDate)).toEqual(expectedDate)
}))
}));
(0, _globals.describe)("getViewOption", (() => {
const inputDate = new Date(2025, 3, 23, 12, 1, 54);
const expectedDate = new Date(2025, 3, 23);
(0, _globals.it)("should return currentDate", (() => {
(0, _globals.expect)((0, _utils.getViewOption)("currentDate", inputDate)).toEqual(expectedDate)
}));
(0, _globals.it)("should return min", (() => {
(0, _globals.expect)((0, _utils.getViewOption)("min", inputDate)).toEqual(inputDate)
}));
(0, _globals.it)("should return max", (() => {
(0, _globals.expect)((0, _utils.getViewOption)("max", inputDate)).toEqual(inputDate)
}));
(0, _globals.it)("should return views", (() => {
(0, _globals.expect)((0, _utils.getViewOption)("views", ["month", "agenda"])).toEqual(["month", "agenda"])
}))
}))
}));