2014-11-26 02:30:30 +00:00
|
|
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../src/ViewSwitcherController"],
|
2014-11-26 03:46:56 +00:00
|
|
|
function (ViewSwitcherController) {
|
2014-11-26 02:30:30 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("The view switcher controller", function () {
|
2014-11-26 03:46:56 +00:00
|
|
|
var mockScope,
|
|
|
|
controller;
|
2014-11-26 02:30:30 +00:00
|
|
|
|
2014-11-26 03:46:56 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
mockScope = jasmine.createSpyObj("$scope", [ "$watch" ]);
|
2014-12-04 20:17:43 +00:00
|
|
|
mockScope.ngModel = {};
|
2014-11-26 03:46:56 +00:00
|
|
|
controller = new ViewSwitcherController(mockScope);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("watches for changes in applicable views", function () {
|
|
|
|
// The view capability is used by associated
|
|
|
|
// representations, so "view" in scope should always
|
|
|
|
// be the list of applicable views. The view switcher
|
|
|
|
// controller should be watching this.
|
|
|
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
|
|
|
"view",
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("maintains the current selection when views change", function () {
|
|
|
|
var views = [
|
|
|
|
{ key: "a", name: "View A" },
|
|
|
|
{ key: "b", name: "View B" },
|
|
|
|
{ key: "c", name: "View C" },
|
|
|
|
{ key: "d", name: "View D" }
|
|
|
|
];
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](views);
|
2014-12-04 20:17:43 +00:00
|
|
|
mockScope.ngModel.selected = views[1];
|
2014-11-26 03:46:56 +00:00
|
|
|
|
|
|
|
// Change the set of applicable views
|
|
|
|
mockScope.$watch.mostRecentCall.args[1]([
|
|
|
|
{ key: "a", name: "View A" },
|
|
|
|
{ key: "b", name: "View B" },
|
|
|
|
{ key: "x", name: "View X" }
|
|
|
|
]);
|
|
|
|
|
|
|
|
// "b" is still in there, should remain selected
|
2014-12-04 20:17:43 +00:00
|
|
|
expect(mockScope.ngModel.selected).toEqual(views[1]);
|
2014-11-26 03:46:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("chooses a default if a selected view becomes inapplicable", function () {
|
|
|
|
var views = [
|
|
|
|
{ key: "a", name: "View A" },
|
|
|
|
{ key: "b", name: "View B" },
|
|
|
|
{ key: "c", name: "View C" },
|
|
|
|
{ key: "d", name: "View D" }
|
|
|
|
];
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](views);
|
2014-12-04 20:17:43 +00:00
|
|
|
mockScope.ngModel.selected = views[1];
|
2014-11-26 03:46:56 +00:00
|
|
|
|
|
|
|
// Change the set of applicable views
|
|
|
|
mockScope.$watch.mostRecentCall.args[1]([
|
|
|
|
{ key: "a", name: "View A" },
|
|
|
|
{ key: "c", name: "View C" },
|
|
|
|
{ key: "x", name: "View X" }
|
|
|
|
]);
|
|
|
|
|
|
|
|
// "b" is still in there, should remain selected
|
2014-12-04 20:17:43 +00:00
|
|
|
expect(mockScope.ngModel.selected).not.toEqual(views[1]);
|
2014-11-26 03:46:56 +00:00
|
|
|
});
|
2014-11-26 02:30:30 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|