mirror of
https://github.com/nasa/openmct.git
synced 2025-05-06 10:38:23 +00:00
Merge pull request #1446 from nasa/fix-orphan-navigation
Orphan check uses capability not model
This commit is contained in:
commit
2088fc52f3
@ -43,24 +43,24 @@ define([], function () {
|
|||||||
return context.getParent();
|
return context.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
function isOrphan(domainObject) {
|
function preventOrphanNavigation(domainObject) {
|
||||||
var parent = getParent(domainObject),
|
|
||||||
composition = parent.getModel().composition,
|
|
||||||
id = domainObject.getId();
|
|
||||||
return !composition || (composition.indexOf(id) === -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function navigateToParent(domainObject) {
|
|
||||||
var parent = getParent(domainObject);
|
var parent = getParent(domainObject);
|
||||||
return parent.getCapability('action').perform('navigate');
|
parent.useCapability('composition')
|
||||||
|
.then(function (composees) {
|
||||||
|
var isOrphan = composees.every(function (c) {
|
||||||
|
return c.getId() !== domainObject.getId();
|
||||||
|
});
|
||||||
|
if (isOrphan) {
|
||||||
|
parent.getCapability('action').perform('navigate');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkNavigation() {
|
function checkNavigation() {
|
||||||
var navigatedObject = navigationService.getNavigation();
|
var navigatedObject = navigationService.getNavigation();
|
||||||
if (navigatedObject.hasCapability('context') &&
|
if (navigatedObject.hasCapability('context')) {
|
||||||
isOrphan(navigatedObject)) {
|
|
||||||
if (!navigatedObject.getCapability('editor').isEditContextRoot()) {
|
if (!navigatedObject.getCapability('editor').isEditContextRoot()) {
|
||||||
navigateToParent(navigatedObject);
|
preventOrphanNavigation(navigatedObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ define([
|
|||||||
mockContext,
|
mockContext,
|
||||||
mockActionCapability,
|
mockActionCapability,
|
||||||
mockEditor,
|
mockEditor,
|
||||||
testParentModel,
|
testParentComposition,
|
||||||
testId,
|
testId,
|
||||||
mockThrottledFns;
|
mockThrottledFns;
|
||||||
|
|
||||||
@ -41,7 +41,6 @@ define([
|
|||||||
testId = 'some-identifier';
|
testId = 'some-identifier';
|
||||||
|
|
||||||
mockThrottledFns = [];
|
mockThrottledFns = [];
|
||||||
testParentModel = {};
|
|
||||||
|
|
||||||
mockTopic = jasmine.createSpy('topic');
|
mockTopic = jasmine.createSpy('topic');
|
||||||
mockThrottle = jasmine.createSpy('throttle');
|
mockThrottle = jasmine.createSpy('throttle');
|
||||||
@ -55,14 +54,12 @@ define([
|
|||||||
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||||
'getId',
|
'getId',
|
||||||
'getCapability',
|
'getCapability',
|
||||||
'getModel',
|
|
||||||
'hasCapability'
|
'hasCapability'
|
||||||
]);
|
]);
|
||||||
mockParentObject = jasmine.createSpyObj('domainObject', [
|
mockParentObject = jasmine.createSpyObj('domainObject', [
|
||||||
'getId',
|
'getId',
|
||||||
'getCapability',
|
'getCapability',
|
||||||
'getModel',
|
'useCapability'
|
||||||
'hasCapability'
|
|
||||||
]);
|
]);
|
||||||
mockContext = jasmine.createSpyObj('context', ['getParent']);
|
mockContext = jasmine.createSpyObj('context', ['getParent']);
|
||||||
mockActionCapability = jasmine.createSpyObj('action', ['perform']);
|
mockActionCapability = jasmine.createSpyObj('action', ['perform']);
|
||||||
@ -75,9 +72,7 @@ define([
|
|||||||
mockThrottledFns.push(mockThrottledFn);
|
mockThrottledFns.push(mockThrottledFn);
|
||||||
return mockThrottledFn;
|
return mockThrottledFn;
|
||||||
});
|
});
|
||||||
mockTopic.andCallFake(function (k) {
|
mockTopic.andReturn(mockMutationTopic);
|
||||||
return k === 'mutation' && mockMutationTopic;
|
|
||||||
});
|
|
||||||
mockDomainObject.getId.andReturn(testId);
|
mockDomainObject.getId.andReturn(testId);
|
||||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||||
return {
|
return {
|
||||||
@ -88,12 +83,13 @@ define([
|
|||||||
mockDomainObject.hasCapability.andCallFake(function (c) {
|
mockDomainObject.hasCapability.andCallFake(function (c) {
|
||||||
return !!mockDomainObject.getCapability(c);
|
return !!mockDomainObject.getCapability(c);
|
||||||
});
|
});
|
||||||
mockParentObject.getModel.andReturn(testParentModel);
|
|
||||||
mockParentObject.getCapability.andCallFake(function (c) {
|
mockParentObject.getCapability.andCallFake(function (c) {
|
||||||
return {
|
return {
|
||||||
action: mockActionCapability
|
action: mockActionCapability
|
||||||
}[c];
|
}[c];
|
||||||
});
|
});
|
||||||
|
testParentComposition = [];
|
||||||
|
mockParentObject.useCapability.andReturn(Promise.resolve(testParentComposition));
|
||||||
mockContext.getParent.andReturn(mockParentObject);
|
mockContext.getParent.andReturn(mockParentObject);
|
||||||
mockNavigationService.getNavigation.andReturn(mockDomainObject);
|
mockNavigationService.getNavigation.andReturn(mockDomainObject);
|
||||||
mockEditor.isEditContextRoot.andReturn(false);
|
mockEditor.isEditContextRoot.andReturn(false);
|
||||||
@ -126,7 +122,9 @@ define([
|
|||||||
var prefix = isOrphan ? "" : "non-";
|
var prefix = isOrphan ? "" : "non-";
|
||||||
describe("for " + prefix + "orphan objects", function () {
|
describe("for " + prefix + "orphan objects", function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
testParentModel.composition = isOrphan ? [] : [testId];
|
if (!isOrphan) {
|
||||||
|
testParentComposition.push(mockDomainObject);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
[false, true].forEach(function (isEditRoot) {
|
[false, true].forEach(function (isEditRoot) {
|
||||||
@ -136,13 +134,31 @@ define([
|
|||||||
function itNavigatesAsExpected() {
|
function itNavigatesAsExpected() {
|
||||||
if (isOrphan && !isEditRoot) {
|
if (isOrphan && !isEditRoot) {
|
||||||
it("navigates to the parent", function () {
|
it("navigates to the parent", function () {
|
||||||
expect(mockActionCapability.perform)
|
var done = false;
|
||||||
.toHaveBeenCalledWith('navigate');
|
waitsFor(function () {
|
||||||
|
return done;
|
||||||
|
});
|
||||||
|
setTimeout(function () {
|
||||||
|
done = true;
|
||||||
|
}, 5);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockActionCapability.perform)
|
||||||
|
.toHaveBeenCalledWith('navigate');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
it("does nothing", function () {
|
it("does nothing", function () {
|
||||||
expect(mockActionCapability.perform)
|
var done = false;
|
||||||
.not.toHaveBeenCalled();
|
waitsFor(function () {
|
||||||
|
return done;
|
||||||
|
});
|
||||||
|
setTimeout(function () {
|
||||||
|
done = true;
|
||||||
|
}, 5);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockActionCapability.perform)
|
||||||
|
.not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +173,6 @@ define([
|
|||||||
mockNavigationService.addListener.mostRecentCall
|
mockNavigationService.addListener.mostRecentCall
|
||||||
.args[0](mockDomainObject);
|
.args[0](mockDomainObject);
|
||||||
});
|
});
|
||||||
|
|
||||||
itNavigatesAsExpected();
|
itNavigatesAsExpected();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user