UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

131 lines • 6.32 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 spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); const test_utils_1 = require("@sprucelabs/test-utils"); const AbstractSkillTest_1 = __importDefault(require("../../../tests/AbstractSkillTest")); const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility")); class KeepingViewsInSyncTest extends AbstractSkillTest_1.default { static skillCacheKey = 'views'; static action; static async beforeEach() { await super.beforeEach(); this.action = this.Action('view', 'sync'); } static async hasSyncAction() { test_utils_1.assert.isFunction(this.action.execute); } static async syncingWithNoViewsGeneratesNothing() { const results = await this.action.execute(); test_utils_1.assert.isFalsy(results.errors); test_utils_1.assert.isFalsy(results.files); } static async createsValidCombinedEventsFileWhenCreatingANewSvc() { const results = await this.Action('view', 'create').execute({ viewType: 'skillView', isRoot: true, }); await this.assertValuedViewsFile(results); } static async generatesValidTypesFileWithNoSkillViews() { await this.createCardViewController('test'); } static async exportUndefinedApp() { const testScript = `import { App } from '#` + `spruce/views/views' if (App !== undefined) { throw new Error('App should be undefined') }`; const testScriptPath = this.resolvePath('src/test.ts'); spruce_skill_utils_1.diskUtil.writeFile(testScriptPath, testScript); await this.Service('typeChecker').check(testScriptPath); } static async alwaysRendersCombinedViewsFileAlphabetically() { await this.createCardViewController('apple bottom'); await this.createCardViewController('banana bottom'); await this.createCardViewController('zebra tooshie'); const contents = this.readCombinedViewsFile(); const vcsExpeced = `{ AppleBottomViewController, BananaBottomViewController, RootSkillViewController, TestViewController, ZebraTooshieViewController, }`; test_utils_1.assert.doesInclude(contents, vcsExpeced, 'views.ts vcs = {} out of order'); const viewControllerMapExpected = `'testing-views.apple-bottom': AppleBottomViewController 'testing-views.banana-bottom': BananaBottomViewController 'testing-views.root': RootSkillViewController 'testing-views.test': TestViewController 'testing-views.zebra-tooshie': ZebraTooshieViewController`; test_utils_1.assert.doesInclude(contents, viewControllerMapExpected, 'views.ts viewControllerMap out of order'); const viewControllerOptionsMapExpected = `'testing-views.apple-bottom': ConstructorParameters<typeof AppleBottomViewController>[0] 'testing-views.banana-bottom': ConstructorParameters<typeof BananaBottomViewController>[0] 'testing-views.test': ConstructorParameters<typeof TestViewController>[0] 'testing-views.zebra-tooshie': ConstructorParameters<typeof ZebraTooshieViewController>[0]`; test_utils_1.assert.doesInclude(contents, viewControllerOptionsMapExpected, 'views.ts viewControllerOptionsMap out of order'); } static async sortsSkillViewsAlphabetically() { await this.create({ viewType: 'skillView', nameReadable: 'Cheesey', isRoot: false, }); const skillViewControllerMapExpected = `'testing-views.cheesey': CheeseySkillViewController 'testing-views.root': RootSkillViewController`; const contents = this.readCombinedViewsFile(); test_utils_1.assert.doesInclude(contents, skillViewControllerMapExpected, 'views.ts skillViewControllerMap out of order'); } static readCombinedViewsFile() { return spruce_skill_utils_1.diskUtil.readFile(this.resolvePath('src/.spruce/views/views.ts')); } static async createCardViewController(name) { const options = { viewType: 'view', nameReadable: name, viewModel: 'Card', }; const results = await this.create(options); await this.assertValuedViewsFile(results); } static async create(options) { const results = await this.Action('view', 'create').execute(options); test_utils_1.assert.isFalsy(results.errors); return results; } static async assertValuedViewsFile(results) { const match = test_utility_1.default.assertFileByPathInGeneratedFiles(`views/views.ts`, results.files); await this.Service('typeChecker').check(match); } } exports.default = KeepingViewsInSyncTest; __decorate([ (0, test_utils_1.test)() ], KeepingViewsInSyncTest, "hasSyncAction", null); __decorate([ (0, test_utils_1.test)() ], KeepingViewsInSyncTest, "syncingWithNoViewsGeneratesNothing", null); __decorate([ (0, test_utils_1.test)() ], KeepingViewsInSyncTest, "createsValidCombinedEventsFileWhenCreatingANewSvc", null); __decorate([ (0, test_utils_1.test)() ], KeepingViewsInSyncTest, "generatesValidTypesFileWithNoSkillViews", null); __decorate([ (0, test_utils_1.test)() ], KeepingViewsInSyncTest, "exportUndefinedApp", null); __decorate([ (0, test_utils_1.test)() ], KeepingViewsInSyncTest, "alwaysRendersCombinedViewsFileAlphabetically", null); __decorate([ (0, test_utils_1.test)() ], KeepingViewsInSyncTest, "sortsSkillViewsAlphabetically", null); //# sourceMappingURL=KeepingViewsInSync.test.js.map