/*
 * Copyright 2021 The Kubernetes Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { Common, CLI, Selectors, Util } from '@kui-shell/test';
const TIMEOUT = 1000;
Common.localDescribe('notebooks read only mode', function () {
    before(Common.before(this));
    after(Common.after(this));
    Util.closeAllExceptFirstTab.bind(this);
    const openNotebook = () => {
        it('should open a notebook using a CLI command', () => CLI.command('replay /kui/welcome.md', this.app).catch(Common.oops(this, true)));
    };
    const splitHeadersCheck = () => {
        it('should verify that split headers are not showing', () => __awaiter(this, void 0, void 0, function* () {
            try {
                yield this.app.client.$('.kui--split-header').then(_ => _.waitForDisplayed({ timeout: TIMEOUT, reverse: true }));
            }
            catch (err) {
                return Common.oops(this, true)(err);
            }
        }));
    };
    const doubleClick = () => {
        it('should verify that commentary blocks cannot enter edit mode when double clicked', () => __awaiter(this, void 0, void 0, function* () {
            try {
                yield this.app.client.$('.kui--commentary-card').then(_ => _.doubleClick());
                yield this.app.client
                    .$(Selectors.COMMENTARY_EDITOR)
                    .then(_ => _.waitForDisplayed({ timeout: TIMEOUT, reverse: true }));
            }
            catch (err) {
                return Common.oops(this, true)(err);
            }
        }));
    };
    const blockActionsAvailable = () => {
        it('should verify that only the replay button is available for block actions', () => __awaiter(this, void 0, void 0, function* () {
            try {
                // For notebooks being used for this test, the block at split index 2 will be used
                const splitIndex = 2;
                const N = (yield CLI.lastBlock(this.app, splitIndex, 1, true)).count;
                // the replay button should be showing
                yield this.app.client
                    .$(Selectors.COMMAND_RERUN_BUTTON(N, splitIndex))
                    .then(_ => _.waitForDisplayed({ timeout: TIMEOUT }));
                // any other block action button should not be showing
                yield this.app.client
                    .$(Selectors.BLOCK_REMOVE_BUTTON(N))
                    .then(_ => _.waitForDisplayed({ timeout: TIMEOUT, reverse: true }));
                yield this.app.client
                    .$(Selectors.BLOCK_LINK_BUTTON(N))
                    .then(_ => _.waitForDisplayed({ timeout: TIMEOUT, reverse: true }));
                yield this.app.client
                    .$(Selectors.COMMAND_COPY_BUTTON(N))
                    .then(_ => _.waitForDisplayed({ timeout: TIMEOUT, reverse: true }));
            }
            catch (err) {
                return Common.oops(this, true)(err);
            }
        }));
    };
    // Tests begin here
    openNotebook();
    splitHeadersCheck();
    doubleClick();
    blockActionsAvailable();
});
//# sourceMappingURL=notebooks-readonly.js.map