UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

142 lines • 6.31 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const test_utils_1 = require("@sprucelabs/test-utils"); const AbstractSkillTest_1 = __importDefault(require("../../../tests/AbstractSkillTest")); class InstallingFeaturesDirectlyTest extends AbstractSkillTest_1.default { static action; static skillCacheKey = 'skills'; static async beforeEach() { await super.beforeEach(); this.action = this.Action('skill', 'installFeature'); } static async afterEach() { this.ui.reset(); await super.afterEach(); } static async hasExpectedAliases() { test_utils_1.assert.isEqualDeep(this.action.commandAliases, ['install.feature']); } static async promptsForWhichFeatureToInstall() { await this.executeAndWaitForPrompt(); const features = { error: 'Errors', event: 'Events', schema: 'Schemas', store: 'Stores (including database support)', test: 'Tests', view: 'Views', }; const choices = Object.keys(features).map((key) => ({ label: features[key], value: key, })); const last = this.ui.getLastInvocation(); test_utils_1.assert.isEqual(last.command, 'prompt'); test_utils_1.assert.isEqualDeep(last.options, { type: 'select', label: 'Which feature do you want to install?', isRequired: true, options: { choices, }, }); } static async selectingAFeatureTriesToInstallIt(featureCode) { let passedOption; this.featureInstaller.install = async (options) => { passedOption = options; return {}; }; await this.executeAndWaitForPrompt(); await this.sendInput(featureCode); test_utils_1.assert.isEqualDeep(passedOption, { features: [{ code: featureCode }] }); } static async returnsResultsFromFeatureInstall() { const results = { [(0, test_utils_1.generateId)()]: (0, test_utils_1.generateId)(), [(0, test_utils_1.generateId)()]: (0, test_utils_1.generateId)(), }; this.featureInstaller.install = async () => results; const { promise } = await this.executeAndWaitForPrompt(); await this.sendInput('store'); const actual = await promise; test_utils_1.assert.isEqualDeep(actual, results); } static async doesNotShowOptionForInstalledFeature(code) { this.featureInstaller.install = async () => ({}); const installed = ['skill', code]; this.featureInstaller.isInstalled = async (code) => installed.includes(code); await this.executeAndWaitForPrompt(); const { options } = this.ui.getLastInvocation(); const choices = options.options.choices; test_utils_1.assert.doesNotInclude(choices.map((c) => c.value), code); } static async ifThereAreNoFeaturesToInstallDonNotPrompt() { this.featureInstaller.isInstalled = async () => true; const results = await this.execute(); test_utils_1.assert.isEqualDeep(results, { summaryLines: [ 'Nothing to install, you have already installed everything!', ], }); } static async passingFeatureCodeToActionSkipsPrompt(code) { let passedOption; this.featureInstaller.install = async (options) => { passedOption = options; return {}; }; this.ui.prompt = async () => test_utils_1.assert.fail('Should not prompt'); await this.execute({ code }); test_utils_1.assert.isEqualDeep(passedOption, { features: [{ code }] }); } static async sendInput(featureCode) { await this.ui.sendInput(featureCode); } static async executeAndWaitForPrompt() { const promise = this.execute(); await this.ui.waitForInput(); return { promise }; } static execute(options) { return this.action.execute(options ?? {}); } } exports.default = InstallingFeaturesDirectlyTest; __decorate([ (0, test_utils_1.test)() ], InstallingFeaturesDirectlyTest, "hasExpectedAliases", null); __decorate([ (0, test_utils_1.test)() ], InstallingFeaturesDirectlyTest, "promptsForWhichFeatureToInstall", null); __decorate([ (0, test_utils_1.test)('can install store feature', 'store'), (0, test_utils_1.test)('can install view feature', 'view'), (0, test_utils_1.test)('can install test feature', 'test') ], InstallingFeaturesDirectlyTest, "selectingAFeatureTriesToInstallIt", null); __decorate([ (0, test_utils_1.test)() ], InstallingFeaturesDirectlyTest, "returnsResultsFromFeatureInstall", null); __decorate([ (0, test_utils_1.test)('skips view feature if already installed', 'view'), (0, test_utils_1.test)('skips store feature if already installed', 'store'), (0, test_utils_1.test)('skips test feature if already installed', 'test') ], InstallingFeaturesDirectlyTest, "doesNotShowOptionForInstalledFeature", null); __decorate([ (0, test_utils_1.test)() ], InstallingFeaturesDirectlyTest, "ifThereAreNoFeaturesToInstallDonNotPrompt", null); __decorate([ (0, test_utils_1.test)('should install directly view', 'view'), (0, test_utils_1.test)('should install directly store', 'store'), (0, test_utils_1.test)('should install directly test', 'test') ], InstallingFeaturesDirectlyTest, "passingFeatureCodeToActionSkipsPrompt", null); //# sourceMappingURL=InstallingFeaturesDirectly.test.js.map