mirror of
https://github.com/nasa/openmct.git
synced 2025-02-01 00:45:41 +00:00
Merge remote-tracking branch 'origin/wtd689' into open-master
This commit is contained in:
commit
8e7f916558
@ -73,7 +73,7 @@
|
|||||||
{
|
{
|
||||||
"key": "ViewSwitcherController",
|
"key": "ViewSwitcherController",
|
||||||
"implementation": "controllers/ViewSwitcherController.js",
|
"implementation": "controllers/ViewSwitcherController.js",
|
||||||
"depends": [ "$scope" ]
|
"depends": [ "$scope", "$timeout" ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "BottomBarController",
|
"key": "BottomBarController",
|
||||||
|
@ -13,7 +13,7 @@ define(
|
|||||||
* of applicable views for a represented domain object.
|
* of applicable views for a represented domain object.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function ViewSwitcherController($scope) {
|
function ViewSwitcherController($scope, $timeout) {
|
||||||
// If the view capability gets refreshed, try to
|
// If the view capability gets refreshed, try to
|
||||||
// keep the same option chosen.
|
// keep the same option chosen.
|
||||||
function findMatchingOption(options, selected) {
|
function findMatchingOption(options, selected) {
|
||||||
@ -32,10 +32,12 @@ define(
|
|||||||
|
|
||||||
// Get list of views, read from capability
|
// Get list of views, read from capability
|
||||||
function updateOptions(views) {
|
function updateOptions(views) {
|
||||||
|
$timeout(function () {
|
||||||
$scope.ngModel.selected = findMatchingOption(
|
$scope.ngModel.selected = findMatchingOption(
|
||||||
views || [],
|
views || [],
|
||||||
($scope.ngModel || {}).selected
|
($scope.ngModel || {}).selected
|
||||||
);
|
);
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update view options when the in-scope results of using the
|
// Update view options when the in-scope results of using the
|
||||||
|
@ -10,12 +10,15 @@ define(
|
|||||||
|
|
||||||
describe("The view switcher controller", function () {
|
describe("The view switcher controller", function () {
|
||||||
var mockScope,
|
var mockScope,
|
||||||
|
mockTimeout,
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockScope = jasmine.createSpyObj("$scope", [ "$watch" ]);
|
mockScope = jasmine.createSpyObj("$scope", [ "$watch" ]);
|
||||||
|
mockTimeout = jasmine.createSpy("$timeout");
|
||||||
|
mockTimeout.andCallFake(function (cb) { cb(); });
|
||||||
mockScope.ngModel = {};
|
mockScope.ngModel = {};
|
||||||
controller = new ViewSwitcherController(mockScope);
|
controller = new ViewSwitcherController(mockScope, mockTimeout);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("watches for changes in applicable views", function () {
|
it("watches for changes in applicable views", function () {
|
||||||
@ -71,6 +74,19 @@ define(
|
|||||||
expect(mockScope.ngModel.selected).not.toEqual(views[1]);
|
expect(mockScope.ngModel.selected).not.toEqual(views[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Use of a timeout avoids infinite digest problems when deeply
|
||||||
|
// nesting switcher-driven views (e.g. in a layout.) See WTD-689
|
||||||
|
it("updates initial selection on a timeout", function () {
|
||||||
|
// Verify precondition
|
||||||
|
expect(mockTimeout).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
// Invoke the watch for set of views
|
||||||
|
mockScope.$watch.mostRecentCall.args[1]([]);
|
||||||
|
|
||||||
|
// Should have run on a timeout
|
||||||
|
expect(mockTimeout).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
Loading…
x
Reference in New Issue
Block a user