mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
[Fixed Position] Add tests for FixedController
Add additional test cases for controller for Fixed Position view to meet code coverage after changes for WTD-879.
This commit is contained in:
parent
3cfcd027e0
commit
1015e97b3e
@ -11,7 +11,7 @@
|
||||
</span>
|
||||
|
||||
<!-- Fixed position elements -->
|
||||
<mct-include ng-repeat="element in controller.getDecoratedElements()"
|
||||
<mct-include ng-repeat="element in controller.getElements()"
|
||||
style="position: absolute;"
|
||||
key="element.template"
|
||||
ng-class="{ test: controller.selected(element) }"
|
||||
|
@ -24,6 +24,7 @@ define(
|
||||
subscription,
|
||||
cellStyles = [],
|
||||
elementProxies = [],
|
||||
elementProxiesById = {},
|
||||
selection;
|
||||
|
||||
// Refresh cell styles (e.g. because grid extent changed)
|
||||
@ -65,7 +66,7 @@ define(
|
||||
function updateValue(telemetryObject) {
|
||||
var id = telemetryObject && telemetryObject.getId();
|
||||
if (id) {
|
||||
elementProxies.forEach(function (element) {
|
||||
(elementProxiesById[id] || []).forEach(function (element) {
|
||||
element.name = telemetryObject.getModel().name;
|
||||
element.value = telemetryFormatter.formatRangeValue(
|
||||
subscription.getRangeValue(telemetryObject)
|
||||
@ -120,6 +121,17 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, rebuild lists of elements by id to
|
||||
// facilitate faster update when new telemetry comes in.
|
||||
elementProxiesById = {};
|
||||
elementProxies.forEach(function (elementProxy) {
|
||||
var id = elementProxy.id;
|
||||
if (elementProxy.element.type === 'fixed.telemetry') {
|
||||
elementProxiesById[id] = elementProxiesById[id] || [];
|
||||
elementProxiesById[id].push(elementProxy);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: Ensure elements for all domain objects?
|
||||
}
|
||||
|
||||
@ -224,11 +236,11 @@ define(
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Get an array of elements in this panel, decorated for
|
||||
* display.
|
||||
* Get an array of elements in this panel; these are
|
||||
* decorated proxies for both selection and display.
|
||||
* @returns {Array} elements in this panel
|
||||
*/
|
||||
getDecoratedElements: function () {
|
||||
getElements: function () {
|
||||
return elementProxies;
|
||||
},
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ define(
|
||||
testGrid,
|
||||
testModel,
|
||||
testValues,
|
||||
testConfiguration,
|
||||
controller;
|
||||
|
||||
// Utility function; find a watch for a given expression
|
||||
@ -41,9 +42,10 @@ define(
|
||||
function makeMockDomainObject(id) {
|
||||
var mockObject = jasmine.createSpyObj(
|
||||
'domainObject-' + id,
|
||||
[ 'getId' ]
|
||||
[ 'getId', 'getModel' ]
|
||||
);
|
||||
mockObject.getId.andReturn(id);
|
||||
mockObject.getModel.andReturn({ name: "Point " + id});
|
||||
return mockObject;
|
||||
}
|
||||
|
||||
@ -75,6 +77,11 @@ define(
|
||||
layoutGrid: testGrid
|
||||
};
|
||||
testValues = { a: 10, b: 42, c: 31.42 };
|
||||
testConfiguration = { elements: [
|
||||
{ type: "fixed.telemetry", id: 'a', x: 1, y: 1 },
|
||||
{ type: "fixed.telemetry", id: 'b', x: 1, y: 1 },
|
||||
{ type: "fixed.telemetry", id: 'c', x: 1, y: 1 }
|
||||
]};
|
||||
|
||||
mockSubscriber.subscribe.andReturn(mockSubscription);
|
||||
mockSubscription.getTelemetryObjects.andReturn(
|
||||
@ -87,6 +94,8 @@ define(
|
||||
return "Formatted " + v;
|
||||
});
|
||||
mockScope.model = testModel;
|
||||
mockScope.configuration = testConfiguration;
|
||||
mockScope.selection = []; // Act like edit mode
|
||||
|
||||
controller = new FixedController(
|
||||
mockScope,
|
||||
@ -109,7 +118,7 @@ define(
|
||||
);
|
||||
});
|
||||
|
||||
xit("releases subscriptions when domain objects change", function () {
|
||||
it("releases subscriptions when domain objects change", function () {
|
||||
mockScope.domainObject = mockDomainObject;
|
||||
|
||||
// First pass - should simply should subscribe
|
||||
@ -123,30 +132,85 @@ define(
|
||||
expect(mockSubscriber.subscribe.calls.length).toEqual(2);
|
||||
});
|
||||
|
||||
xit("configures view based on model", function () {
|
||||
it("exposes visible elements based on configuration", function () {
|
||||
var elements;
|
||||
|
||||
mockScope.model = testModel;
|
||||
findWatch("model.composition")(mockScope.model.composition);
|
||||
// Should have styles for all elements of composition
|
||||
expect(controller.getStyle('a')).toBeDefined();
|
||||
expect(controller.getStyle('b')).toBeDefined();
|
||||
expect(controller.getStyle('c')).toBeDefined();
|
||||
expect(controller.getStyle('d')).not.toBeDefined();
|
||||
testModel.modified = 1;
|
||||
findWatch("model.modified")(testModel.modified);
|
||||
|
||||
elements = controller.getElements();
|
||||
expect(elements.length).toEqual(3);
|
||||
expect(elements[0].id).toEqual('a');
|
||||
expect(elements[1].id).toEqual('b');
|
||||
expect(elements[2].id).toEqual('c');
|
||||
});
|
||||
|
||||
xit("provides values for telemetry elements", function () {
|
||||
it("allows elements to be selected", function () {
|
||||
var elements;
|
||||
|
||||
testModel.modified = 1;
|
||||
findWatch("model.modified")(testModel.modified);
|
||||
|
||||
elements = controller.getElements();
|
||||
controller.select(elements[1]);
|
||||
expect(controller.selected(elements[0])).toBeFalsy();
|
||||
expect(controller.selected(elements[1])).toBeTruthy();
|
||||
});
|
||||
|
||||
it("allows selections to be cleared", function () {
|
||||
var elements;
|
||||
|
||||
testModel.modified = 1;
|
||||
findWatch("model.modified")(testModel.modified);
|
||||
|
||||
elements = controller.getElements();
|
||||
controller.select(elements[1]);
|
||||
controller.clearSelection();
|
||||
expect(controller.selected(elements[1])).toBeFalsy();
|
||||
});
|
||||
|
||||
it("retains selections during refresh", function () {
|
||||
// Get elements; remove one of them; trigger refresh.
|
||||
// Same element (at least by index) should still be selected.
|
||||
var elements;
|
||||
|
||||
testModel.modified = 1;
|
||||
findWatch("model.modified")(testModel.modified);
|
||||
|
||||
elements = controller.getElements();
|
||||
controller.select(elements[1]);
|
||||
|
||||
elements[2].remove();
|
||||
testModel.modified = 2;
|
||||
findWatch("model.modified")(testModel.modified);
|
||||
|
||||
elements = controller.getElements();
|
||||
// Verify removal, as test assumes this
|
||||
expect(elements.length).toEqual(2);
|
||||
|
||||
expect(controller.selected(elements[1])).toBeTruthy();
|
||||
});
|
||||
|
||||
it("provides values for telemetry elements", function () {
|
||||
var elements;
|
||||
// Initialize
|
||||
mockScope.domainObject = mockDomainObject;
|
||||
mockScope.model = testModel;
|
||||
findWatch("domainObject")(mockDomainObject);
|
||||
findWatch("model.modified")(1);
|
||||
findWatch("model.composition")(mockScope.model.composition);
|
||||
|
||||
// Invoke the subscription callback
|
||||
mockSubscriber.subscribe.mostRecentCall.args[1]();
|
||||
|
||||
// Get elements that controller is now exposing
|
||||
elements = controller.getElements();
|
||||
|
||||
// Formatted values should be available
|
||||
expect(controller.getValue('a')).toEqual("Formatted 10");
|
||||
expect(controller.getValue('b')).toEqual("Formatted 42");
|
||||
expect(controller.getValue('c')).toEqual("Formatted 31.42");
|
||||
expect(elements[0].value).toEqual("Formatted 10");
|
||||
expect(elements[1].value).toEqual("Formatted 42");
|
||||
expect(elements[2].value).toEqual("Formatted 31.42");
|
||||
});
|
||||
|
||||
it("adds grid cells to fill boundaries", function () {
|
||||
@ -170,7 +234,7 @@ define(
|
||||
expect(controller.getCellStyles().length).toEqual(60); // 10 * 6
|
||||
});
|
||||
|
||||
xit("listens for drop events", function () {
|
||||
it("listens for drop events", function () {
|
||||
// Layout should position panels according to
|
||||
// where the user dropped them, so it needs to
|
||||
// listen for drop events.
|
||||
@ -180,7 +244,7 @@ define(
|
||||
);
|
||||
|
||||
// Verify precondition
|
||||
expect(controller.getStyle('d')).not.toBeDefined();
|
||||
expect(testConfiguration.elements.length).toEqual(3);
|
||||
|
||||
// Notify that a drop occurred
|
||||
testModel.composition.push('d');
|
||||
@ -189,13 +253,28 @@ define(
|
||||
'd',
|
||||
{ x: 300, y: 100 }
|
||||
);
|
||||
expect(controller.getStyle('d')).toBeDefined();
|
||||
|
||||
// Should have added an element
|
||||
expect(testConfiguration.elements.length).toEqual(4);
|
||||
|
||||
// Should have triggered commit (provided by
|
||||
// EditRepresenter) with some message.
|
||||
expect(mockScope.commit)
|
||||
.toHaveBeenCalledWith(jasmine.any(String));
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("unsubscribes when destroyed", function () {
|
||||
// Make an object available
|
||||
findWatch('domainObject')(mockDomainObject);
|
||||
// Also verify precondition
|
||||
expect(mockSubscription.unsubscribe).not.toHaveBeenCalled();
|
||||
// Destroy the scope
|
||||
findOn('$destroy')();
|
||||
// Should have unsubscribed
|
||||
expect(mockSubscription.unsubscribe).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user