mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 19:27:07 +00:00
Merge pull request #780 from nasa/open715
[Timelines] #715 Added a check to prevent mutation when modes are unchanged
This commit is contained in:
commit
f8682a7a29
@ -45,11 +45,13 @@ define(
|
|||||||
function modes(value) {
|
function modes(value) {
|
||||||
// Can be used as a setter...
|
// Can be used as a setter...
|
||||||
if (arguments.length > 0 && Array.isArray(value)) {
|
if (arguments.length > 0 && Array.isArray(value)) {
|
||||||
// Update the relationships
|
if ((model.relationships || {})[ACTIVITY_RELATIONSHIP] !== value) {
|
||||||
mutator.mutate(function (model) {
|
// Update the relationships
|
||||||
model.relationships = model.relationships || {};
|
mutator.mutate(function (model) {
|
||||||
model.relationships[ACTIVITY_RELATIONSHIP] = value;
|
model.relationships = model.relationships || {};
|
||||||
}).then(persister.persist);
|
model.relationships[ACTIVITY_RELATIONSHIP] = value;
|
||||||
|
}).then(persister.persist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ...otherwise, use as a getter
|
// ...otherwise, use as a getter
|
||||||
return (model.relationships || {})[ACTIVITY_RELATIONSHIP] || [];
|
return (model.relationships || {})[ACTIVITY_RELATIONSHIP] || [];
|
||||||
|
@ -32,12 +32,14 @@ define(
|
|||||||
mockCapabilities,
|
mockCapabilities,
|
||||||
testModel,
|
testModel,
|
||||||
mockPromise,
|
mockPromise,
|
||||||
|
testModes,
|
||||||
decorator;
|
decorator;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockSwimlane = {};
|
mockSwimlane = {};
|
||||||
mockCapabilities = {};
|
mockCapabilities = {};
|
||||||
testModel = {};
|
testModel = {};
|
||||||
|
testModes = ['a', 'b', 'c'];
|
||||||
|
|
||||||
mockSelection = jasmine.createSpyObj('selection', ['select', 'get']);
|
mockSelection = jasmine.createSpyObj('selection', ['select', 'get']);
|
||||||
|
|
||||||
@ -135,6 +137,22 @@ define(
|
|||||||
expect(mockCapabilities.persistence.persist).toHaveBeenCalled();
|
expect(mockCapabilities.persistence.persist).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not mutate modes when unchanged", function () {
|
||||||
|
testModel.relationships = { modes: testModes };
|
||||||
|
decorator.modes(testModes);
|
||||||
|
expect(mockCapabilities.mutation.mutate).not.toHaveBeenCalled();
|
||||||
|
expect(testModel.relationships.modes).toEqual(testModes);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does mutate modes when changed", function () {
|
||||||
|
var testModes2 = ['d', 'e', 'f'];
|
||||||
|
testModel.relationships = { modes: testModes };
|
||||||
|
decorator.modes(testModes2);
|
||||||
|
expect(mockCapabilities.mutation.mutate).toHaveBeenCalled();
|
||||||
|
mockCapabilities.mutation.mutate.mostRecentCall.args[0](testModel);
|
||||||
|
expect(testModel.relationships.modes).toBe(testModes2);
|
||||||
|
});
|
||||||
|
|
||||||
it("does not provide a 'remove' method with no parent", function () {
|
it("does not provide a 'remove' method with no parent", function () {
|
||||||
expect(decorator.remove).not.toEqual(jasmine.any(Function));
|
expect(decorator.remove).not.toEqual(jasmine.any(Function));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user