mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 06:08:11 +00:00
[Layout] Move spec for view switcher
Move spec for view switcher from bundle platform/commonUI/browse to bundle platform/commonUI/general to reflect refactoring to simplify usage in other places (including in Layouts, which are being transitioned for WTD-535.)
This commit is contained in:
86
platform/commonUI/general/test/ViewSwitcherControllerSpec.js
Normal file
86
platform/commonUI/general/test/ViewSwitcherControllerSpec.js
Normal file
@ -0,0 +1,86 @@
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
/**
|
||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define(
|
||||
["../src/ViewSwitcherController"],
|
||||
function (ViewSwitcherController) {
|
||||
"use strict";
|
||||
|
||||
describe("The view switcher controller", function () {
|
||||
var mockScope,
|
||||
controller;
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj("$scope", [ "$watch" ]);
|
||||
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("updates available options to reflect views", 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);
|
||||
expect(mockScope.switcher.options).toEqual(views);
|
||||
});
|
||||
|
||||
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);
|
||||
mockScope.switcher.selected = views[1];
|
||||
|
||||
// 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
|
||||
expect(mockScope.switcher.selected).toEqual(views[1]);
|
||||
});
|
||||
|
||||
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);
|
||||
mockScope.switcher.selected = views[1];
|
||||
|
||||
// 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
|
||||
expect(mockScope.switcher.selected).not.toEqual(views[1]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user