[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:
Victor Woeltjen
2015-02-19 16:24:45 -08:00
parent 3cfcd027e0
commit 1015e97b3e
3 changed files with 112 additions and 21 deletions

View File

@ -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();
});
});
}
);