UNPKG

@kui-shell/plugin-core-support

Version:

Kui plugin offering core extensions such as help and screenshot commands

200 lines • 10.3 kB
/* * Copyright 2020 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 { dirname } from 'path'; import { Common, CLI, ReplExpect, Selectors, Util, Keys } from '@kui-shell/test'; import { splitViaButton } from '../core-support2/split-helpers'; import { focus, lastOutput, typeAndVerify, verifyTextInMonaco } from './commentary-util'; const ROOT = dirname(require.resolve('@kui-shell/plugin-core-support/package.json')); /* xit has been added to most tests because of recent changes to notebooks opening in read only mode. These changes make commentaries incapable of being edited for now until more changes are made */ describe('commentary and replay', function () { before(Common.before(this)); after(Common.after(this)); const verifyComment = (inNotebook = true) => { return this.app.client.waitUntil(() => __awaiter(this, void 0, void 0, function* () { const lastOutput = inNotebook ? Selectors.OUTPUT_LAST_IN_NOTEBOOK() : Selectors.OUTPUT_LAST; yield this.app.client.$(`${lastOutput} ${Selectors.TERMINAL_CARD}`).then(_ => _.waitForDisplayed()); const title = yield this.app.client.$(`${lastOutput} ${Selectors.TERMINAL_CARD_TITLE}`).then(_ => _.getText()); const head1 = yield this.app.client.$(`${lastOutput} ${Selectors.TERMINAL_CARD} h1`).then(_ => _.getText()); const head2 = yield this.app.client.$(`${lastOutput} ${Selectors.TERMINAL_CARD} h2`).then(_ => _.getText()); return (title === 'hello there' && head1 === 'The Kui Framework for Graphical Terminals' && head2 === 'Installation'); }), { timeout: CLI.waitTimeout }); }; const addComment = () => { it('should show comment with file', () => CLI.command(`commentary --title "hello there" -f=${ROOT}/tests/data/comment.md`, this.app) .then(() => verifyComment(false)) .catch(Common.oops(this, true))); }; addComment(); it('should show version', () => CLI.command('version', this.app) .then(ReplExpect.okWithCustom({ expect: Common.expectedVersion })) .catch(Common.oops(this, true))); addComment(); }); describe('commentary replace current content', function () { before(Common.before(this)); after(Common.after(this)); it('should add something to the terminal', () => CLI.command('kuiecho hi', this.app).then(ReplExpect.okWithString('hi')).catch(Common.oops(this, true))); splitViaButton.bind(this)(2); it('should run commentary --replace and not show only one finished block', () => CLI.command('commentary --replace hello', this.app).catch(Common.oops(this, true))); it('should show only one split', () => ReplExpect.splitCount(1)); it('should show only one finished block', () => ReplExpect.blockCount.bind(this)().inSplit(1).is(1)); }); describe('edit commentary', function () { before(Common.before(this)); after(Common.after(this)); Util.closeAllExceptFirstTab.bind(this)(); const verifyComment = (expectedText, inNotebook) => { const output = lastOutput(inNotebook); let idx = 0; return this.app.client.waitUntil(() => __awaiter(this, void 0, void 0, function* () { yield this.app.client.$(`${output} ${Selectors.TERMINAL_CARD}`).then(_ => _.waitForDisplayed()); const actualText = yield this.app.client.$(`${output} ${Selectors.TERMINAL_CARD}`).then(_ => _.getText()); if (++idx > 5) { console.error(`still waiting for actual=${actualText} expected=${expectedText}`); } return actualText === expectedText; }), { timeout: CLI.waitTimeout }); }; const openEditor = (expect, inNotebook) => { it('should open editor by clicking', () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client.$(`${lastOutput(inNotebook)} ${Selectors.TERMINAL_CARD}`).then(_ => _.doubleClick()); yield verifyTextInMonaco(this, expect, inNotebook); } catch (err) { yield Common.oops(this, true)(err); } })); }; const saveViaKeys = (keys, expect, inNotebook) => { it(`should close the editor by typing ${keys}`, () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client.keys(keys); yield this.app.client .$(`${lastOutput(inNotebook)} ${Selectors.COMMENTARY_EDITOR}`) .then(_ => _.waitForDisplayed({ timeout: 500, reverse: true })); yield verifyComment(expect, inNotebook); } catch (err) { yield Common.oops(this, true)(err); } })); }; const clickDone = (expect, inNotebook) => { it('should close the editor by clicking the Done button', () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client .$(`${lastOutput(inNotebook)} ${Selectors.COMMENTARY_EDITOR_BUTTON_DONE}`) .then(_ => _.click()); yield this.app.client .$(`${lastOutput(inNotebook)} ${Selectors.COMMENTARY_EDITOR}`) .then(_ => _.waitForDisplayed({ timeout: 500, reverse: true })); yield verifyComment(expect, inNotebook); } catch (err) { yield Common.oops(this, true)(err); } })); }; const clickRevert = (expect, inNotebook) => { it('should revert the editor by clicking the Revert button', () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client .$(`${lastOutput(inNotebook)} ${Selectors.COMMENTARY_EDITOR_BUTTON_REVERT}`) .then(_ => _.click()); yield this.app.client .$(`${lastOutput(inNotebook)} ${Selectors.COMMENTARY_EDITOR}`) .then(_ => _.waitForDisplayed()); // still open! yield verifyTextInMonaco(this, expect, inNotebook); } catch (err) { yield Common.oops(this, true)(err); } })); }; const clickCancel = (expect, inNotebook) => { it('should close the editor by clicking the Cancel button', () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client .$(`${lastOutput(inNotebook)} ${Selectors.COMMENTARY_EDITOR_BUTTON_CANCEL}`) .then(_ => _.click()); yield this.app.client .$(`${lastOutput(inNotebook)} ${Selectors.COMMENTARY_EDITOR}`) .then(_ => _.waitForDisplayed({ timeout: 500, reverse: true })); yield verifyComment(expect, inNotebook); } catch (err) { yield Common.oops(this, true)(err); } })); }; const escapeCancel = (expect, inNotebook) => { it('should close the editor by typing Escape', () => __awaiter(this, void 0, void 0, function* () { try { yield focus(this, inNotebook); yield this.app.client.keys('Escape'); yield this.app.client .$(`${lastOutput(inNotebook)} ${Selectors.COMMENTARY_EDITOR}`) .then(_ => _.waitForDisplayed({ timeout: 500, reverse: true })); yield verifyComment(expect, inNotebook); } catch (err) { yield Common.oops(this, true)(err); } })); }; /** Here comes the test */ it('should add comment', () => CLI.command(`# foo-shift-enter`, this.app) .then(() => verifyComment('foo-shift-enter', false)) .catch(Common.oops(this, true))); // test shift-enter to save openEditor('foo-shift-enter', false); typeAndVerify(this, '1', 'foo-shift-enter1', false); saveViaKeys(['Shift', 'Enter'], 'foo-shift-enter1', false); // test cmdctrl+s to save openEditor('foo-shift-enter1', false); typeAndVerify(this, '2', 'foo-shift-enter12', false); saveViaKeys([Keys.ctrlOrMeta, 's'], 'foo-shift-enter12', false); // test Escape to cancel openEditor('foo-shift-enter12', false); typeAndVerify(this, '3', 'foo-shift-enter123', false); escapeCancel('foo-shift-enter12', false); /** Here comes the test */ it('should add another comment', () => CLI.command(`# foo`, this.app) .then(() => verifyComment('foo', false)) .catch(Common.oops(this, true))); openEditor('foo', false); typeAndVerify(this, '1', 'foo1', false); clickDone('foo1', false); openEditor('foo1', false); typeAndVerify(this, '2', 'foo12', false); clickCancel('foo1', false); openEditor('foo1', false); typeAndVerify(this, '3', 'foo13', false); clickRevert('foo1', false); clickCancel('foo1', false); }); //# sourceMappingURL=commentary.js.map