devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
191 lines (189 loc) • 8.84 kB
JavaScript
/**
* DevExtreme (cjs/__internal/scheduler/utils/options_validator/common/validator_rules.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/
*/
;
var _globals = require("@jest/globals");
var validationFunctions = _interopRequireWildcard(require("./validation_functions"));
var _validator_rules = require("./validator_rules");
function _interopRequireWildcard(e, t) {
if ("function" == typeof WeakMap) {
var r = new WeakMap,
n = new WeakMap
}
return (_interopRequireWildcard = function(e, t) {
if (!t && e && e.__esModule) {
return e
}
var o, i, f = {
__proto__: null,
default: e
};
if (null === e || "object" != typeof e && "function" != typeof e) {
return f
}
if (o = t ? n : r) {
if (o.has(e)) {
return o.get(e)
}
o.set(e, f)
}
for (const t in e) {
"default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t])
}
return f
})(e, t)
}(0, _globals.describe)("mustBeInteger", (() => {
const mock = _globals.jest.spyOn(validationFunctions, "isInteger");
(0, _globals.afterEach)((() => {
null === mock || void 0 === mock || mock.mockReset()
}));
(0, _globals.it)("should call isInteger function", (() => {
(0, _validator_rules.mustBeInteger)(10);
(0, _globals.expect)(mock).toHaveBeenCalledWith(10)
}));
(0, _globals.it)("should return true if valid", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => true));
const result = (0, _validator_rules.mustBeInteger)(10);
(0, _globals.expect)(result).toBe(true)
}));
(0, _globals.it)("should return error (string) if invalid", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => false));
const result = (0, _validator_rules.mustBeInteger)(10.5);
(0, _globals.expect)(result).toBe(false)
}));
(0, _globals.it)("should be the function with the correct name", (() => {
const func = _validator_rules.mustBeInteger;
(0, _globals.expect)(func.name).toBe("mustBeInteger")
}))
}));
(0, _globals.describe)("mustBeGreaterThan", (() => {
const mock = _globals.jest.spyOn(validationFunctions, "greaterThan");
(0, _globals.afterEach)((() => {
null === mock || void 0 === mock || mock.mockReset()
}));
(0, _globals.it)("should call greaterThan function", (() => {
const func = (0, _validator_rules.mustBeGreaterThan)(10, true);
func(15);
(0, _globals.expect)(mock).toHaveBeenCalledWith(15, 10, true)
}));
(0, _globals.it)("should return true if valid", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => true));
const func = (0, _validator_rules.mustBeGreaterThan)(10, true);
const result = func(15);
(0, _globals.expect)(result).toBe(true)
}));
(0, _globals.it)("should return error (string) if invalid with strict: true", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => false));
const func = (0, _validator_rules.mustBeGreaterThan)(15, true);
const result = func(10);
(0, _globals.expect)(result).toBe(false)
}));
(0, _globals.it)("should return error (string) if invalid with strict: false", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => false));
const func = (0, _validator_rules.mustBeGreaterThan)(15, false);
const result = func(10);
(0, _globals.expect)(result).toBe(false)
}));
(0, _globals.it)("should be the function with the correct name", (() => {
const func = (0, _validator_rules.mustBeGreaterThan)(15, false);
(0, _globals.expect)(func.name).toBe("mustBeGreaterThan")
}))
}));
(0, _globals.describe)("mustBeLessThan", (() => {
const mock = _globals.jest.spyOn(validationFunctions, "lessThan");
(0, _globals.afterEach)((() => {
null === mock || void 0 === mock || mock.mockReset()
}));
(0, _globals.it)("should call lessThan function", (() => {
const func = (0, _validator_rules.mustBeLessThan)(10, true);
func(5);
(0, _globals.expect)(mock).toHaveBeenCalledWith(5, 10, true)
}));
(0, _globals.it)("should return true if valid", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => true));
const func = (0, _validator_rules.mustBeLessThan)(10, true);
const result = func(5);
(0, _globals.expect)(result).toBe(true)
}));
(0, _globals.it)("should return error (string) if invalid with strict: true", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => false));
const func = (0, _validator_rules.mustBeLessThan)(10, true);
const result = func(15);
(0, _globals.expect)(result).toBe(false)
}));
(0, _globals.it)("should return error (string) if invalid with strict: false", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => false));
const func = (0, _validator_rules.mustBeLessThan)(10, false);
const result = func(15);
(0, _globals.expect)(result).toBe(false)
}));
(0, _globals.it)("should be the function with the correct name", (() => {
const func = (0, _validator_rules.mustBeLessThan)(15, false);
(0, _globals.expect)(func.name).toBe("mustBeLessThan")
}))
}));
(0, _globals.describe)("mustBeInRange", (() => {
const mock = _globals.jest.spyOn(validationFunctions, "inRange");
(0, _globals.afterEach)((() => {
null === mock || void 0 === mock || mock.mockReset()
}));
(0, _globals.it)("should call inRange function", (() => {
const func = (0, _validator_rules.mustBeInRange)([0, 10]);
func(5);
(0, _globals.expect)(mock).toHaveBeenCalledWith(5, [0, 10])
}));
(0, _globals.it)("should return true if valid", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => true));
const func = (0, _validator_rules.mustBeInRange)([0, 10]);
const result = func(5);
(0, _globals.expect)(result).toBe(true)
}));
(0, _globals.it)("should return error (string) if invalid ", (() => {
null === mock || void 0 === mock || mock.mockImplementation((() => false));
const func = (0, _validator_rules.mustBeInRange)([0, 10]);
const result = func(15);
(0, _globals.expect)(result).toBe(false)
}));
(0, _globals.it)("should be the function with the correct name", (() => {
const func = (0, _validator_rules.mustBeInRange)([0, 10]);
(0, _globals.expect)(func.name).toBe("mustBeInRange")
}))
}));
(0, _globals.describe)("mustBeDivisibleBy", (() => {
let mock = _globals.jest.spyOn(validationFunctions, "divisibleBy");
(0, _globals.beforeEach)((() => {
mock = _globals.jest.spyOn(validationFunctions, "divisibleBy")
}));
(0, _globals.afterEach)((() => {
var _mock;
null === (_mock = mock) || void 0 === _mock || _mock.mockReset()
}));
(0, _globals.it)("should call divisibleBy function", (() => {
const func = (0, _validator_rules.mustBeDivisibleBy)(10);
func(100);
(0, _globals.expect)(mock).toHaveBeenCalledWith(100, 10)
}));
(0, _globals.it)("should return true if valid", (() => {
var _mock2;
null === (_mock2 = mock) || void 0 === _mock2 || _mock2.mockImplementation((() => true));
const func = (0, _validator_rules.mustBeDivisibleBy)(5);
const result = func(10);
(0, _globals.expect)(result).toBe(true)
}));
(0, _globals.it)("should return error (string) if invalid ", (() => {
var _mock3;
null === (_mock3 = mock) || void 0 === _mock3 || _mock3.mockImplementation((() => false));
const func = (0, _validator_rules.mustBeDivisibleBy)(5);
const result = func(6);
(0, _globals.expect)(result).toBe(false)
}));
(0, _globals.it)("should be the function with the correct name", (() => {
const func = (0, _validator_rules.mustBeDivisibleBy)(5);
(0, _globals.expect)(func.name).toBe("mustBeDivisibleBy")
}))
}));