From 333e8b5583cd3b707a58266096e1d529a3d89df8 Mon Sep 17 00:00:00 2001 From: David Tsay <3614296+davetsay@users.noreply.github.com> Date: Fri, 18 Jun 2021 16:06:15 -0700 Subject: [PATCH] [Testing] Resolve all promises (#3829) * all promises in test specs should be returned Co-authored-by: Shefali Joshi Co-authored-by: Andrew Henry --- src/plugins/CouchDBSearchFolder/pluginSpec.js | 4 +- src/plugins/LADTable/pluginSpec.js | 91 +++------ .../URLIndicatorPlugin/URLIndicatorSpec.js | 6 +- .../autoflow/AutoflowTabularPluginSpec.js | 10 +- src/plugins/duplicate/pluginSpec.js | 13 +- src/plugins/goToOriginalAction/pluginSpec.js | 172 +++++++++++++++--- src/plugins/interceptors/pluginSpec.js | 19 +- src/plugins/move/pluginSpec.js | 16 +- src/plugins/newFolderAction/pluginSpec.js | 2 +- .../notebook/utils/notebook-entriesSpec.js | 7 +- .../notebook/utils/notebook-storageSpec.js | 3 +- src/plugins/plan/pluginSpec.js | 9 +- src/plugins/plot/pluginSpec.js | 2 +- src/plugins/remove/pluginSpec.js | 17 +- src/plugins/tabs/pluginSpec.js | 10 +- src/plugins/timeline/pluginSpec.js | 10 +- 16 files changed, 227 insertions(+), 164 deletions(-) diff --git a/src/plugins/CouchDBSearchFolder/pluginSpec.js b/src/plugins/CouchDBSearchFolder/pluginSpec.js index 58bdb1d75e..15eff8801f 100644 --- a/src/plugins/CouchDBSearchFolder/pluginSpec.js +++ b/src/plugins/CouchDBSearchFolder/pluginSpec.js @@ -73,7 +73,7 @@ describe('the plugin', function () { }); it('provides a folder to hold plans', () => { - openmct.objects.get(identifier).then((object) => { + return openmct.objects.get(identifier).then((object) => { expect(object).toEqual({ identifier, type: 'folder', @@ -83,7 +83,7 @@ describe('the plugin', function () { }); it('provides composition for couch search folders', () => { - composition.load().then((objects) => { + return composition.load().then((objects) => { expect(objects.length).toEqual(2); }); }); diff --git a/src/plugins/LADTable/pluginSpec.js b/src/plugins/LADTable/pluginSpec.js index 4dc902125e..329eeb5452 100644 --- a/src/plugins/LADTable/pluginSpec.js +++ b/src/plugins/LADTable/pluginSpec.js @@ -67,10 +67,6 @@ describe("The LAD Table", () => { // this setups up the app beforeEach((done) => { - const appHolder = document.createElement('div'); - appHolder.style.width = '640px'; - appHolder.style.height = '480px'; - openmct = createOpenMct(); parent = document.createElement('div'); @@ -90,7 +86,7 @@ describe("The LAD Table", () => { }); openmct.on('start', done); - openmct.startHeadless(appHolder); + openmct.startHeadless(); }); afterEach(() => { @@ -113,7 +109,8 @@ describe("The LAD Table", () => { beforeEach(() => { ladTableCompositionCollection = openmct.composition.get(mockObj.ladTable); - ladTableCompositionCollection.load(); + + return ladTableCompositionCollection.load(); }); it("should accept telemetry producing objects", () => { @@ -192,8 +189,6 @@ describe("The LAD Table", () => { await Promise.all([telemetryRequestPromise, telemetryObjectPromise, anotherTelemetryObjectPromise]); await Vue.nextTick(); - - return; }); it("should show one row per object in the composition", () => { @@ -242,13 +237,6 @@ describe("The LAD Table Set", () => { let ladPlugin; let parent; let child; - let telemetryCount = 3; - let timeFormat = 'utc'; - - let mockTelemetry = getMockTelemetry({ - count: telemetryCount, - format: timeFormat - }); let mockObj = getMockObjects({ objectKeyStrings: ['ladTable', 'ladTableSet', 'telemetry'] @@ -264,31 +252,22 @@ describe("The LAD Table Set", () => { mockObj.ladTableSet.composition.push(mockObj.ladTable.identifier); beforeEach((done) => { - const appHolder = document.createElement('div'); - - appHolder.style.width = '640px'; - appHolder.style.height = '480px'; - openmct = createOpenMct(); parent = document.createElement('div'); child = document.createElement('div'); parent.appendChild(child); - spyOn(openmct.telemetry, 'request').and.returnValue(Promise.resolve([])); - ladPlugin = new LadPlugin(); openmct.install(ladPlugin); - spyOn(openmct.objects, 'get').and.returnValue(Promise.resolve({})); - openmct.time.bounds({ start: bounds.start, end: bounds.end }); openmct.on('start', done); - openmct.start(appHolder); + openmct.startHeadless(); }); afterEach(() => { @@ -301,6 +280,8 @@ describe("The LAD Table Set", () => { }); it("should provide a lad table set view only for lad table set objects", () => { + spyOn(openmct.objects, 'get').and.returnValue(Promise.resolve({})); + let applicableViews = openmct.objectViews.get(mockObj.ladTableSet, []); let ladTableSetView = applicableViews.find( @@ -315,8 +296,11 @@ describe("The LAD Table Set", () => { let ladTableSetCompositionCollection; beforeEach(() => { + spyOn(openmct.objects, 'get').and.returnValue(Promise.resolve({})); + ladTableSetCompositionCollection = openmct.composition.get(mockObj.ladTableSet); - ladTableSetCompositionCollection.load(); + + return ladTableSetCompositionCollection.load(); }); it("should accept lad table objects", () => { @@ -354,41 +338,17 @@ describe("The LAD Table Set", () => { otherObj.ladTable.composition.push(mockObj.telemetry.identifier); mockObj.ladTableSet.composition.push(otherObj.ladTable.identifier); - beforeEach(async () => { - let telemetryRequestResolve; - let ladObjectResolve; - let anotherLadObjectResolve; + beforeEach(() => { + spyOn(openmct.telemetry, 'request').and.returnValue(Promise.resolve([])); - let telemetryRequestPromise = new Promise((resolve) => { - telemetryRequestResolve = resolve; - }); - - let ladObjectPromise = new Promise((resolve) => { - ladObjectResolve = resolve; - }); - - let anotherLadObjectPromise = new Promise((resolve) => { - anotherLadObjectResolve = resolve; - }); - - openmct.telemetry.request.and.callFake(() => { - telemetryRequestResolve(mockTelemetry); - - return telemetryRequestPromise; - }); - - openmct.objects.get.and.callFake((obj) => { + spyOn(openmct.objects, 'get').and.callFake((obj) => { if (obj.key === 'lad-object') { - ladObjectResolve(mockObj.ladObject); - - return ladObjectPromise; + return Promise.resolve(mockObj.ladTable); } else if (obj.key === 'another-lad-object') { - anotherLadObjectResolve(otherObj.ladObject); - - return anotherLadObjectPromise; + return Promise.resolve(otherObj.ladTable); + } else if (obj.key === 'telemetry-object') { + return Promise.resolve(mockObj.telemetry); } - - return Promise.resolve({}); }); openmct.time.bounds({ @@ -399,20 +359,19 @@ describe("The LAD Table Set", () => { applicableViews = openmct.objectViews.get(mockObj.ladTableSet, []); ladTableSetViewProvider = applicableViews.find((viewProvider) => viewProvider.key === ladTableSetKey); ladTableSetView = ladTableSetViewProvider.view(mockObj.ladTableSet, [mockObj.ladTableSet]); - ladTableSetView.show(child, true); + ladTableSetView.show(child); - await Promise.all([telemetryRequestPromise, ladObjectPromise, anotherLadObjectPromise]); - await Vue.nextTick(); - - return; + return Vue.nextTick(); }); it("should show one row per lad table object in the composition", () => { - const rowCount = parent.querySelectorAll(LAD_SET_TABLE_HEADERS).length; + const ladTableSetCompositionCollection = openmct.composition.get(mockObj.ladTableSet); - expect(rowCount).toBe(mockObj.ladTableSet.composition.length); - pending(); + return ladTableSetCompositionCollection.load().then(() => { + const rowCount = parent.querySelectorAll(LAD_SET_TABLE_HEADERS).length; + + expect(rowCount).toBe(mockObj.ladTableSet.composition.length); + }); }); }); }); - diff --git a/src/plugins/URLIndicatorPlugin/URLIndicatorSpec.js b/src/plugins/URLIndicatorPlugin/URLIndicatorSpec.js index ce1d32cfc0..0c45938f58 100644 --- a/src/plugins/URLIndicatorPlugin/URLIndicatorSpec.js +++ b/src/plugins/URLIndicatorPlugin/URLIndicatorSpec.js @@ -22,12 +22,14 @@ define( [ + "utils/testing", "./URLIndicator", "./URLIndicatorPlugin", "../../MCT", "zepto" ], function ( + testingUtils, URLIndicator, URLIndicatorPlugin, MCT, @@ -44,7 +46,7 @@ define( beforeEach(function () { jasmine.clock().install(); - openmct = new MCT(); + openmct = new testingUtils.createOpenMct(); spyOn(openmct.indicators, 'add'); spyOn($, 'ajax'); $.ajax.and.callFake(function (options) { @@ -55,6 +57,8 @@ define( afterEach(function () { $.ajax = defaultAjaxFunction; jasmine.clock().uninstall(); + + return testingUtils.resetApplicationState(openmct); }); describe("on initialization", function () { diff --git a/src/plugins/autoflow/AutoflowTabularPluginSpec.js b/src/plugins/autoflow/AutoflowTabularPluginSpec.js index ae27e83858..f04cd51d70 100644 --- a/src/plugins/autoflow/AutoflowTabularPluginSpec.js +++ b/src/plugins/autoflow/AutoflowTabularPluginSpec.js @@ -28,8 +28,10 @@ import { resetApplicationState, spyOnBuiltins } from 'utils/testing'; +import Vue from 'vue'; -describe("AutoflowTabularPlugin", () => { +// TODO lots of its without expects +xdescribe("AutoflowTabularPlugin", () => { let testType; let testObject; let mockmct; @@ -51,7 +53,7 @@ describe("AutoflowTabularPlugin", () => { }); afterEach(() => { - resetApplicationState(mockmct); + return resetApplicationState(mockmct); }); it("installs a view provider", () => { @@ -101,7 +103,7 @@ describe("AutoflowTabularPlugin", () => { }); } - beforeEach((done) => { + beforeEach(() => { callbacks = {}; spyOnBuiltins(['requestAnimationFrame']); @@ -180,7 +182,7 @@ describe("AutoflowTabularPlugin", () => { view = provider.view(testObject); view.show(testContainer); - return done(); + return Vue.nextTick(); }); afterEach(() => { diff --git a/src/plugins/duplicate/pluginSpec.js b/src/plugins/duplicate/pluginSpec.js index 3666e1eb1c..cb61144977 100644 --- a/src/plugins/duplicate/pluginSpec.js +++ b/src/plugins/duplicate/pluginSpec.js @@ -121,10 +121,9 @@ describe("The Duplicate Action plugin", () => { describe("when moving an object to a new parent", () => { - beforeEach(async (done) => { + beforeEach(async () => { duplicateTask = new DuplicateTask(openmct); await duplicateTask.duplicate(parentObject, anotherParentObject); - done(); }); it("the duplicate child object's name (when not changing) should be the same as the original object", async () => { @@ -143,15 +142,15 @@ describe("The Duplicate Action plugin", () => { }); describe("when a new name is provided for the duplicated object", () => { - const NEW_NAME = 'New Name'; + it("the name is updated", () => { + const NEW_NAME = 'New Name'; + let childName; - beforeEach(() => { duplicateTask = new DuplicateAction(openmct); duplicateTask.updateNameCheck(parentObject, NEW_NAME); - }); - it("the name is updated", () => { - let childName = parentObject.name; + childName = parentObject.name; + expect(childName).toEqual(NEW_NAME); }); }); diff --git a/src/plugins/goToOriginalAction/pluginSpec.js b/src/plugins/goToOriginalAction/pluginSpec.js index 66d024459b..6bd428e2e6 100644 --- a/src/plugins/goToOriginalAction/pluginSpec.js +++ b/src/plugins/goToOriginalAction/pluginSpec.js @@ -24,10 +24,15 @@ import { resetApplicationState } from 'utils/testing'; -describe("the plugin", () => { +describe("the goToOriginalAction plugin", () => { let openmct; - let goToFolderAction; + let goToOriginalAction; + let mockRootFolder; + let mockSubFolder; + let mockSubSubFolder; + let mockObject; let mockObjectPath; + let hash; beforeEach((done) => { openmct = createOpenMct(); @@ -35,7 +40,7 @@ describe("the plugin", () => { openmct.on('start', done); openmct.startHeadless(); - goToFolderAction = openmct.actions._allActions.goToOriginal; + goToOriginalAction = openmct.actions._allActions.goToOriginal; }); afterEach(() => { @@ -43,34 +48,153 @@ describe("the plugin", () => { }); it('installs the go to folder action', () => { - expect(goToFolderAction).toBeDefined(); + expect(goToOriginalAction).toBeDefined(); }); describe('when invoked', () => { beforeEach(() => { - mockObjectPath = [{ - name: 'mock folder', - type: 'folder', - identifier: { - key: 'mock-folder', - namespace: '' - } - }]; - spyOn(openmct.objects, 'get').and.returnValue(Promise.resolve({ - identifier: { - namespace: '', - key: 'test' - } - })); + mockRootFolder = getMockObject('mock-root'); + mockSubFolder = getMockObject('mock-sub'); + mockSubSubFolder = getMockObject('mock-sub-sub'); + mockObject = getMockObject('mock-table'); - goToFolderAction.invoke(mockObjectPath); + mockObjectPath = [ + mockObject, + mockSubSubFolder, + mockSubFolder, + mockRootFolder + ]; + + spyOn(openmct.objects, 'get').and.callFake(identifier => { + const mockedObject = getMockObject(identifier); + + return Promise.resolve(mockedObject); + }); + + spyOn(openmct.router, 'navigate').and.callFake(navigateTo => { + hash = navigateTo; + }); + + return goToOriginalAction.invoke(mockObjectPath); }); - it('goes to the original location', (done) => { - setTimeout(() => { - expect(window.location.href).toContain('context.html#/browse/?tc.mode=fixed&tc.startBound=0&tc.endBound=1&tc.timeSystem=utc'); - done(); - }, 1500); + it('goes to the original location', () => { + const originalLocationHash = '#/browse/mock-root/mock-table'; + + return waitForNavigation(() => { + return hash === originalLocationHash; + }).then(() => { + expect(hash).toEqual(originalLocationHash); + }); }); }); + + function waitForNavigation(navigated) { + return new Promise((resolve, reject) => { + const start = Date.now(); + + checkNavigated(); + + function checkNavigated() { + const elapsed = Date.now() - start; + + if (navigated()) { + resolve(); + } else if (elapsed >= jasmine.DEFAULT_TIMEOUT_INTERVAL - 1000) { + reject("didn't navigate in time"); + } else { + setTimeout(checkNavigated); + } + } + }); + } + + function getMockObject(key) { + const id = typeof key === 'string' ? key : key.key; + + const mockMCTObjects = { + "ROOT": { + "composition": [ + { + "namespace": "", + "key": "mock-root" + } + ], + "identifier": { + "namespace": "", + "key": "mock-root" + } + }, + "mock-root": { + "composition": [ + { + "namespace": "", + "key": "mock-sub" + }, + { + "namespace": "", + "key": "mock-table" + } + ], + "name": "root", + "type": "folder", + "id": "mock-root", + "location": "ROOT", + "identifier": { + "namespace": "", + "key": "mock-root" + } + }, + "mock-sub": { + "composition": [ + { + "namespace": "", + "key": "mock-sub-sub" + }, + { + "namespace": "", + "key": "mock-table" + } + ], + "name": "sub", + "type": "folder", + "location": "mock-root", + "identifier": { + "namespace": "", + "key": "mock-sub" + } + }, + "mock-table": { + "composition": [], + "configuration": { + "columnWidths": {}, + "hiddenColumns": {} + }, + "name": "table", + "type": "table", + "location": "mock-root", + "identifier": { + "namespace": "", + "key": "mock-table" + } + }, + "mock-sub-sub": { + "composition": [ + { + "namespace": "", + "key": "mock-table" + } + ], + "name": "sub sub", + "type": "folder", + "location": "mock-sub", + "identifier": { + "namespace": "", + "key": "mock-sub-sub" + } + } + }; + + return mockMCTObjects[id]; + } }); diff --git a/src/plugins/interceptors/pluginSpec.js b/src/plugins/interceptors/pluginSpec.js index f96868f188..c5c6bfea72 100644 --- a/src/plugins/interceptors/pluginSpec.js +++ b/src/plugins/interceptors/pluginSpec.js @@ -30,10 +30,6 @@ describe('the plugin', function () { const TEST_NAMESPACE = 'test'; beforeEach((done) => { - const appHolder = document.createElement('div'); - appHolder.style.width = '640px'; - appHolder.style.height = '480px'; - openmct = createOpenMct(); openmct.install(new InterceptorPlugin(openmct)); @@ -46,7 +42,7 @@ describe('the plugin', function () { element.appendChild(child); openmct.on('start', done); - openmct.startHeadless(appHolder); + openmct.startHeadless(); }); afterEach(() => { @@ -55,6 +51,7 @@ describe('the plugin', function () { describe('the missingObjectInterceptor', () => { let mockProvider; + beforeEach(() => { mockProvider = jasmine.createSpyObj("mock provider", [ "get" @@ -63,27 +60,28 @@ describe('the plugin', function () { openmct.objects.addProvider(TEST_NAMESPACE, mockProvider); }); - it('returns missing objects', (done) => { + it('returns missing objects', () => { const identifier = { namespace: TEST_NAMESPACE, key: 'hello' }; - openmct.objects.get(identifier).then((testObject) => { + + return openmct.objects.get(identifier).then((testObject) => { expect(testObject).toEqual({ identifier, type: 'unknown', name: 'Missing: test:hello' }); - done(); }); }); - it('returns the My items object if not found', (done) => { + it('returns the My items object if not found', () => { const identifier = { namespace: TEST_NAMESPACE, key: 'mine' }; - openmct.objects.get(identifier).then((testObject) => { + + return openmct.objects.get(identifier).then((testObject) => { expect(testObject).toEqual({ identifier, "name": "My Items", @@ -91,7 +89,6 @@ describe('the plugin', function () { "composition": [], "location": "ROOT" }); - done(); }); }); diff --git a/src/plugins/move/pluginSpec.js b/src/plugins/move/pluginSpec.js index 5ee1c77e4c..cee1745c25 100644 --- a/src/plugins/move/pluginSpec.js +++ b/src/plugins/move/pluginSpec.js @@ -19,8 +19,6 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ -import MoveActionPlugin from './plugin.js'; -import MoveAction from './MoveAction.js'; import { createOpenMct, resetApplicationState, @@ -37,10 +35,6 @@ describe("The Move Action plugin", () => { // this setups up the app beforeEach((done) => { - const appHolder = document.createElement('div'); - appHolder.style.width = '640px'; - appHolder.style.height = '480px'; - openmct = createOpenMct(); childObject = getMockObjects({ @@ -73,11 +67,10 @@ describe("The Move Action plugin", () => { } }).folder; - // already installed by default, but never hurts, just adds to context menu - openmct.install(MoveActionPlugin()); - openmct.on('start', done); - openmct.startHeadless(appHolder); + openmct.startHeadless(); + + moveAction = openmct.actions._allActions.move; }); afterEach(() => { @@ -85,13 +78,12 @@ describe("The Move Action plugin", () => { }); it("should be defined", () => { - expect(MoveActionPlugin).toBeDefined(); + expect(moveAction).toBeDefined(); }); describe("when moving an object to a new parent and removing from the old parent", () => { beforeEach(() => { - moveAction = new MoveAction(openmct); moveAction.addToNewParent(childObject, anotherParentObject); moveAction.removeFromOldParent(parentObject, childObject); }); diff --git a/src/plugins/newFolderAction/pluginSpec.js b/src/plugins/newFolderAction/pluginSpec.js index daa70e906c..923a5f7b51 100644 --- a/src/plugins/newFolderAction/pluginSpec.js +++ b/src/plugins/newFolderAction/pluginSpec.js @@ -79,7 +79,7 @@ describe("the plugin", () => { spyOn(compositionAPI, 'get').and.returnValue(mockComposition); spyOn(openmct.objects, 'save').and.returnValue(Promise.resolve(true)); - newFolderAction.invoke(mockObjectPath); + return newFolderAction.invoke(mockObjectPath); }); it('gets user input for folder name', () => { diff --git a/src/plugins/notebook/utils/notebook-entriesSpec.js b/src/plugins/notebook/utils/notebook-entriesSpec.js index 4bdfece0a4..f2b528e747 100644 --- a/src/plugins/notebook/utils/notebook-entriesSpec.js +++ b/src/plugins/notebook/utils/notebook-entriesSpec.js @@ -112,7 +112,7 @@ let openmct; let mockIdentifierService; describe('Notebook Entries:', () => { - beforeEach(done => { + beforeEach(() => { openmct = createOpenMct(); openmct.$injector = jasmine.createSpyObj('$injector', ['get']); mockIdentifierService = jasmine.createSpyObj( @@ -134,8 +134,6 @@ describe('Notebook Entries:', () => { 'update' ])); window.localStorage.setItem('notebook-storage', null); - - done(); }); afterEach(() => { @@ -150,12 +148,11 @@ describe('Notebook Entries:', () => { expect(entries.length).toEqual(0); }); - it('addNotebookEntry adds entry', (done) => { + it('addNotebookEntry adds entry', () => { const unlisten = openmct.objects.observe(notebookDomainObject, '*', (object) => { const entries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage); expect(entries.length).toEqual(1); - done(); unlisten(); }); diff --git a/src/plugins/notebook/utils/notebook-storageSpec.js b/src/plugins/notebook/utils/notebook-storageSpec.js index b20709a543..4028ba9141 100644 --- a/src/plugins/notebook/utils/notebook-storageSpec.js +++ b/src/plugins/notebook/utils/notebook-storageSpec.js @@ -60,7 +60,7 @@ let openmct; let mockIdentifierService; describe('Notebook Storage:', () => { - beforeEach((done) => { + beforeEach(() => { openmct = createOpenMct(); openmct.$injector = jasmine.createSpyObj('$injector', ['get']); mockIdentifierService = jasmine.createSpyObj( @@ -79,7 +79,6 @@ describe('Notebook Storage:', () => { 'create', 'update' ])); - done(); }); afterEach(() => { diff --git a/src/plugins/plan/pluginSpec.js b/src/plugins/plan/pluginSpec.js index 9f3bf35701..e1d498cdec 100644 --- a/src/plugins/plan/pluginSpec.js +++ b/src/plugins/plan/pluginSpec.js @@ -29,9 +29,10 @@ describe('the plugin', function () { let element; let child; let openmct; + let appHolder; beforeEach((done) => { - const appHolder = document.createElement('div'); + appHolder = document.createElement('div'); appHolder.style.width = '640px'; appHolder.style.height = '480px'; @@ -103,7 +104,7 @@ describe('the plugin', function () { ]; let planView; - beforeEach((done) => { + beforeEach(() => { planDomainObject = { identifier: { key: 'test-object', @@ -140,9 +141,7 @@ describe('the plugin', function () { let view = planView.view(planDomainObject, mockObjectPath); view.show(child, true); - return Vue.nextTick().then(() => { - done(); - }); + return Vue.nextTick(); }); it('loads activities into the view', () => { diff --git a/src/plugins/plot/pluginSpec.js b/src/plugins/plot/pluginSpec.js index 951cc69bbf..586894a15f 100644 --- a/src/plugins/plot/pluginSpec.js +++ b/src/plugins/plot/pluginSpec.js @@ -34,6 +34,7 @@ describe("the plugin", function () { let child; let openmct; let telemetryPromise; + let telemetryPromiseResolve; let cleanupFirst; let mockObjectPath; let telemetrylimitProvider; @@ -78,7 +79,6 @@ describe("the plugin", function () { openmct = createOpenMct(); - let telemetryPromiseResolve; telemetryPromise = new Promise((resolve) => { telemetryPromiseResolve = resolve; }); diff --git a/src/plugins/remove/pluginSpec.js b/src/plugins/remove/pluginSpec.js index 91870392a3..887cc0a50c 100644 --- a/src/plugins/remove/pluginSpec.js +++ b/src/plugins/remove/pluginSpec.js @@ -19,8 +19,6 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ -import RemoveActionPlugin from './plugin.js'; -import RemoveAction from './RemoveAction.js'; import { createOpenMct, resetApplicationState, @@ -36,10 +34,6 @@ describe("The Remove Action plugin", () => { // this setups up the app beforeEach((done) => { - const appHolder = document.createElement('div'); - appHolder.style.width = '640px'; - appHolder.style.height = '480px'; - openmct = createOpenMct(); childObject = getMockObjects({ @@ -64,11 +58,10 @@ describe("The Remove Action plugin", () => { } }).folder; - // already installed by default, but never hurts, just adds to context menu - openmct.install(RemoveActionPlugin()); - openmct.on('start', done); - openmct.startHeadless(appHolder); + openmct.startHeadless(); + + removeAction = openmct.actions._allActions.remove; }); afterEach(() => { @@ -76,13 +69,12 @@ describe("The Remove Action plugin", () => { }); it("should be defined", () => { - expect(RemoveActionPlugin).toBeDefined(); + expect(removeAction).toBeDefined(); }); describe("when removing an object from a parent composition", () => { beforeEach(() => { - removeAction = new RemoveAction(openmct); spyOn(removeAction, 'removeFromComposition').and.callThrough(); spyOn(removeAction, 'inNavigationPath').and.returnValue(false); spyOn(openmct.objects, 'mutate').and.callThrough(); @@ -103,7 +95,6 @@ describe("The Remove Action plugin", () => { describe("when determining the object is applicable", () => { beforeEach(() => { - removeAction = new RemoveAction(openmct); spyOn(removeAction, 'appliesTo').and.callThrough(); }); diff --git a/src/plugins/tabs/pluginSpec.js b/src/plugins/tabs/pluginSpec.js index 065cb50693..610c2a0a99 100644 --- a/src/plugins/tabs/pluginSpec.js +++ b/src/plugins/tabs/pluginSpec.js @@ -113,7 +113,7 @@ describe('the plugin', function () { let tabsLayoutViewProvider; let mockComposition; - beforeEach((done) => { + beforeEach(() => { mockComposition = new EventEmitter(); mockComposition.load = () => { return Promise.resolve([telemetryItem1]); @@ -125,7 +125,8 @@ describe('the plugin', function () { tabsLayoutViewProvider = applicableViews.find((viewProvider) => viewProvider.key === 'tabs'); let view = tabsLayoutViewProvider.view(testViewObject, []); view.show(child, true); - Vue.nextTick(done); + + return Vue.nextTick(); }); it('provides a view', () => { @@ -150,7 +151,7 @@ describe('the plugin', function () { let mockComposition; let count = 0; - beforeEach((done) => { + beforeEach(() => { mockComposition = new EventEmitter(); mockComposition.load = () => { if (count === 0) { @@ -168,7 +169,8 @@ describe('the plugin', function () { tabsLayoutViewProvider = applicableViews.find((viewProvider) => viewProvider.key === 'tabs'); let view = tabsLayoutViewProvider.view(testViewObject, []); view.show(child, true); - Vue.nextTick(done); + + return Vue.nextTick(); }); it ('renders a tab for each item', () => { diff --git a/src/plugins/timeline/pluginSpec.js b/src/plugins/timeline/pluginSpec.js index 75f9c54695..87229d1882 100644 --- a/src/plugins/timeline/pluginSpec.js +++ b/src/plugins/timeline/pluginSpec.js @@ -50,9 +50,6 @@ describe('the plugin', function () { } } ]; - const appHolder = document.createElement('div'); - appHolder.style.width = '640px'; - appHolder.style.height = '480px'; openmct = createOpenMct(); openmct.install(new TimelinePlugin()); @@ -73,7 +70,7 @@ describe('the plugin', function () { }); openmct.on('start', done); - openmct.startHeadless(appHolder); + openmct.startHeadless(); }); afterEach(() => { @@ -100,7 +97,7 @@ describe('the plugin', function () { describe('the view', () => { let timelineView; - beforeEach((done) => { + beforeEach(() => { const testViewObject = { id: "test-object", type: "time-strip" @@ -110,7 +107,8 @@ describe('the plugin', function () { timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view'); let view = timelineView.view(testViewObject, element); view.show(child, true); - Vue.nextTick(done); + + return Vue.nextTick(); }); it('provides a view', () => {