UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

175 lines (174 loc) • 6.69 kB
/** * DevExtreme (esm/__internal/scheduler/utils/options_validator/common/validator_rules.test.js) * Version: 25.2.7 * Build date: Tue May 05 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals"; import * as validationFunctions from "./validation_functions"; import { mustBeDivisibleBy, mustBeGreaterThan, mustBeInRange, mustBeInteger, mustBeLessThan } from "./validator_rules"; describe("mustBeInteger", () => { const mock = jest.spyOn(validationFunctions, "isInteger"); afterEach(() => { null === mock || void 0 === mock || mock.mockReset() }); it("should call isInteger function", () => { mustBeInteger(10); expect(mock).toHaveBeenCalledWith(10) }); it("should return true if valid", () => { null === mock || void 0 === mock || mock.mockImplementation(() => true); const result = mustBeInteger(10); expect(result).toBe(true) }); it("should return error (string) if invalid", () => { null === mock || void 0 === mock || mock.mockImplementation(() => false); const result = mustBeInteger(10.5); expect(result).toBe(false) }); it("should be the function with the correct name", () => { const func = mustBeInteger; expect(func.name).toBe("mustBeInteger") }) }); describe("mustBeGreaterThan", () => { const mock = jest.spyOn(validationFunctions, "greaterThan"); afterEach(() => { null === mock || void 0 === mock || mock.mockReset() }); it("should call greaterThan function", () => { const func = mustBeGreaterThan(10, true); func(15); expect(mock).toHaveBeenCalledWith(15, 10, true) }); it("should return true if valid", () => { null === mock || void 0 === mock || mock.mockImplementation(() => true); const func = mustBeGreaterThan(10, true); const result = func(15); expect(result).toBe(true) }); it("should return error (string) if invalid with strict: true", () => { null === mock || void 0 === mock || mock.mockImplementation(() => false); const func = mustBeGreaterThan(15, true); const result = func(10); expect(result).toBe(false) }); it("should return error (string) if invalid with strict: false", () => { null === mock || void 0 === mock || mock.mockImplementation(() => false); const func = mustBeGreaterThan(15, false); const result = func(10); expect(result).toBe(false) }); it("should be the function with the correct name", () => { const func = mustBeGreaterThan(15, false); expect(func.name).toBe("mustBeGreaterThan") }) }); describe("mustBeLessThan", () => { const mock = jest.spyOn(validationFunctions, "lessThan"); afterEach(() => { null === mock || void 0 === mock || mock.mockReset() }); it("should call lessThan function", () => { const func = mustBeLessThan(10, true); func(5); expect(mock).toHaveBeenCalledWith(5, 10, true) }); it("should return true if valid", () => { null === mock || void 0 === mock || mock.mockImplementation(() => true); const func = mustBeLessThan(10, true); const result = func(5); expect(result).toBe(true) }); it("should return error (string) if invalid with strict: true", () => { null === mock || void 0 === mock || mock.mockImplementation(() => false); const func = mustBeLessThan(10, true); const result = func(15); expect(result).toBe(false) }); it("should return error (string) if invalid with strict: false", () => { null === mock || void 0 === mock || mock.mockImplementation(() => false); const func = mustBeLessThan(10, false); const result = func(15); expect(result).toBe(false) }); it("should be the function with the correct name", () => { const func = mustBeLessThan(15, false); expect(func.name).toBe("mustBeLessThan") }) }); describe("mustBeInRange", () => { const mock = jest.spyOn(validationFunctions, "inRange"); afterEach(() => { null === mock || void 0 === mock || mock.mockReset() }); it("should call inRange function", () => { const func = mustBeInRange([0, 10]); func(5); expect(mock).toHaveBeenCalledWith(5, [0, 10]) }); it("should return true if valid", () => { null === mock || void 0 === mock || mock.mockImplementation(() => true); const func = mustBeInRange([0, 10]); const result = func(5); expect(result).toBe(true) }); it("should return error (string) if invalid ", () => { null === mock || void 0 === mock || mock.mockImplementation(() => false); const func = mustBeInRange([0, 10]); const result = func(15); expect(result).toBe(false) }); it("should be the function with the correct name", () => { const func = mustBeInRange([0, 10]); expect(func.name).toBe("mustBeInRange") }) }); describe("mustBeDivisibleBy", () => { let mock = jest.spyOn(validationFunctions, "divisibleBy"); beforeEach(() => { mock = jest.spyOn(validationFunctions, "divisibleBy") }); afterEach(() => { var _mock; null === (_mock = mock) || void 0 === _mock || _mock.mockReset() }); it("should call divisibleBy function", () => { const func = mustBeDivisibleBy(10); func(100); expect(mock).toHaveBeenCalledWith(100, 10) }); it("should return true if valid", () => { var _mock2; null === (_mock2 = mock) || void 0 === _mock2 || _mock2.mockImplementation(() => true); const func = mustBeDivisibleBy(5); const result = func(10); expect(result).toBe(true) }); it("should return error (string) if invalid ", () => { var _mock3; null === (_mock3 = mock) || void 0 === _mock3 || _mock3.mockImplementation(() => false); const func = mustBeDivisibleBy(5); const result = func(6); expect(result).toBe(false) }); it("should be the function with the correct name", () => { const func = mustBeDivisibleBy(5); expect(func.name).toBe("mustBeDivisibleBy") }) });