UNPKG

kui-shell

Version:

This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool

243 lines 12.2 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const Common = require("./common"); const CLI = require("./cli"); const ReplExpect = require("./repl-expect"); const SidecarExpect = require("./sidecar-expect"); const Selectors = require("./selectors"); const keys_1 = require("./keys"); class TestMMR { constructor(param) { this.param = param; } name() { const { command, metadata } = this.param; describe(`mmr name ${process.env.MOCHA_RUN_TARGET || ''}`, function () { before(Common.before(this)); after(Common.after(this)); it(`should show name ${metadata.name} in sidecar`, () => CLI.command(command, this.app) .then(ReplExpect.ok) .then(SidecarExpect.open) .then(SidecarExpect.name(metadata.name)) .catch(Common.oops(this, true))); }); } namespace() { const { command, metadata } = this.param; describe(`mmr namespace ${process.env.MOCHA_RUN_TARGET || ''}`, function () { before(Common.before(this)); after(Common.after(this)); it(`should show namespace ${metadata.namespace} in sidecar`, () => CLI.command(command, this.app) .then(ReplExpect.ok) .then(SidecarExpect.open) .then(SidecarExpect.namespace(metadata.namespace)) .catch(Common.oops(this, true))); }); } kind(kind) { const command = this.param.command; describe(`mmr kind ${process.env.MOCHA_RUN_TARGET || ''}`, function () { before(Common.before(this)); after(Common.after(this)); it(`should show kind ${kind} in sidecar`, () => CLI.command(command, this.app) .then(ReplExpect.ok) .then(SidecarExpect.open) .then(SidecarExpect.kind(kind.toUpperCase())) .catch(Common.oops(this, true))); }); } badges(badges) { const { command, testName } = this.param; describe(`mmr badges ${testName || ''} ${process.env.MOCHA_RUN_TARGET || ''}`, function () { before(Common.before(this)); after(Common.after(this)); it(`should show badges in sidecar`, () => CLI.command(command, this.app) .then(ReplExpect.ok) .then(SidecarExpect.open) .then(app => Promise.all(badges.map(badge => SidecarExpect.badge(badge.title)(app))))); }); } modes(expectModes, options) { const { command, testName } = this.param; describe(`mmr modes ${testName || ''} ${process.env.MOCHA_RUN_TARGET || ''}`, function () { before(Common.before(this)); after(Common.after(this)); const showModes = () => { it(`should show modes in sidecar`, () => CLI.command(command, this.app) .then(ReplExpect.ok) .then(SidecarExpect.open) .then(SidecarExpect.modes(expectModes)) .catch(Common.oops(this, true))); }; const cycleTheTabs = () => expectModes.forEach(expectMode => { it(`should switch to the ${expectMode.mode} tab`, () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client.click(Selectors.SIDECAR_MODE_BUTTON(expectMode.mode)); yield this.app.client.waitForExist(Selectors.SIDECAR_MODE_BUTTON_SELECTED(expectMode.mode)); } catch (err) { return Common.oops(this)(err); } })); if (expectMode.contentType === 'text/plain') { it(`should show plain text content in the ${expectMode.mode} tab`, () => __awaiter(this, void 0, void 0, function* () { try { yield SidecarExpect.textPlainContent(expectMode.content)(this.app); } catch (err) { return Common.oops(this)(err); } })); } else if (expectMode.contentType === 'yaml') { if (expectMode.editor === true) { it(`should open editor and show yaml content in the ${expectMode.mode} tab`, () => __awaiter(this, void 0, void 0, function* () { try { yield SidecarExpect.yaml(expectMode.content)(this.app); } catch (err) { return Common.oops(this)(err); } })); } else { it(`should show plain yaml content in the ${expectMode.mode} tab`, () => __awaiter(this, void 0, void 0, function* () { try { yield SidecarExpect.textPlainContent(expectMode.content)(this.app); } catch (err) { return Common.oops(this)(err); } })); } } }); showModes(); cycleTheTabs(); cycleTheTabs(); if (options && options.testWindowButtons === true) { const toggleSidecarWithESC = (expectOpen = false) => it(`should hit ESCAPE key and expect sidecar ${expectOpen ? 'open' : 'closed'}`, () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client.keys(keys_1.keys.ESCAPE); expectOpen ? yield SidecarExpect.open(this.app) : yield SidecarExpect.closed(this.app); } catch (err) { yield Common.oops(this, true); } })); const quit = () => it('should fully close the sidecar', () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client.waitForVisible(Selectors.SIDECAR_FULLY_CLOSE_BUTTON); yield this.app.client.click(Selectors.SIDECAR_FULLY_CLOSE_BUTTON); yield SidecarExpect.fullyClosed(this.app); } catch (err) { yield Common.oops(this, true); } })); const maximize = () => it('should maximize the sidecar', () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client.waitForVisible(Selectors.SIDECAR_MAXIMIZE_BUTTON); yield this.app.client.click(Selectors.SIDECAR_MAXIMIZE_BUTTON); yield SidecarExpect.fullscreen(this.app); } catch (err) { yield Common.oops(this, true); } })); const minimize = () => { it('should toggle the sidebar closed with close button click', () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client.waitForVisible(Selectors.SIDECAR_CLOSE_BUTTON); yield this.app.client.click(Selectors.SIDECAR_CLOSE_BUTTON); yield SidecarExpect.closed(this.app); } catch (err) { yield Common.oops(this, true); } })); }; const backToOpen = (backFromMinimized) => { const button = backFromMinimized ? Selectors.SIDECAR_RESUME_FROM_CLOSE_BUTTON : Selectors.SIDECAR_MAXIMIZE_BUTTON; it(`should resume the sidecar from ${backFromMinimized ? 'minimized' : 'maximized'} to open`, () => __awaiter(this, void 0, void 0, function* () { try { yield this.app.client.waitForVisible(button); yield this.app.client.click(button); yield SidecarExpect.open(this.app); } catch (err) { yield Common.oops(this, true); } })); }; showModes(); toggleSidecarWithESC(); toggleSidecarWithESC(true); toggleSidecarWithESC(); showModes(); minimize(); backToOpen(true); minimize(); showModes(); maximize(); backToOpen(false); showModes(); quit(); showModes(); } }); } toolbarButtons(buttons) { const command = this.param.command; describe(`mmr toolbar buttons ${process.env.MOCHA_RUN_TARGET || ''}`, function () { before(Common.before(this)); after(Common.after(this)); it(`should show toolbar buttons in sidecar `, () => CLI.command(command, this.app) .then(ReplExpect.ok) .then(SidecarExpect.open) .then(app => Promise.all(buttons.map(button => SidecarExpect.button(button)(app)))) .catch(Common.oops(this, true))); const drilldownButtons = buttons.filter(_ => _.kind === 'drilldown'); if (drilldownButtons.length > 0) { it(`should drilldown toolbar buttons in sidecar `, () => __awaiter(this, void 0, void 0, function* () { const { app, count } = yield CLI.command(command, this.app); yield ReplExpect.ok({ app, count }); yield SidecarExpect.open(app); yield Promise.all(drilldownButtons.map((button, index) => __awaiter(this, void 0, void 0, function* () { const buttonSelector = Selectors.SIDECAR_TOOLBAR_BUTTON(button.mode); yield app.client.waitForVisible(buttonSelector); yield app.client.click(buttonSelector); const promptSelector = Selectors.PROMPT_N(count + 1 + index); yield ReplExpect.ok({ app, count: count + 1 + index }); yield CLI.expectInput(promptSelector, button.command)(app); }))); })); } }); } toolbarText(toolbarText) { const command = this.param.command; describe(`mmr toolbar text ${process.env.MOCHA_RUN_TARGET || ''}`, function () { before(Common.before(this)); after(Common.after(this)); it(`should show toolbar text in sidecar `, () => CLI.command(command, this.app) .then(ReplExpect.ok) .then(SidecarExpect.open) .then(SidecarExpect.toolbarText(toolbarText)) .catch(Common.oops(this, true))); }); } } exports.TestMMR = TestMMR; //# sourceMappingURL=mmr.js.map