From 99aa5c7b7b4b5bf4eaadb0558342d81972498878 Mon Sep 17 00:00:00 2001 From: Jamie Vigliotta Date: Thu, 2 Jul 2020 10:14:14 -0700 Subject: [PATCH 1/6] few more tests, not ready yet though --- src/plugins/remove/pluginSpec.js | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/plugins/remove/pluginSpec.js diff --git a/src/plugins/remove/pluginSpec.js b/src/plugins/remove/pluginSpec.js new file mode 100644 index 0000000000..eb8e4a17bc --- /dev/null +++ b/src/plugins/remove/pluginSpec.js @@ -0,0 +1,63 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2018, 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 RemoveAction from './plugin.js'; +import { + createOpenMct, + resetApplicationState +} from 'utils/testing'; + +fdescribe("The Remove Action plugin", () => { + + let openmct, + removeActionPlugin; + + // this setups up the app + beforeEach((done) => { + const appHolder = document.createElement('div'); + appHolder.style.width = '640px'; + appHolder.style.height = '480px'; + + openmct = createOpenMct(); + + spyOn(openmct.objects, 'mutate') + + // already installed by default, but never hurts + removeActionPlugin = new RemoveAction(openmct); + openmct.install(removeActionPlugin()); + + openmct.on('start', done); + openmct.startHeadless(appHolder); + }); + + afterEach(() => { + resetApplicationState(openmct); + }); + + it("should be definied", () => { + expect(removeActionPlugin).toBeDefined(); + }); + + it("should remove a child from parent composition", () => { + + expect(true).toBe(true); + }); +}); From 731ab895611c73614d601974417135349ba36bb7 Mon Sep 17 00:00:00 2001 From: Jamie Vigliotta Date: Mon, 6 Jul 2020 14:05:32 -0700 Subject: [PATCH 2/6] added some tests for remove action as well as another mock object "folder" --- src/plugins/remove/pluginSpec.js | 77 +++++++++++++++++++++++++++----- src/utils/testing.js | 7 +++ 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/plugins/remove/pluginSpec.js b/src/plugins/remove/pluginSpec.js index eb8e4a17bc..88ec141480 100644 --- a/src/plugins/remove/pluginSpec.js +++ b/src/plugins/remove/pluginSpec.js @@ -19,16 +19,20 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ -import RemoveAction from './plugin.js'; +import RemoveActionPlugin from './plugin.js'; +import RemoveAction from './RemoveAction.js'; import { createOpenMct, - resetApplicationState + resetApplicationState, + getMockObjects } from 'utils/testing'; fdescribe("The Remove Action plugin", () => { let openmct, - removeActionPlugin; + removeAction, + childObject, + parentObject; // this setups up the app beforeEach((done) => { @@ -38,11 +42,27 @@ fdescribe("The Remove Action plugin", () => { openmct = createOpenMct(); - spyOn(openmct.objects, 'mutate') + childObject = getMockObjects({ + objectKeyStrings: ['folder'], + overwrite: { + folder: { + name: "Child Folder", + identifier: { namespace: "", key: "child-folder-object" } + } + } + }).folder; + parentObject = getMockObjects({ + objectKeyStrings: ['folder'], + overwrite: { + folder: { + name: "Parent Folder", + composition: [childObject.identifier] + } + } + }).folder; - // already installed by default, but never hurts - removeActionPlugin = new RemoveAction(openmct); - openmct.install(removeActionPlugin()); + // already installed by default, but never hurts, just adds to context menu + openmct.install(RemoveActionPlugin()); openmct.on('start', done); openmct.startHeadless(appHolder); @@ -53,11 +73,46 @@ fdescribe("The Remove Action plugin", () => { }); it("should be definied", () => { - expect(removeActionPlugin).toBeDefined(); + expect(RemoveActionPlugin).toBeDefined(); }); - it("should remove a child from parent composition", () => { - - expect(true).toBe(true); + describe("when removeFromComposition is invoked", () => { + + beforeEach(() => { + removeAction = new RemoveAction(openmct); + spyOn(removeAction, 'removeFromComposition').and.callThrough(); + spyOn(removeAction, 'inNavigationPath').and.returnValue(false); + spyOn(openmct.objects, 'mutate').and.callThrough(); + removeAction.removeFromComposition(parentObject, childObject); + }); + + it("it should be called", () => { + expect(removeAction.removeFromComposition).toHaveBeenCalled(); + expect(removeAction.removeFromComposition).toHaveBeenCalledWith(parentObject, childObject); + }); + + it("it should mutate the parent object", () => { + expect(openmct.objects.mutate).toHaveBeenCalled(); + expect(openmct.objects.mutate.calls.argsFor(0)[0]).toEqual(parentObject); + }); + }); + + describe("when appliesTo is called", () => { + + beforeEach(() => { + removeAction = new RemoveAction(openmct); + spyOn(removeAction, 'appliesTo').and.callThrough(); + }); + + it("should be true when the parent is creatable and has composition", () => { + let applies = removeAction.appliesTo([childObject, parentObject]); + expect(applies).toBe(true); + }); + + it("should be false when the child is locked", () => { + childObject.locked = true; + let applies = removeAction.appliesTo([childObject, parentObject]); + expect(applies).toBe(false); + }); }); }); diff --git a/src/utils/testing.js b/src/utils/testing.js index 362b6ffc2c..0609874780 100644 --- a/src/utils/testing.js +++ b/src/utils/testing.js @@ -227,6 +227,13 @@ function copyObj(obj) { function setMockObjects() { return { default: { + folder: { + identifier: { namespace: "", key: "folder-object" }, + name: "Test Folder Object", + type: "folder", + composition: [], + location: "mine" + }, ladTable: { identifier: { namespace: "", key: "lad-object"}, type: 'LadTable', From 7dee6344b097b71767e2e1ba312b0f30c802fda4 Mon Sep 17 00:00:00 2001 From: Jamie Vigliotta Date: Mon, 6 Jul 2020 14:14:57 -0700 Subject: [PATCH 3/6] updating spec statements to be more broad --- src/plugins/remove/pluginSpec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/remove/pluginSpec.js b/src/plugins/remove/pluginSpec.js index 88ec141480..dcf1083c58 100644 --- a/src/plugins/remove/pluginSpec.js +++ b/src/plugins/remove/pluginSpec.js @@ -76,7 +76,7 @@ fdescribe("The Remove Action plugin", () => { expect(RemoveActionPlugin).toBeDefined(); }); - describe("when removeFromComposition is invoked", () => { + describe("when removing an object from a parent composition", () => { beforeEach(() => { removeAction = new RemoveAction(openmct); @@ -86,7 +86,7 @@ fdescribe("The Remove Action plugin", () => { removeAction.removeFromComposition(parentObject, childObject); }); - it("it should be called", () => { + it("removeFromComposition should be called with the parent and child", () => { expect(removeAction.removeFromComposition).toHaveBeenCalled(); expect(removeAction.removeFromComposition).toHaveBeenCalledWith(parentObject, childObject); }); @@ -97,7 +97,7 @@ fdescribe("The Remove Action plugin", () => { }); }); - describe("when appliesTo is called", () => { + describe("when determining the object is applicable", () => { beforeEach(() => { removeAction = new RemoveAction(openmct); From e1d0c22071e8bbf7ed6fedad6556c44384dec1e1 Mon Sep 17 00:00:00 2001 From: Jamie Vigliotta Date: Mon, 6 Jul 2020 15:27:38 -0700 Subject: [PATCH 4/6] removing fdescribe --- src/plugins/remove/pluginSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/remove/pluginSpec.js b/src/plugins/remove/pluginSpec.js index dcf1083c58..866b6db371 100644 --- a/src/plugins/remove/pluginSpec.js +++ b/src/plugins/remove/pluginSpec.js @@ -27,7 +27,7 @@ import { getMockObjects } from 'utils/testing'; -fdescribe("The Remove Action plugin", () => { +describe("The Remove Action plugin", () => { let openmct, removeAction, From 79c4dc9272f1350e94142cf511d8d56b6b537676 Mon Sep 17 00:00:00 2001 From: Jamie Vigliotta Date: Mon, 13 Jul 2020 14:42:01 -0700 Subject: [PATCH 5/6] typo fix! and using object assign where appropriate --- src/plugins/remove/pluginSpec.js | 2 +- src/utils/testing.js | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/plugins/remove/pluginSpec.js b/src/plugins/remove/pluginSpec.js index 866b6db371..eb5d35c421 100644 --- a/src/plugins/remove/pluginSpec.js +++ b/src/plugins/remove/pluginSpec.js @@ -72,7 +72,7 @@ describe("The Remove Action plugin", () => { resetApplicationState(openmct); }); - it("should be definied", () => { + it("should be defined", () => { expect(RemoveActionPlugin).toBeDefined(); }); diff --git a/src/utils/testing.js b/src/utils/testing.js index 0609874780..20a1cdea60 100644 --- a/src/utils/testing.js +++ b/src/utils/testing.js @@ -166,11 +166,7 @@ export function getMockObjects(opts = {}) { if(opts.overwrite) { for(let mock in requestedMocks) { if(opts.overwrite[mock]) { - for(let key in opts.overwrite[mock]) { - if (Object.prototype.hasOwnProperty.call(opts.overwrite[mock], key)) { - requestedMocks[mock][key] = opts.overwrite[mock][key]; - } - } + requestedMocks[mock] = Object.assign(requestedMocks[mock], opts.overwrite[mock]); } } } From 69a6cd20af4740fd8d646779eb2384f1382ab6fc Mon Sep 17 00:00:00 2001 From: Jamie Vigliotta Date: Tue, 11 Aug 2020 13:01:54 -0700 Subject: [PATCH 6/6] linting --- src/plugins/remove/pluginSpec.js | 13 ++++++++----- src/utils/testing.js | 11 +++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/plugins/remove/pluginSpec.js b/src/plugins/remove/pluginSpec.js index eb5d35c421..6b52da8c6a 100644 --- a/src/plugins/remove/pluginSpec.js +++ b/src/plugins/remove/pluginSpec.js @@ -29,10 +29,10 @@ import { describe("The Remove Action plugin", () => { - let openmct, - removeAction, - childObject, - parentObject; + let openmct; + let removeAction; + let childObject; + let parentObject; // this setups up the app beforeEach((done) => { @@ -47,7 +47,10 @@ describe("The Remove Action plugin", () => { overwrite: { folder: { name: "Child Folder", - identifier: { namespace: "", key: "child-folder-object" } + identifier: { + namespace: "", + key: "child-folder-object" + } } } }).folder; diff --git a/src/utils/testing.js b/src/utils/testing.js index b790a959bc..0c2327c2b7 100644 --- a/src/utils/testing.js +++ b/src/utils/testing.js @@ -190,9 +190,9 @@ export function getMockObjects(opts = {}) { } // overwrite any field keys - if(opts.overwrite) { - for(let mock in requestedMocks) { - if(opts.overwrite[mock]) { + if (opts.overwrite) { + for (let mock in requestedMocks) { + if (opts.overwrite[mock]) { requestedMocks[mock] = Object.assign(requestedMocks[mock], opts.overwrite[mock]); } } @@ -251,7 +251,10 @@ function setMockObjects() { return { default: { folder: { - identifier: { namespace: "", key: "folder-object" }, + identifier: { + namespace: "", + key: "folder-object" + }, name: "Test Folder Object", type: "folder", composition: [],