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) {
|
||||
// Can be used as a setter...
|
||||
if (arguments.length > 0 && Array.isArray(value)) {
|
||||
// Update the relationships
|
||||
mutator.mutate(function (model) {
|
||||
model.relationships = model.relationships || {};
|
||||
model.relationships[ACTIVITY_RELATIONSHIP] = value;
|
||||
}).then(persister.persist);
|
||||
if ((model.relationships || {})[ACTIVITY_RELATIONSHIP] !== value) {
|
||||
// Update the relationships
|
||||
mutator.mutate(function (model) {
|
||||
model.relationships = model.relationships || {};
|
||||
model.relationships[ACTIVITY_RELATIONSHIP] = value;
|
||||
}).then(persister.persist);
|
||||
}
|
||||
}
|
||||
// ...otherwise, use as a getter
|
||||
return (model.relationships || {})[ACTIVITY_RELATIONSHIP] || [];
|
||||
|
@ -32,12 +32,14 @@ define(
|
||||
mockCapabilities,
|
||||
testModel,
|
||||
mockPromise,
|
||||
testModes,
|
||||
decorator;
|
||||
|
||||
beforeEach(function () {
|
||||
mockSwimlane = {};
|
||||
mockCapabilities = {};
|
||||
testModel = {};
|
||||
testModes = ['a', 'b', 'c'];
|
||||
|
||||
mockSelection = jasmine.createSpyObj('selection', ['select', 'get']);
|
||||
|
||||
@ -135,6 +137,22 @@ define(
|
||||
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 () {
|
||||
expect(decorator.remove).not.toEqual(jasmine.any(Function));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user