mirror of
https://github.com/nasa/openmct.git
synced 2025-06-02 07:30:49 +00:00
[Remove] Tests
RemoveActionSpec test complete, tests if parent is object is removed. Also tests if object not in object path is removed.
This commit is contained in:
parent
e8bc9ecc1a
commit
793c99ac2f
@ -31,8 +31,11 @@ define(
|
|||||||
mockNavigationService,
|
mockNavigationService,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockParent,
|
mockParent,
|
||||||
mockGrandparent,
|
mockChildObject,
|
||||||
|
mockGrandchildObject,
|
||||||
mockContext,
|
mockContext,
|
||||||
|
mockChildContext,
|
||||||
|
mockGrandchildContext,
|
||||||
mockMutation,
|
mockMutation,
|
||||||
mockPersistence,
|
mockPersistence,
|
||||||
mockType,
|
mockType,
|
||||||
@ -56,21 +59,15 @@ define(
|
|||||||
"domainObject",
|
"domainObject",
|
||||||
[ "getId", "getCapability" ]
|
[ "getId", "getCapability" ]
|
||||||
);
|
);
|
||||||
|
mockChildObject = jasmine.createSpyObj(
|
||||||
|
"domainObject",
|
||||||
|
[ "getId", "getCapability" ]
|
||||||
|
);
|
||||||
|
mockGrandchildObject = jasmine.createSpyObj(
|
||||||
|
"domainObject",
|
||||||
|
[ "getId", "getCapability" ]
|
||||||
|
);
|
||||||
mockQ = { when: mockPromise };
|
mockQ = { when: mockPromise };
|
||||||
mockGrandparent = {
|
|
||||||
getModel: function () {
|
|
||||||
return model;
|
|
||||||
},
|
|
||||||
getCapability: function (k) {
|
|
||||||
return capabilities[k];
|
|
||||||
},
|
|
||||||
useCapability: function (k, v) {
|
|
||||||
return capabilities[k].invoke(v);
|
|
||||||
},
|
|
||||||
getId: function () {
|
|
||||||
return "test";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mockParent = {
|
mockParent = {
|
||||||
getModel: function () {
|
getModel: function () {
|
||||||
return model;
|
return model;
|
||||||
@ -80,12 +77,11 @@ define(
|
|||||||
},
|
},
|
||||||
useCapability: function (k, v) {
|
useCapability: function (k, v) {
|
||||||
return capabilities[k].invoke(v);
|
return capabilities[k].invoke(v);
|
||||||
},
|
|
||||||
getParent: function () {
|
|
||||||
return mockGrandparent;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||||
|
mockChildContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||||
|
mockGrandchildContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||||
mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]);
|
mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]);
|
||||||
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
||||||
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
|
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
|
||||||
@ -112,7 +108,7 @@ define(
|
|||||||
type: mockType
|
type: mockType
|
||||||
};
|
};
|
||||||
model = {
|
model = {
|
||||||
composition: [ "a", "b", "test", "c" ]
|
composition: [ "a", "test", "b" ]
|
||||||
};
|
};
|
||||||
|
|
||||||
actionContext = { domainObject: mockDomainObject };
|
actionContext = { domainObject: mockDomainObject };
|
||||||
@ -152,11 +148,66 @@ define(
|
|||||||
|
|
||||||
// Should have removed "test" - that was our
|
// Should have removed "test" - that was our
|
||||||
// mock domain object's id.
|
// mock domain object's id.
|
||||||
expect(result.composition).toEqual(["a", "b", "c"]);
|
expect(result.composition).toEqual(["a", "b"]);
|
||||||
|
|
||||||
// Finally, should have persisted
|
// Finally, should have persisted
|
||||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("removes parent of object currently navigated to", function () {
|
||||||
|
var mutator, result;
|
||||||
|
|
||||||
|
// Navigates to child object
|
||||||
|
mockNavigationService.getNavigation.andReturn(mockChildObject);
|
||||||
|
|
||||||
|
// Test is id of object being removed
|
||||||
|
// Child object has different id
|
||||||
|
mockDomainObject.getId.andReturn("test");
|
||||||
|
mockChildObject.getId.andReturn("not test");
|
||||||
|
|
||||||
|
// Sets context for the child and domainObject
|
||||||
|
mockDomainObject.getCapability.andReturn(mockContext);
|
||||||
|
mockChildObject.getCapability.andReturn(mockChildContext);
|
||||||
|
|
||||||
|
// Parents of child and domainObject are set
|
||||||
|
mockContext.getParent.andReturn(mockParent);
|
||||||
|
mockChildContext.getParent.andReturn(mockDomainObject);
|
||||||
|
|
||||||
|
mockType.hasFeature.andReturn(true);
|
||||||
|
|
||||||
|
action.perform();
|
||||||
|
|
||||||
|
// Expects navigation to parent of domainObject (removed object)
|
||||||
|
expect(mockNavigationService.setNavigation).toHaveBeenCalledWith(mockParent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("checks if removing object not in ascendent path (reaches ROOT)", function () {
|
||||||
|
// Navigates to grandchild of ROOT
|
||||||
|
mockNavigationService.getNavigation.andReturn(mockGrandchildObject);
|
||||||
|
|
||||||
|
// domainObject (grandparent) is set as ROOT, child and grandchild
|
||||||
|
// are set objects not being removed
|
||||||
|
mockDomainObject.getId.andReturn("ROOT");
|
||||||
|
mockChildObject.getId.andReturn("not test");
|
||||||
|
mockGrandchildObject.getId.andReturn("not test");
|
||||||
|
|
||||||
|
// Sets context for the grandchild, child, and domainObject
|
||||||
|
mockDomainObject.getCapability.andReturn(mockContext);
|
||||||
|
mockChildObject.getCapability.andReturn(mockChildContext);
|
||||||
|
mockGrandchildObject.getCapability.andReturn(mockGrandchildContext);
|
||||||
|
|
||||||
|
// Parents of grandchild, child, and domainObject are set
|
||||||
|
mockContext.getParent.andReturn(mockParent);
|
||||||
|
mockChildContext.getParent.andReturn(mockDomainObject);
|
||||||
|
mockGrandchildContext.getParent.andReturn(mockChildObject);
|
||||||
|
|
||||||
|
mockType.hasFeature.andReturn(true);
|
||||||
|
|
||||||
|
action.perform();
|
||||||
|
|
||||||
|
// Expects no navigation to occur
|
||||||
|
expect(mockNavigationService.setNavigation).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user