/**
 * DevExtreme (esm/__internal/scheduler/options_validator/core/options_validator.test.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import {
    OptionsValidator
} from "./options_validator";
import {
    Validator
} from "./validator";
class TestOptionsValidator extends OptionsValidator {
    constructor(validators) {
        super(validators)
    }
}
var widgetOptions = {
    A: 1,
    B: "1",
    C: true
};
describe("OptionsValidator", () => {
    it("should call each validator's validate method", () => {
        var validators = [new Validator(() => {}, []), new Validator(() => {}, []), new Validator(() => {}, [])];
        var validateSpies = validators.map(validator => {
            var validateSpy = jest.spyOn(validator, "validate");
            validateSpy.mockImplementation(() => true);
            return validateSpy
        });
        var optionsValidator = new TestOptionsValidator({
            A: validators[0],
            B: validators[1],
            C: validators[2]
        });
        optionsValidator.validate(widgetOptions);
        expect(validateSpies[0]).toHaveBeenCalledWith(widgetOptions);
        expect(validateSpies[1]).toHaveBeenCalledWith(widgetOptions);
        expect(validateSpies[2]).toHaveBeenCalledWith(widgetOptions);
        validateSpies.forEach(spy => {
            spy.mockReset()
        })
    });
    it("should return true if all validators validates without errors", () => {
        var validator = new Validator(() => {}, []);
        var validateSpy = jest.spyOn(validator, "validate");
        validateSpy.mockImplementation(() => true);
        var optionsValidator = new TestOptionsValidator({
            A: validator,
            B: validator,
            C: validator
        });
        var result = optionsValidator.validate(widgetOptions);
        expect(result).toBe(true);
        validateSpy.mockReset()
    });
    it("should return object with errors if some validators validates with errors", () => {
        var firstValidateResult = {
            required: "false",
            isInteger: "false"
        };
        var thirdValidateResult = {
            someError: "some message"
        };
        var expectedResult = {
            A: firstValidateResult,
            C: thirdValidateResult
        };
        var validators = [new Validator(() => {}, []), new Validator(() => {}, []), new Validator(() => {}, [])];
        var firstValidateSpy = jest.spyOn(validators[0], "validate");
        var secondValidateSpy = jest.spyOn(validators[1], "validate");
        var thirdValidateSpy = jest.spyOn(validators[2], "validate");
        firstValidateSpy.mockImplementation(() => firstValidateResult);
        secondValidateSpy.mockImplementation(() => true);
        thirdValidateSpy.mockImplementation(() => thirdValidateResult);
        var optionsValidator = new TestOptionsValidator({
            A: validators[0],
            B: validators[1],
            C: validators[2]
        });
        var result = optionsValidator.validate(widgetOptions);
        expect(result).toEqual(expectedResult);
        firstValidateSpy.mockReset();
        secondValidateSpy.mockReset();
        thirdValidateSpy.mockReset()
    })
});
