"use strict";
// © 2022 SolarWinds Worldwide, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to
//  deal in the Software without restriction, including without limitation the
//  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
//  sell copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectionType = void 0;
const tslib_1 = require("tslib");
const protractor_1 = require("protractor");
const atom_1 = require("../../atom");
const helpers_1 = require("../../helpers");
const selector_atom_1 = require("./selector.atom");
var SelectionType;
(function (SelectionType) {
    SelectionType["All"] = "Select all items on this page";
    SelectionType["UnselectAll"] = "Unselect all items on this page";
    SelectionType["None"] = "Unselect all items";
    SelectionType["AllPages"] = "Select all items on all pages";
})(SelectionType = exports.SelectionType || (exports.SelectionType = {}));
describe("USERCONTROL Selector", () => {
    const demoElementId = "nui-demo-selector";
    let subject;
    let selectionElement;
    let indeterminateElement;
    const isIndeterminate = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return (yield indeterminateElement.getText()) === "indeterminate"; });
    const makeIndeterminate = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return protractor_1.browser.element(protractor_1.by.id("nui-demo-make-indeterminate")).click(); });
    const makeAppendedToBody = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return protractor_1.browser.element(protractor_1.by.id("nui-demo-make-appended-to-body")).click(); });
    beforeAll(() => {
        subject = atom_1.Atom.find(selector_atom_1.SelectorAtom, demoElementId);
        selectionElement = (0, protractor_1.element)(protractor_1.by.id("nui-demo-selection-type"));
        indeterminateElement = (0, protractor_1.element)(protractor_1.by.id("nui-demo-indeterminate"));
    });
    beforeEach(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        yield helpers_1.Helpers.prepareBrowser("selector");
    }));
    it("should get appropriate 'SelectionType' state by clicking repeat item", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        yield subject.select(SelectionType.All);
        expect(yield selectionElement.getText()).toEqual(SelectionType.All);
        yield subject.select(SelectionType.None);
        expect(yield selectionElement.getText()).toEqual(SelectionType.None);
        yield subject.select(SelectionType.All);
        yield subject.select(SelectionType.AllPages);
        expect(yield selectionElement.getText()).toEqual(SelectionType.AllPages);
    }));
    it("should get 'SelectionType' (All, None) by changing checkbox state", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        const selectorCheckbox = subject.getCheckbox();
        yield selectorCheckbox.toggle();
        expect(yield selectionElement.getText()).toEqual(SelectionType.All);
        yield selectorCheckbox.toggle();
        expect(yield selectionElement.getText()).toEqual(SelectionType.UnselectAll);
    }));
    it("should set 'Indeterminate'", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        yield subject.select(SelectionType.AllPages);
        expect(yield isIndeterminate()).toBe(false);
        yield makeIndeterminate();
        expect(yield isIndeterminate()).toBe(true);
    }));
    it("should get 'SelectionType' (All, None) by clicking on selector button", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        const selectorButton = subject.getSelectorButton();
        yield selectorButton.click();
        expect(yield selectionElement.getText()).toEqual(SelectionType.All);
        yield selectorButton.click();
        expect(yield selectionElement.getText()).toEqual(SelectionType.UnselectAll);
    }));
    describe("appended to body >", () => {
        it("should get appropriate 'SelectionType' state by clicking repeat item", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
            yield makeAppendedToBody();
            yield subject.selectAppendedToBodyItem(SelectionType.All);
            expect(yield selectionElement.getText()).toEqual(SelectionType.All);
            yield subject.selectAppendedToBodyItem(SelectionType.None);
            expect(yield selectionElement.getText()).toEqual(SelectionType.None);
            yield subject.selectAppendedToBodyItem(SelectionType.AllPages);
            expect(yield selectionElement.getText()).toEqual(SelectionType.AllPages);
        }));
    });
});
//# sourceMappingURL=selector.e2e.js.map