Router test fix (#3973)

* removed DEPRECATION warnings
* test fixes
* added spec reporter to debug failing tests  and fixed couple specs
* disabled failFast to see all failing tests
* disabled fail test and  change timeoutInterval to 5000
* removed unused debounce import

Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
Nikhil 2021-10-21 16:55:34 -07:00 committed by GitHub
parent c269e089da
commit 4f8cba160d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 173 additions and 254 deletions

View File

@ -25,7 +25,7 @@
const devMode = process.env.NODE_ENV !== 'production'; const devMode = process.env.NODE_ENV !== 'production';
const browsers = [process.env.NODE_ENV === 'debug' ? 'ChromeDebugging' : 'ChromeHeadless']; const browsers = [process.env.NODE_ENV === 'debug' ? 'ChromeDebugging' : 'ChromeHeadless'];
const coverageEnabled = process.env.COVERAGE === 'true'; const coverageEnabled = process.env.COVERAGE === 'true';
const reporters = ['progress', 'html', 'junit']; const reporters = ['spec', 'html', 'junit'];
if (coverageEnabled) { if (coverageEnabled) {
reporters.push('coverage-istanbul'); reporters.push('coverage-istanbul');
@ -60,7 +60,7 @@ module.exports = (config) => {
client: { client: {
jasmine: { jasmine: {
random: false, random: false,
timeoutInterval: 30000 timeoutInterval: 5000
} }
}, },
customLaunchers: { customLaunchers: {
@ -88,11 +88,6 @@ module.exports = (config) => {
outputFile: "test-results.xml", outputFile: "test-results.xml",
useBrowserName: false useBrowserName: false
}, },
browserConsoleLogOptions: {
level: "error",
format: "%b %T: %m",
terminal: true
},
coverageIstanbulReporter: { coverageIstanbulReporter: {
fixWebpackSourcePaths: true, fixWebpackSourcePaths: true,
dir: process.env.CIRCLE_ARTIFACTS dir: process.env.CIRCLE_ARTIFACTS
@ -105,6 +100,15 @@ module.exports = (config) => {
} }
} }
}, },
specReporter: {
maxLogLines: 5,
suppressErrorSummary: true,
suppressFailed: false,
suppressPassed: false,
suppressSkipped: true,
showSpecTiming: true,
failFast: false
},
preprocessors: { preprocessors: {
'indexTest.js': ['webpack', 'sourcemap'] 'indexTest.js': ['webpack', 'sourcemap']
}, },

View File

@ -41,6 +41,7 @@
"karma-jasmine": "4.0.1", "karma-jasmine": "4.0.1",
"karma-junit-reporter": "2.0.1", "karma-junit-reporter": "2.0.1",
"karma-sourcemap-loader": "0.3.8", "karma-sourcemap-loader": "0.3.8",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "4.0.2", "karma-webpack": "4.0.2",
"location-bar": "^3.0.1", "location-bar": "^3.0.1",
"lodash": "^4.17.12", "lodash": "^4.17.12",

View File

@ -50,8 +50,6 @@ define(
* or finish() are called. * or finish() are called.
*/ */
EditorCapability.prototype.edit = function () { EditorCapability.prototype.edit = function () {
console.warn('DEPRECATED: cannot edit via edit capability, use openmct.editor instead.');
if (!this.openmct.editor.isEditing()) { if (!this.openmct.editor.isEditing()) {
this.openmct.editor.edit(); this.openmct.editor.edit();
this.domainObject.getCapability('status').set('editing', true); this.domainObject.getCapability('status').set('editing', true);
@ -82,8 +80,6 @@ define(
* @returns {*} * @returns {*}
*/ */
EditorCapability.prototype.save = function () { EditorCapability.prototype.save = function () {
console.warn('DEPRECATED: cannot save via edit capability, use openmct.editor instead.');
return Promise.resolve(); return Promise.resolve();
}; };
@ -95,8 +91,6 @@ define(
* @returns {*} * @returns {*}
*/ */
EditorCapability.prototype.finish = function () { EditorCapability.prototype.finish = function () {
console.warn('DEPRECATED: cannot finish via edit capability, use openmct.editor instead.');
return Promise.resolve(); return Promise.resolve();
}; };

View File

@ -28,8 +28,6 @@ export default function LegacyActionAdapter(openmct, legacyActions) {
return true; return true;
} }
console.warn(`DEPRECATION WARNING: Action ${action.definition.key} in bundle ${action.bundle.path} is non-contextual and should be migrated.`);
return false; return false;
} }

View File

@ -29,7 +29,6 @@ define([
'./capabilities/APICapabilityDecorator', './capabilities/APICapabilityDecorator',
'./policies/AdaptedViewPolicy', './policies/AdaptedViewPolicy',
'./runs/AlternateCompositionInitializer', './runs/AlternateCompositionInitializer',
'./runs/TypeDeprecationChecker',
'./runs/LegacyTelemetryProvider', './runs/LegacyTelemetryProvider',
'./runs/RegisterLegacyTypes', './runs/RegisterLegacyTypes',
'./services/LegacyObjectAPIInterceptor', './services/LegacyObjectAPIInterceptor',
@ -46,7 +45,6 @@ define([
APICapabilityDecorator, APICapabilityDecorator,
AdaptedViewPolicy, AdaptedViewPolicy,
AlternateCompositionInitializer, AlternateCompositionInitializer,
TypeDeprecationChecker,
LegacyTelemetryProvider, LegacyTelemetryProvider,
RegisterLegacyTypes, RegisterLegacyTypes,
LegacyObjectAPIInterceptor, LegacyObjectAPIInterceptor,
@ -135,10 +133,6 @@ define([
} }
], ],
runs: [ runs: [
{
implementation: TypeDeprecationChecker,
depends: ["types[]"]
},
{ {
implementation: AlternateCompositionInitializer, implementation: AlternateCompositionInitializer,
depends: ["openmct"] depends: ["openmct"]

View File

@ -4,12 +4,6 @@ define([
) { ) {
function RegisterLegacyTypes(types, openmct) { function RegisterLegacyTypes(types, openmct) {
types.forEach(function (legacyDefinition) {
if (!openmct.types.get(legacyDefinition.key)) {
console.warn(`DEPRECATION WARNING: Migrate type ${legacyDefinition.key} from ${legacyDefinition.bundle.path} to use the new Types API. Legacy type support will be removed soon.`);
}
});
openmct.types.importLegacyTypes(types); openmct.types.importLegacyTypes(types);
} }

View File

@ -1,46 +0,0 @@
/*****************************************************************************
* Open openmct, Copyright (c) 2014-2021, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open openmct 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 openmct 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.
*****************************************************************************/
define([
], function (
) {
function checkForDeprecatedFunctionality(typeDef) {
if (Object.prototype.hasOwnProperty.call(typeDef, 'telemetry')) {
console.warn(
'DEPRECATION WARNING: Telemetry data on type '
+ 'registrations will be deprecated in a future version, '
+ 'please convert to a custom telemetry metadata provider '
+ 'for type: ' + typeDef.key
);
}
}
function TypeDeprecationChecker(types) {
types.forEach(checkForDeprecatedFunctionality);
}
return TypeDeprecationChecker;
});

View File

@ -15,8 +15,6 @@ define([
}; };
function LegacyViewProvider(legacyView, openmct, convertToLegacyObject) { function LegacyViewProvider(legacyView, openmct, convertToLegacyObject) {
console.warn(`DEPRECATION WARNING: Migrate ${legacyView.key} from ${legacyView.bundle.path} to use the new View APIs. Legacy view support will be removed soon.`);
return { return {
key: legacyView.key, key: legacyView.key,
name: legacyView.name, name: legacyView.name,

View File

@ -4,7 +4,6 @@ define([
) { ) {
function TypeInspectorViewProvider(typeDefinition, openmct, convertToLegacyObject) { function TypeInspectorViewProvider(typeDefinition, openmct, convertToLegacyObject) {
console.warn(`DEPRECATION WARNING: Migrate ${typeDefinition.key} from ${typeDefinition.bundle.path} to use the new Inspector View APIs. Legacy Inspector view support will be removed soon.`);
let representation = openmct.$injector.get('representations[]') let representation = openmct.$injector.get('representations[]')
.filter((r) => r.key === typeDefinition.inspector)[0]; .filter((r) => r.key === typeDefinition.inspector)[0];

View File

@ -304,10 +304,15 @@ ObjectAPI.prototype.save = function (domainObject) {
savedResolve = resolve; savedResolve = resolve;
}); });
domainObject.persisted = persistedTime; domainObject.persisted = persistedTime;
provider.create(domainObject).then((response) => { const newObjectPromise = provider.create(domainObject);
this.mutate(domainObject, 'persisted', persistedTime); if (newObjectPromise) {
savedResolve(response); newObjectPromise.then(response => {
}); this.mutate(domainObject, 'persisted', persistedTime);
savedResolve(response);
});
} else {
result = Promise.reject(`[ObjectAPI][save] Object provider returned ${newObjectPromise} when creating new object.`);
}
} else { } else {
domainObject.persisted = persistedTime; domainObject.persisted = persistedTime;
this.mutate(domainObject, 'persisted', persistedTime); this.mutate(domainObject, 'persisted', persistedTime);

View File

@ -180,12 +180,6 @@ define([
* @memberof module:openmct.TelemetryAPI~TelemetryProvider# * @memberof module:openmct.TelemetryAPI~TelemetryProvider#
*/ */
TelemetryAPI.prototype.canProvideTelemetry = function (domainObject) { TelemetryAPI.prototype.canProvideTelemetry = function (domainObject) {
console.warn(
'DEPRECATION WARNING: openmct.telemetry.canProvideTelemetry '
+ 'will not be supported in future versions of Open MCT. Please '
+ 'use openmct.telemetry.isTelemetryObject instead.'
);
return Boolean(this.findSubscriptionProvider(domainObject)) return Boolean(this.findSubscriptionProvider(domainObject))
|| Boolean(this.findRequestProvider(domainObject)); || Boolean(this.findRequestProvider(domainObject));
}; };

View File

@ -31,11 +31,6 @@ define([
valueMetadata.hints = valueMetadata.hints || {}; valueMetadata.hints = valueMetadata.hints || {};
if (Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'x')) { if (Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'x')) {
console.warn(
'DEPRECATION WARNING: `x` hints should be replaced with '
+ '`domain` hints moving forward. '
+ 'https://github.com/nasa/openmct/issues/1546'
);
if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'domain')) { if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'domain')) {
valueMetadata.hints.domain = valueMetadata.hints.x; valueMetadata.hints.domain = valueMetadata.hints.x;
} }
@ -44,11 +39,6 @@ define([
} }
if (Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'y')) { if (Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'y')) {
console.warn(
'DEPRECATION WARNING: `y` hints should be replaced with '
+ '`range` hints moving forward. '
+ 'https://github.com/nasa/openmct/issues/1546'
);
if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'range')) { if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'range')) {
valueMetadata.hints.range = valueMetadata.hints.y; valueMetadata.hints.range = valueMetadata.hints.y;
} }

View File

@ -63,12 +63,6 @@ define(['./Type'], function (Type) {
*/ */
TypeRegistry.prototype.standardizeType = function (typeDef) { TypeRegistry.prototype.standardizeType = function (typeDef) {
if (Object.prototype.hasOwnProperty.call(typeDef, 'label')) { if (Object.prototype.hasOwnProperty.call(typeDef, 'label')) {
console.warn(
'DEPRECATION WARNING typeDef: ' + typeDef.label + '. '
+ '`label` is deprecated in type definitions. Please use '
+ '`name` instead. This will cause errors in a future version '
+ 'of Open MCT. For more information, see '
+ 'https://github.com/nasa/openmct/issues/1568');
if (!typeDef.name) { if (!typeDef.name) {
typeDef.name = typeDef.label; typeDef.name = typeDef.label;
} }

View File

@ -39,10 +39,13 @@ describe("The Compass component", () => {
sunAngle: 30 sunAngle: 30
}; };
let propsData = { let propsData = {
containerWidth: 600,
containerHeight: 600,
naturalAspectRatio: 0.9, naturalAspectRatio: 0.9,
image: imageDatum image: imageDatum,
sizedImageDimensions: {
width: 100,
height: 100
},
compassRoseSizingClasses: '--rose-small --rose-min'
}; };
app = new Vue({ app = new Vue({
@ -51,13 +54,13 @@ describe("The Compass component", () => {
return propsData; return propsData;
}, },
template: `<Compass template: `<Compass
:container-width="containerWidth" :compass-rose-sizing-classes="compassRoseSizingClasses"
:container-height="containerHeight" :image="image"
:natural-aspect-ratio="naturalAspectRatio" :natural-aspect-ratio="naturalAspectRatio"
:image="image" />` :sized-image-dimensions="sizedImageDimensions"
/>`
}); });
instance = app.$mount(); instance = app.$mount();
}); });
afterAll(() => { afterAll(() => {

View File

@ -220,7 +220,7 @@ describe("The Imagery View Layouts", () => {
}); });
spyOn(openmct.telemetry, 'request').and.returnValue(Promise.resolve([])); spyOn(openmct.telemetry, 'request').and.returnValue(Promise.resolve([]));
spyOn(openmct.objects, 'get').and.returnValue(Promise.resolve({})); spyOn(openmct.objects, 'get').and.returnValue(Promise.resolve(imageryObject));
originalRouterPath = openmct.router.path; originalRouterPath = openmct.router.path;
@ -370,18 +370,15 @@ describe("The Imagery View Layouts", () => {
}); });
}); });
xit("should show that an image is not new", (done) => { it("should show that an image is not new", (done) => {
const target = imageTelemetry[2].url; const target = imageTelemetry[2].url;
parent.querySelectorAll(`img[src='${target}']`)[0].click(); parent.querySelectorAll(`img[src='${target}']`)[0].click();
Vue.nextTick(() => { Vue.nextTick(() => {
// used in code, need to wait to the 500ms here too const imageIsNew = isNew(parent);
setTimeout(() => {
const imageIsNew = isNew(parent);
expect(imageIsNew).toBeFalse(); expect(imageIsNew).toBeFalse();
done(); done();
}, REFRESH_CSS_MS);
}); });
}); });

View File

@ -96,6 +96,9 @@ export function setDefaultNotebookPageId(pageId) {
export function validateNotebookStorageObject() { export function validateNotebookStorageObject() {
const notebookStorage = getDefaultNotebook(); const notebookStorage = getDefaultNotebook();
if (!notebookStorage) {
return true;
}
let valid = false; let valid = false;
if (notebookStorage) { if (notebookStorage) {

View File

@ -34,7 +34,7 @@ describe('the plugin', () => {
let countFramesPromise; let countFramesPromise;
beforeEach((done) => { beforeEach((done) => {
openmct = createOpenMct(false); openmct = createOpenMct();
element = document.createElement('div'); element = document.createElement('div');
child = document.createElement('div'); child = document.createElement('div');

View File

@ -49,7 +49,7 @@ describe('the plugin', () => {
filter: {}, filter: {},
disableObserve: true disableObserve: true
}; };
openmct = createOpenMct(false); openmct = createOpenMct();
openmct.$injector = jasmine.createSpyObj('$injector', ['get']); openmct.$injector = jasmine.createSpyObj('$injector', ['get']);
mockIdentifierService = jasmine.createSpyObj( mockIdentifierService = jasmine.createSpyObj(

View File

@ -36,7 +36,15 @@ describe('the plugin', function () {
appHolder.style.width = '640px'; appHolder.style.width = '640px';
appHolder.style.height = '480px'; appHolder.style.height = '480px';
openmct = createOpenMct(); const timeSystemOptions = {
timeSystemKey: 'utc',
bounds: {
start: 1597160002854,
end: 1597181232854
}
};
openmct = createOpenMct(timeSystemOptions);
openmct.install(new PlanPlugin()); openmct.install(new PlanPlugin());
planDefinition = openmct.types.get('plan').definition; planDefinition = openmct.types.get('plan').definition;
@ -48,7 +56,6 @@ describe('the plugin', function () {
child.style.width = '640px'; child.style.width = '640px';
child.style.height = '480px'; child.style.height = '480px';
element.appendChild(child); element.appendChild(child);
openmct.on('start', done); openmct.on('start', done);
openmct.start(appHolder); openmct.start(appHolder);
}); });
@ -72,7 +79,6 @@ describe('the plugin', function () {
}); });
describe('the plan view', () => { describe('the plan view', () => {
it('provides a plan view', () => { it('provides a plan view', () => {
const testViewObject = { const testViewObject = {
id: "test-object", id: "test-object",
@ -83,7 +89,6 @@ describe('the plugin', function () {
let planView = applicableViews.find((viewProvider) => viewProvider.key === 'plan.view'); let planView = applicableViews.find((viewProvider) => viewProvider.key === 'plan.view');
expect(planView).toBeDefined(); expect(planView).toBeDefined();
}); });
}); });
describe('the plan view displays activities', () => { describe('the plan view displays activities', () => {
@ -155,12 +160,22 @@ describe('the plugin', function () {
expect(labelEl.innerHTML).toEqual('TEST-GROUP'); expect(labelEl.innerHTML).toEqual('TEST-GROUP');
}); });
it('displays the activities and their labels', () => { it('displays the activities and their labels', (done) => {
const rectEls = element.querySelectorAll('.c-plan__contents rect'); const bounds = {
expect(rectEls.length).toEqual(2); start: 1597160002854,
const textEls = element.querySelectorAll('.c-plan__contents text'); end: 1597181232854
expect(textEls.length).toEqual(3); };
openmct.time.bounds(bounds);
Vue.nextTick(() => {
const rectEls = element.querySelectorAll('.c-plan__contents rect');
expect(rectEls.length).toEqual(2);
const textEls = element.querySelectorAll('.c-plan__contents text');
expect(textEls.length).toEqual(3);
done();
});
}); });
}); });
}); });

View File

@ -79,7 +79,15 @@ describe("the plugin", function () {
]; ];
cleanupFirst = []; cleanupFirst = [];
openmct = createOpenMct(); const timeSystem = {
timeSystemKey: 'utc',
bounds: {
start: 0,
end: 4
}
};
openmct = createOpenMct(timeSystem);
telemetryPromise = new Promise((resolve) => { telemetryPromise = new Promise((resolve) => {
telemetryPromiseResolve = resolve; telemetryPromiseResolve = resolve;
@ -146,11 +154,6 @@ describe("the plugin", function () {
disconnect() {} disconnect() {}
}); });
openmct.time.timeSystem("utc", {
start: 0,
end: 4
});
openmct.types.addType("test-object", { openmct.types.addType("test-object", {
creatable: true creatable: true
}); });
@ -165,11 +168,6 @@ describe("the plugin", function () {
}); });
afterEach((done) => { afterEach((done) => {
openmct.time.timeSystem('utc', {
start: 0,
end: 1
});
// Needs to be in a timeout because plots use a bunch of setTimeouts, some of which can resolve during or after // Needs to be in a timeout because plots use a bunch of setTimeouts, some of which can resolve during or after
// teardown, which causes problems // teardown, which causes problems
// This is hacky, we should find a better approach here. // This is hacky, we should find a better approach here.
@ -418,12 +416,23 @@ describe("the plugin", function () {
expect(legend.length).toBe(6); expect(legend.length).toBe(6);
}); });
it("Renders X-axis ticks for the telemetry object", () => { it("Renders X-axis ticks for the telemetry object", (done) => {
let xAxisElement = element.querySelectorAll(".gl-plot-axis-area.gl-plot-x .gl-plot-tick-wrapper"); const configId = openmct.objects.makeKeyString(testTelemetryObject.identifier);
expect(xAxisElement.length).toBe(1); const config = configStore.get(configId);
config.xAxis.set('displayRange', {
min: 0,
max: 4
});
let ticks = xAxisElement[0].querySelectorAll(".gl-plot-tick"); Vue.nextTick(() => {
expect(ticks.length).toBe(5); let xAxisElement = element.querySelectorAll(".gl-plot-axis-area.gl-plot-x .gl-plot-tick-wrapper");
expect(xAxisElement.length).toBe(1);
let ticks = xAxisElement[0].querySelectorAll(".gl-plot-tick");
expect(ticks.length).toBe(5);
done();
});
}); });
it("Renders Y-axis options for the telemetry object", () => { it("Renders Y-axis options for the telemetry object", () => {
@ -780,12 +789,21 @@ describe("the plugin", function () {
expect(legend.length).toBe(6); expect(legend.length).toBe(6);
}); });
xit("Renders X-axis ticks for the telemetry object", () => { it("Renders X-axis ticks for the telemetry object", (done) => {
let xAxisElement = element.querySelectorAll(".gl-plot-axis-area.gl-plot-x .gl-plot-tick-wrapper"); let xAxisElement = element.querySelectorAll(".gl-plot-axis-area.gl-plot-x .gl-plot-tick-wrapper");
expect(xAxisElement.length).toBe(1); expect(xAxisElement.length).toBe(1);
let ticks = xAxisElement[0].querySelectorAll(".gl-plot-tick"); config.xAxis.set('displayRange', {
expect(ticks.length).toBe(5); min: 0,
max: 4
});
Vue.nextTick(() => {
let ticks = xAxisElement[0].querySelectorAll(".gl-plot-tick");
expect(ticks.length).toBe(5);
done();
});
}); });
it("Renders Y-axis ticks for the telemetry object", (done) => { it("Renders Y-axis ticks for the telemetry object", (done) => {

View File

@ -528,7 +528,6 @@ export default {
if (!this.updatingView) { if (!this.updatingView) {
this.updatingView = true; this.updatingView = true;
requestAnimationFrame(() => { requestAnimationFrame(() => {
let start = 0; let start = 0;
let end = VISIBLE_ROW_COUNT; let end = VISIBLE_ROW_COUNT;
let tableRows = this.table.tableRows.getRows(); let tableRows = this.table.tableRows.getRows();

View File

@ -222,9 +222,13 @@ describe("the plugin", () => {
openmct.router.path = originalRouterPath; openmct.router.path = originalRouterPath;
}); });
it("Renders a row for every telemetry datum returned", () => { it("Renders a row for every telemetry datum returned", (done) => {
let rows = element.querySelectorAll('table.c-telemetry-table__body tr'); let rows = element.querySelectorAll('table.c-telemetry-table__body tr');
expect(rows.length).toBe(3); Vue.nextTick(() => {
expect(rows.length).toBe(3);
done();
});
}); });
it("Renders a column for every item in telemetry metadata", () => { it("Renders a column for every item in telemetry metadata", () => {

View File

@ -51,7 +51,15 @@ describe('the plugin', function () {
} }
]; ];
openmct = createOpenMct(); const timeSystem = {
timeSystemKey: 'utc',
bounds: {
start: 1597160002854,
end: 1597181232854
}
};
openmct = createOpenMct(timeSystem);
openmct.install(new TimelinePlugin()); openmct.install(new TimelinePlugin());
objectDef = openmct.types.get('time-strip').definition; objectDef = openmct.types.get('time-strip').definition;
@ -64,11 +72,6 @@ describe('the plugin', function () {
child.style.height = '480px'; child.style.height = '480px';
element.appendChild(child); element.appendChild(child);
openmct.time.timeSystem('utc', {
start: 1597160002854,
end: 1597181232854
});
openmct.on('start', done); openmct.on('start', done);
openmct.startHeadless(); openmct.startHeadless();
}); });
@ -88,7 +91,6 @@ describe('the plugin', function () {
}); });
describe('the time-strip object', () => { describe('the time-strip object', () => {
it('is creatable', () => { it('is creatable', () => {
expect(objectDef.creatable).toEqual(mockObject.creatable); expect(objectDef.creatable).toEqual(mockObject.creatable);
}); });

View File

@ -6,133 +6,74 @@ let child;
let appHolder; let appHolder;
let resolveFunction; let resolveFunction;
let initialHash = ''; describe('Application router utility functions', () => {
beforeEach(done => {
xdescribe('Application router utility functions', () => {
beforeAll(done => {
appHolder = document.createElement('div'); appHolder = document.createElement('div');
appHolder.style.width = '640px'; appHolder.style.width = '640px';
appHolder.style.height = '480px'; appHolder.style.height = '480px';
openmct = createOpenMct(); openmct = createOpenMct();
openmct.install(openmct.plugins.MyItems()); openmct.install(openmct.plugins.MyItems());
openmct.install(openmct.plugins.LocalTimeSystem());
openmct.install(openmct.plugins.UTCTimeSystem());
element = document.createElement('div'); element = document.createElement('div');
child = document.createElement('div'); child = document.createElement('div');
element.appendChild(child); element.appendChild(child);
openmct.on('start', done); openmct.on('start', () => {
resolveFunction = () => {
const success = window.location.hash !== null && window.location.hash !== '';
if (success) {
done();
}
};
openmct.router.on('change:hash', resolveFunction);
openmct.router.setLocationFromUrl();
});
openmct.start(appHolder); openmct.start(appHolder);
document.body.append(appHolder); document.body.append(appHolder);
}); });
afterAll(() => { afterEach(() => {
openmct.router.setHash(initialHash); openmct.router.removeListener('change:hash', resolveFunction);
appHolder.remove(); appHolder.remove();
return resetApplicationState(openmct); return resetApplicationState(openmct);
}); });
it('has initial hash when loaded', (done) => { it('has initial hash when loaded', () => {
let success; const success = window.location.hash !== null;
resolveFunction = () => { expect(success).toBe(true);
openmct.router.setLocationFromUrl();
success = window.location.hash !== null;
if (success) {
initialHash = window.location.hash;
expect(success).toBe(true);
openmct.router.removeListener('change:hash', resolveFunction);
done();
}
};
openmct.router.on('change:hash', resolveFunction);
}); });
it('The setSearchParam function sets an individual search parameter in the window location hash', (done) => { it('The setSearchParam function sets an individual search parameter in the window location hash', () => {
let success;
openmct.router.setSearchParam('testParam', 'testValue'); openmct.router.setSearchParam('testParam', 'testValue');
resolveFunction = () => { const searchParams = openmct.router.getAllSearchParams();
success = window.location.hash.includes('testParam=testValue'); expect(searchParams.get('testParam')).toBe('testValue');
if (success) {
expect(success).toBe(true);
openmct.router.removeListener('change:hash', resolveFunction);
done();
}
};
openmct.router.on('change:hash', resolveFunction);
}); });
it('The getSearchParam function returns the value of an individual search parameter in the window location hash', () => { it('The deleteSearchParam function deletes an individual search paramater in the window location hash', () => {
expect(openmct.router.getSearchParam('testParam')).toBe('testValue');
});
it('The deleteSearchParam function deletes an individual search parameter in the window location hash', (done) => {
let success;
openmct.router.deleteSearchParam('testParam'); openmct.router.deleteSearchParam('testParam');
resolveFunction = () => { const searchParams = openmct.router.getAllSearchParams();
success = window.location.hash.includes('testParam=testValue') === false; expect(searchParams.get('testParam')).toBe(null);
if (success) {
expect(success).toBe(true);
openmct.router.removeListener('change:hash', resolveFunction);
done();
}
};
openmct.router.on('change:hash', resolveFunction);
}); });
it('The setSearchParam function sets an individual search parameters in the window location hash', (done) => { it('The setSearchParam function sets a multiple individual search parameters in the window location hash', () => {
let success;
openmct.router.setSearchParam('testParam1', 'testValue1'); openmct.router.setSearchParam('testParam1', 'testValue1');
openmct.router.setSearchParam('testParam2', 'testValue2'); openmct.router.setSearchParam('testParam2', 'testValue2');
resolveFunction = () => { const searchParams = openmct.router.getAllSearchParams();
const hasTestParam1 = window.location.hash.includes('testParam1=testValue1'); expect(searchParams.get('testParam1')).toBe('testValue1');
const hasTestParam2 = window.location.hash.includes('testParam2=testValue2'); expect(searchParams.get('testParam2')).toBe('testValue2');
success = hasTestParam1 && hasTestParam2;
if (success) {
expect(success).toBe(true);
openmct.router.removeListener('change:hash', resolveFunction);
done();
}
};
openmct.router.on('change:hash', resolveFunction);
}); });
it('The setAllSearchParams function replaces all search parameters in the window location hash', (done) => { it('The setAllSearchParams function replaces all search paramaters in the window location hash', () => {
let success;
openmct.router.setSearchParam('testParam2', 'updatedtestValue2'); openmct.router.setSearchParam('testParam2', 'updatedtestValue2');
openmct.router.setSearchParam('newTestParam3', 'newTestValue3'); openmct.router.setSearchParam('newTestParam3', 'newTestValue3');
resolveFunction = () => { const searchParams = openmct.router.getAllSearchParams();
const hasupdatedValueForTestParam2 = window.location.hash.includes('testParam2=updatedtestValue2');
const hasNewTestParam3 = window.location.hash.includes('newTestParam3=newTestValue3');
success = hasupdatedValueForTestParam2 && hasNewTestParam3;
if (success) {
expect(success).toBe(true);
openmct.router.removeListener('change:hash', resolveFunction);
done();
}
};
openmct.router.on('change:hash', resolveFunction);
});
it('The getAllSearchParams function returns the values of all search parameters in the window location hash', () => {
let searchParams = openmct.router.getAllSearchParams();
expect(searchParams.get('testParam1')).toBe('testValue1');
expect(searchParams.get('testParam2')).toBe('updatedtestValue2'); expect(searchParams.get('testParam2')).toBe('updatedtestValue2');
expect(searchParams.get('newTestParam3')).toBe('newTestValue3'); expect(searchParams.get('newTestParam3')).toBe('newTestValue3');
}); });

View File

@ -119,11 +119,16 @@ define([
function navigateToFirstChildOfRoot() { function navigateToFirstChildOfRoot() {
openmct.objects.get('ROOT') openmct.objects.get('ROOT')
.then(rootObject => { .then(rootObject => {
openmct.composition.get(rootObject).load() const composition = openmct.composition.get(rootObject);
if (!composition) {
return;
}
composition.load()
.then(children => { .then(children => {
let lastChild = children[children.length - 1]; let lastChild = children[children.length - 1];
if (!lastChild) { if (!lastChild) {
console.error('Unable to navigate to anything. No root objects found.'); console.debug('Unable to navigate to anything. No root objects found.');
} else { } else {
let lastChildId = openmct.objects.makeKeyString(lastChild.identifier); let lastChildId = openmct.objects.makeKeyString(lastChild.identifier);
openmct.router.setPath(`#/browse/${lastChildId}`); openmct.router.setPath(`#/browse/${lastChildId}`);

View File

@ -25,13 +25,26 @@ import MCT from 'MCT';
let nativeFunctions = []; let nativeFunctions = [];
let mockObjects = setMockObjects(); let mockObjects = setMockObjects();
export function createOpenMct() { const DEFAULT_TIME_OPTIONS = {
timeSystemKey: 'utc',
bounds: {
start: 0,
end: 1
}
};
export function createOpenMct(timeSystemOptions = DEFAULT_TIME_OPTIONS) {
const openmct = new MCT(); const openmct = new MCT();
openmct.install(openmct.plugins.LocalStorage()); openmct.install(openmct.plugins.LocalStorage());
openmct.install(openmct.plugins.UTCTimeSystem()); openmct.install(openmct.plugins.UTCTimeSystem());
openmct.time.timeSystem('utc', {
start: 0, const timeSystemKey = timeSystemOptions.timeSystemKey;
end: 1 const start = timeSystemOptions.bounds.start;
const end = timeSystemOptions.bounds.end;
openmct.time.timeSystem(timeSystemKey, {
start,
end
}); });
return openmct; return openmct;