From 4b13cbdb33cad527c3dc0fe3f1d45c962b119c6e Mon Sep 17 00:00:00 2001 From: Deep Tailor Date: Tue, 23 Jun 2020 15:22:43 -0700 Subject: [PATCH] add test --- .../newFolderAction/newFolderAction.js | 11 ++-- src/plugins/newFolderAction/plugin.js | 4 +- src/plugins/newFolderAction/pluginSpec.js | 51 +++++++++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/plugins/newFolderAction/pluginSpec.js diff --git a/src/plugins/newFolderAction/newFolderAction.js b/src/plugins/newFolderAction/newFolderAction.js index 1c017d36af..98ac889e8f 100644 --- a/src/plugins/newFolderAction/newFolderAction.js +++ b/src/plugins/newFolderAction/newFolderAction.js @@ -30,7 +30,6 @@ export default class NewFolderAction { this.cssClass = 'icon-folder'; this._openmct = openmct; - this._dialogService = openmct.$injector.get('dialogService'); this._folderType = openmct.types.get('folder'); this._dialogForm = { name: "New Folder Name", @@ -51,9 +50,11 @@ export default class NewFolderAction { invoke(objectPath) { let domainObject = objectPath[0], parentKeystring = this._openmct.objects.makeKeyString(domainObject.identifier), - composition = this._openmct.composition.get(domainObject); + composition = this._openmct.composition.get(domainObject), + dialogService = this._openmct.$injector.get('dialogService'), + folderType = this._openmct.types.get('folder'); - this._dialogService.getUserInput(this._dialogForm, {}).then((userInput) => { + dialogService.getUserInput(this._dialogForm, {}).then((userInput) => { let name = userInput.name, identifier = { key: uuid(), @@ -65,8 +66,8 @@ export default class NewFolderAction { location: parentKeystring }; - this._folderType.definition.initialize(objectModel); - objectModel.name = name; + folderType.definition.initialize(objectModel); + objectModel.name = name || 'New Folder'; this._openmct.objects.mutate(objectModel, 'created', Date.now()); composition.add(objectModel); diff --git a/src/plugins/newFolderAction/plugin.js b/src/plugins/newFolderAction/plugin.js index 21bf2c4ef9..4d6b673a5e 100644 --- a/src/plugins/newFolderAction/plugin.js +++ b/src/plugins/newFolderAction/plugin.js @@ -23,8 +23,6 @@ import NewFolderAction from './newFolderAction'; export default function () { return function (openmct) { - openmct.on('start', () => { - openmct.contextMenu.registerAction(new NewFolderAction(openmct)); - }); + openmct.contextMenu.registerAction(new NewFolderAction(openmct)); }; } diff --git a/src/plugins/newFolderAction/pluginSpec.js b/src/plugins/newFolderAction/pluginSpec.js new file mode 100644 index 0000000000..d6f7d49406 --- /dev/null +++ b/src/plugins/newFolderAction/pluginSpec.js @@ -0,0 +1,51 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2020, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +import { + createOpenMct, + createMouseEvent, + spyOnBuiltins, + resetApplicationState +} from 'utils/testing'; + +fdescribe("the plugin", () => { + let openmct, + newFolderAction; + + beforeAll(() => { + resetApplicationState(); + }); + + beforeEach((done) => { + openmct = createOpenMct(); + + openmct.on('start', done); + openmct.startHeadless(); + + newFolderAction = openmct.contextMenu._allActions.filter(action => { + return action.key === 'newFolder'; + })[0]; + }); + + it('installs the new folder action', () => { + expect(newFolderAction).toBeDefined(); + }); +});