UNPKG

kui-shell

Version:

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

176 lines 9.09 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 cli_1 = require("./cli"); const Selectors = require("./selectors"); const keys_1 = require("./keys"); const util_1 = require("./util"); exports.open = (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitForVisible(Selectors.SIDECAR, cli_1.timeout); return app; }); exports.openWithFailure = (app) => __awaiter(void 0, void 0, void 0, function* () { return app.client.waitForVisible(Selectors.SIDECAR_WITH_FAILURE, cli_1.timeout).then(() => app); }); exports.fullscreen = (app) => __awaiter(void 0, void 0, void 0, function* () { return app.client.waitForVisible(Selectors.SIDECAR_FULLSCREEN, cli_1.timeout).then(() => app); }); exports.closed = (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitForExist(Selectors.SIDECAR_HIDDEN, cli_1.timeout).then(() => app); yield new Promise(resolve => setTimeout(resolve, 600)); }); exports.fullyClosed = (app) => __awaiter(void 0, void 0, void 0, function* () { return app.client.waitForExist(Selectors.SIDECAR_FULLY_HIDDEN, cli_1.timeout).then(() => app); }); exports.keyToClose = (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.keys(keys_1.keys.ESCAPE); return exports.closed(app); }); exports.sourceStruct = (expectedJSON) => (app) => __awaiter(void 0, void 0, void 0, function* () { return app.client .getText(Selectors.SIDECAR_ACTION_SOURCE) .then(util_1.expectStruct(expectedJSON)) .then(() => app); }); exports.sourceSubset = (expectedJSON) => (app) => __awaiter(void 0, void 0, void 0, function* () { return app.client .getText(Selectors.SIDECAR_ACTION_SOURCE) .then(util_1.expectSubset(expectedJSON)) .then(() => app); }); exports.source = (expectedSource) => (app) => __awaiter(void 0, void 0, void 0, function* () { return app.client .waitUntil(() => __awaiter(void 0, void 0, void 0, function* () { const actualSource = yield app.client.getText(Selectors.SIDECAR_ACTION_SOURCE); return actualSource.replace(/\s+/g, '') === expectedSource.replace(/\s+/g, ''); }), cli_1.waitTimeout) .then(() => app); }); exports.result = (expectedResult, failFast) => (app) => __awaiter(void 0, void 0, void 0, function* () { return app.client .getText(Selectors.SIDECAR_ACTIVATION_RESULT) .then(util_1.expectStruct(expectedResult, undefined, failFast)) .then(() => app); }); exports.resultSubset = (expectedResult, failFast) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.getText(Selectors.SIDECAR_ACTIVATION_RESULT).then(util_1.expectSubset(expectedResult, failFast)); return app; }); exports.badge = (badge) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitUntil(() => __awaiter(void 0, void 0, void 0, function* () { const badges = yield app.client.getText(Selectors.SIDECAR_BADGES); return badges.indexOf(badge) >= 0; })); return app; }); exports.button = (button) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield util_1.expectText(app, button.label || button.mode)(Selectors.SIDECAR_TOOLBAR_BUTTON(button.mode)); return app; }); exports.limit = (type, expectedValue) => (app) => __awaiter(void 0, void 0, void 0, function* () { const expect = {}; expect[type] = expectedValue; return app.client .click(Selectors.SIDECAR_MODE_BUTTON('limits')) .then(() => app.client.getText(Selectors.SIDECAR_ACTION_SOURCE)) .then(util_1.expectSubset(expect)); }); exports.sequence = (A) => (app) => { return Promise.all(A.map((component, idx) => { const selector = `${Selectors.SIDECAR_SEQUENCE_CANVAS_NODE_N(idx)}[data-name="/_/${component}"]`; console.error(`Waiting for ${selector}`); return app.client.waitForExist(selector); })); }; exports.mode = (expectedMode) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitUntil(() => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitForVisible(`${Selectors.SIDECAR_MODE_BUTTON(expectedMode)}.bx--tabs__nav-item--selected`); return true; })); return app; }); exports.toolbarText = (expect) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield util_1.expectText(app, expect.text)(Selectors.SIDECAR_TOOLBAR_TEXT(expect.type)); return app; }); const show = (expected, selector) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitUntil(() => __awaiter(void 0, void 0, void 0, function* () { return app.client .then(() => app.client.waitForText(selector, cli_1.timeout)) .then(() => app.client.getText(selector)) .then(text => text === expected); })); return app; }); exports.name = (expectedName) => show(expectedName, Selectors.SIDECAR_TITLE); exports.namespace = (expectedNamespace) => show(expectedNamespace, Selectors.SIDECAR_PACKAGE_NAME_TITLE); exports.kind = (expectedKind) => show(expectedKind, Selectors.SIDECAR_KIND); const _mode = (expected) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitUntil(() => __awaiter(void 0, void 0, void 0, function* () { const actualMode = `${Selectors.SIDECAR_MODE_BUTTON(expected.mode)}`; yield app.client.waitForVisible(actualMode); if (expected.label) { const actualLabel = yield app.client.getText(actualMode); return actualLabel.toLowerCase() === expected.label.toLowerCase(); } else { return true; } })); return app; }); exports.modes = (expected) => (app) => __awaiter(void 0, void 0, void 0, function* () { return Promise.all(expected.map(_ => _mode(_)(app))).then(() => app); }); exports.textPlainContent = (content) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield util_1.expectText(app, content)(Selectors.SIDECAR_CUSTOM_CONTENT); return app; }); exports.yaml = (content) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitUntil(() => __awaiter(void 0, void 0, void 0, function* () { const ok = yield util_1.getValueFromMonaco(app).then(util_1.expectYAMLSubset(content, false)); return ok; })); return app; }); exports.showing = (expectedName, expectedActivationId, expectSubstringMatchOnName, expectedPackageName, expectType, waitThisLong) => (app) => __awaiter(void 0, void 0, void 0, function* () { yield app.client.waitUntil(() => __awaiter(void 0, void 0, void 0, function* () { return app.client .waitForVisible(`${Selectors.SIDECAR}${!expectType ? '' : '.entity-is-' + expectType}`) .then(() => app.client.waitForText(Selectors.SIDECAR_TITLE, cli_1.timeout)) .then(() => app.client.getText(Selectors.SIDECAR_TITLE)) .then(name => { const nameMatches = expectSubstringMatchOnName ? name.indexOf(expectedName) >= 0 || expectedName.indexOf(name) >= 0 : name === expectedName; if (nameMatches) { if (expectedPackageName) { return app.client .getText(Selectors.SIDECAR_PACKAGE_NAME_TITLE) .then(name => expectSubstringMatchOnName ? name.search(new RegExp(expectedPackageName, 'i')) >= 0 : name.toLowerCase() === expectedPackageName.toLowerCase()); } else { return true; } } }); }), waitThisLong, `expect action name ${expectedName} in sidecar substringOk? ${expectSubstringMatchOnName}`); if (expectedActivationId) { yield app.client.waitUntil(() => __awaiter(void 0, void 0, void 0, function* () { return app.client .waitForText(Selectors.SIDECAR_ACTIVATION_TITLE, cli_1.timeout) .then(() => app.client.getText(Selectors.SIDECAR_ACTIVATION_TITLE)) .then(id => id === expectedActivationId); }), cli_1.timeout, `expect activation id ${expectedActivationId} in sidecar`); } return app; }); //# sourceMappingURL=sidecar-expect.js.map