UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

159 lines • 6.39 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 ScriptPlayer_1 = __importDefault(require("../../features/onboard/ScriptPlayer")); const AbstractCliTest_1 = __importDefault(require("../../tests/AbstractCliTest")); class OnboardingScriptPlayerTest extends AbstractCliTest_1.default { static player; static commandExecuterCommands = []; static async beforeEach() { await super.beforeEach(); const store = this.Store('onboarding'); this.commandExecuterCommands = []; this.player = new ScriptPlayer_1.default({ ui: this.ui, onboardingStore: store, commandExecuter: async (command) => { this.commandExecuterCommands.push(command); }, }); } static canCreateScriptPlayer() { test_utils_1.assert.isTruthy(this.player); } static async canPlayTextScript() { await this.player.playScript(['Hey there!']); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'Hey there!' }, }); } static async canPlayCallback() { await this.player.playScript([ (player) => { player.ui.renderLine('hello world'); }, ]); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'hello world' }, }); } static async canPlayAsyncCallback() { await this.player.playScript([ async (player) => { player.ui.renderLine('hello async world'); }, ]); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'hello async world' }, }); } static async throwsWithBadScriptKey() { await test_utils_1.assert.doesThrowAsync(() => this.player.playScriptWithKey('not-found')); } static async canLoadScriptsByKey() { this.player.loadScript('first', ['hey there', 'how are you']); this.player.loadScript('second', ['hey there 2', 'how are you 2']); await this.player.playScriptWithKey('first'); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'hey there' }, }); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'how are you' }, }); await this.player.playScriptWithKey('second'); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'hey there 2' }, }); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'how are you 2' }, }); } static async onScriptCanRedirectToAnother() { this.player.loadScript('first', [ 'hey there', 'how are you', ScriptPlayer_1.default.redirect('second'), ]); this.player.loadScript('second', [ 'hey there 2', 'how are you 2', (player) => player.redirect('third'), ]); this.player.loadScript('third', ['hey there 3', 'how are you 3']); await this.player.playScriptWithKey('first'); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'hey there 2' }, }); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'how are you 2' }, }); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderLine', options: { message: 'how are you 3' }, }); } static async scriptsCanAccessOnboardingStore() { await this.player.playScript([ async (player) => { const mode = player.onboardingStore.getMode(); test_utils_1.assert.isEqual(mode, 'off'); }, ]); } static async canInvokeCommand() { await this.player.playScript([ async (player) => { await player.executeCommand('test.command'); }, ]); test_utils_1.assert.isLength(this.commandExecuterCommands, 1); test_utils_1.assert.isEqual(this.commandExecuterCommands[0], 'test.command'); } } exports.default = OnboardingScriptPlayerTest; __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "canCreateScriptPlayer", null); __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "canPlayTextScript", null); __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "canPlayCallback", null); __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "canPlayAsyncCallback", null); __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "throwsWithBadScriptKey", null); __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "canLoadScriptsByKey", null); __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "onScriptCanRedirectToAnother", null); __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "scriptsCanAccessOnboardingStore", null); __decorate([ (0, test_utils_1.test)() ], OnboardingScriptPlayerTest, "canInvokeCommand", null); //# sourceMappingURL=OnboardingScriptPlayer.test.js.map