mirror of
https://github.com/nasa/openmct.git
synced 2025-06-13 04:38:15 +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:
@ -11,7 +11,7 @@
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
<!-- Fixed position elements -->
|
<!-- Fixed position elements -->
|
||||||
<mct-include ng-repeat="element in controller.getDecoratedElements()"
|
<mct-include ng-repeat="element in controller.getElements()"
|
||||||
style="position: absolute;"
|
style="position: absolute;"
|
||||||
key="element.template"
|
key="element.template"
|
||||||
ng-class="{ test: controller.selected(element) }"
|
ng-class="{ test: controller.selected(element) }"
|
||||||
|
@ -24,6 +24,7 @@ define(
|
|||||||
subscription,
|
subscription,
|
||||||
cellStyles = [],
|
cellStyles = [],
|
||||||
elementProxies = [],
|
elementProxies = [],
|
||||||
|
elementProxiesById = {},
|
||||||
selection;
|
selection;
|
||||||
|
|
||||||
// Refresh cell styles (e.g. because grid extent changed)
|
// Refresh cell styles (e.g. because grid extent changed)
|
||||||
@ -65,7 +66,7 @@ define(
|
|||||||
function updateValue(telemetryObject) {
|
function updateValue(telemetryObject) {
|
||||||
var id = telemetryObject && telemetryObject.getId();
|
var id = telemetryObject && telemetryObject.getId();
|
||||||
if (id) {
|
if (id) {
|
||||||
elementProxies.forEach(function (element) {
|
(elementProxiesById[id] || []).forEach(function (element) {
|
||||||
element.name = telemetryObject.getModel().name;
|
element.name = telemetryObject.getModel().name;
|
||||||
element.value = telemetryFormatter.formatRangeValue(
|
element.value = telemetryFormatter.formatRangeValue(
|
||||||
subscription.getRangeValue(telemetryObject)
|
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?
|
// TODO: Ensure elements for all domain objects?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,11 +236,11 @@ define(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Get an array of elements in this panel, decorated for
|
* Get an array of elements in this panel; these are
|
||||||
* display.
|
* decorated proxies for both selection and display.
|
||||||
* @returns {Array} elements in this panel
|
* @returns {Array} elements in this panel
|
||||||
*/
|
*/
|
||||||
getDecoratedElements: function () {
|
getElements: function () {
|
||||||
return elementProxies;
|
return elementProxies;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +14,7 @@ define(
|
|||||||
testGrid,
|
testGrid,
|
||||||
testModel,
|
testModel,
|
||||||
testValues,
|
testValues,
|
||||||
|
testConfiguration,
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
// Utility function; find a watch for a given expression
|
// Utility function; find a watch for a given expression
|
||||||
@ -41,9 +42,10 @@ define(
|
|||||||
function makeMockDomainObject(id) {
|
function makeMockDomainObject(id) {
|
||||||
var mockObject = jasmine.createSpyObj(
|
var mockObject = jasmine.createSpyObj(
|
||||||
'domainObject-' + id,
|
'domainObject-' + id,
|
||||||
[ 'getId' ]
|
[ 'getId', 'getModel' ]
|
||||||
);
|
);
|
||||||
mockObject.getId.andReturn(id);
|
mockObject.getId.andReturn(id);
|
||||||
|
mockObject.getModel.andReturn({ name: "Point " + id});
|
||||||
return mockObject;
|
return mockObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +77,11 @@ define(
|
|||||||
layoutGrid: testGrid
|
layoutGrid: testGrid
|
||||||
};
|
};
|
||||||
testValues = { a: 10, b: 42, c: 31.42 };
|
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);
|
mockSubscriber.subscribe.andReturn(mockSubscription);
|
||||||
mockSubscription.getTelemetryObjects.andReturn(
|
mockSubscription.getTelemetryObjects.andReturn(
|
||||||
@ -87,6 +94,8 @@ define(
|
|||||||
return "Formatted " + v;
|
return "Formatted " + v;
|
||||||
});
|
});
|
||||||
mockScope.model = testModel;
|
mockScope.model = testModel;
|
||||||
|
mockScope.configuration = testConfiguration;
|
||||||
|
mockScope.selection = []; // Act like edit mode
|
||||||
|
|
||||||
controller = new FixedController(
|
controller = new FixedController(
|
||||||
mockScope,
|
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;
|
mockScope.domainObject = mockDomainObject;
|
||||||
|
|
||||||
// First pass - should simply should subscribe
|
// First pass - should simply should subscribe
|
||||||
@ -123,30 +132,85 @@ define(
|
|||||||
expect(mockSubscriber.subscribe.calls.length).toEqual(2);
|
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;
|
mockScope.model = testModel;
|
||||||
findWatch("model.composition")(mockScope.model.composition);
|
testModel.modified = 1;
|
||||||
// Should have styles for all elements of composition
|
findWatch("model.modified")(testModel.modified);
|
||||||
expect(controller.getStyle('a')).toBeDefined();
|
|
||||||
expect(controller.getStyle('b')).toBeDefined();
|
elements = controller.getElements();
|
||||||
expect(controller.getStyle('c')).toBeDefined();
|
expect(elements.length).toEqual(3);
|
||||||
expect(controller.getStyle('d')).not.toBeDefined();
|
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
|
// Initialize
|
||||||
mockScope.domainObject = mockDomainObject;
|
mockScope.domainObject = mockDomainObject;
|
||||||
mockScope.model = testModel;
|
mockScope.model = testModel;
|
||||||
findWatch("domainObject")(mockDomainObject);
|
findWatch("domainObject")(mockDomainObject);
|
||||||
|
findWatch("model.modified")(1);
|
||||||
findWatch("model.composition")(mockScope.model.composition);
|
findWatch("model.composition")(mockScope.model.composition);
|
||||||
|
|
||||||
// Invoke the subscription callback
|
// Invoke the subscription callback
|
||||||
mockSubscriber.subscribe.mostRecentCall.args[1]();
|
mockSubscriber.subscribe.mostRecentCall.args[1]();
|
||||||
|
|
||||||
|
// Get elements that controller is now exposing
|
||||||
|
elements = controller.getElements();
|
||||||
|
|
||||||
// Formatted values should be available
|
// Formatted values should be available
|
||||||
expect(controller.getValue('a')).toEqual("Formatted 10");
|
expect(elements[0].value).toEqual("Formatted 10");
|
||||||
expect(controller.getValue('b')).toEqual("Formatted 42");
|
expect(elements[1].value).toEqual("Formatted 42");
|
||||||
expect(controller.getValue('c')).toEqual("Formatted 31.42");
|
expect(elements[2].value).toEqual("Formatted 31.42");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds grid cells to fill boundaries", function () {
|
it("adds grid cells to fill boundaries", function () {
|
||||||
@ -170,7 +234,7 @@ define(
|
|||||||
expect(controller.getCellStyles().length).toEqual(60); // 10 * 6
|
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
|
// Layout should position panels according to
|
||||||
// where the user dropped them, so it needs to
|
// where the user dropped them, so it needs to
|
||||||
// listen for drop events.
|
// listen for drop events.
|
||||||
@ -180,7 +244,7 @@ define(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Verify precondition
|
// Verify precondition
|
||||||
expect(controller.getStyle('d')).not.toBeDefined();
|
expect(testConfiguration.elements.length).toEqual(3);
|
||||||
|
|
||||||
// Notify that a drop occurred
|
// Notify that a drop occurred
|
||||||
testModel.composition.push('d');
|
testModel.composition.push('d');
|
||||||
@ -189,13 +253,28 @@ define(
|
|||||||
'd',
|
'd',
|
||||||
{ x: 300, y: 100 }
|
{ 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
|
// Should have triggered commit (provided by
|
||||||
// EditRepresenter) with some message.
|
// EditRepresenter) with some message.
|
||||||
expect(mockScope.commit)
|
expect(mockScope.commit)
|
||||||
.toHaveBeenCalledWith(jasmine.any(String));
|
.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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
Reference in New Issue
Block a user