From f4f497246d7448c23d623332d116ed8e82baf73b Mon Sep 17 00:00:00 2001 From: David Gutman Date: Wed, 7 Mar 2018 14:09:57 +0100 Subject: [PATCH] Tabs may not appear in angular instance wizard In the launch instance wizard, when a specific tab is disabled (by example not matching the required policy) then some other tabs may not be displayed. After a long analysis : Each tabs resolved itself if it should or shouldn't be displayed (ready or not). But at the first rejection (first tab ready=false), the wizard will display all "ready" tabs without waiting for other tabs to be ready or not. If all tabs had been resolved before the first reject, the display is correct, but sometimes when the reject finishes first, a lot of tabs are missing. This bugs is not current because I think it is not common to hide tabs. Closes-Bug: #1752604 Change-Id: I67f96092d9f82374087fc0c87b857292e188b675 --- .../framework/widgets/wizard/wizard.controller.js | 4 ++-- .../framework/widgets/wizard/wizard.spec.js | 15 ++++++++++----- .../static/app/core/workflow/decorator.service.js | 8 +++++++- .../app/core/workflow/decorator.service.spec.js | 15 +++++++++++++-- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/horizon/static/framework/widgets/wizard/wizard.controller.js b/horizon/static/framework/widgets/wizard/wizard.controller.js index 0af8de02ae..eeb3c6ec06 100644 --- a/horizon/static/framework/widgets/wizard/wizard.controller.js +++ b/horizon/static/framework/widgets/wizard/wizard.controller.js @@ -208,8 +208,8 @@ if (step.checkReadiness) { var promise = step.checkReadiness(); stepReadyPromises.push(promise); - promise.then(function() { - step.ready = true; + promise.then(function(isReady) { + step.ready = isReady; }); } }); diff --git a/horizon/static/framework/widgets/wizard/wizard.spec.js b/horizon/static/framework/widgets/wizard/wizard.spec.js index 2fd2eaa245..dadb5578a9 100644 --- a/horizon/static/framework/widgets/wizard/wizard.spec.js +++ b/horizon/static/framework/widgets/wizard/wizard.spec.js @@ -225,9 +225,9 @@ expect(checkedStep.checkReadiness).toHaveBeenCalled(); }); - it("should remove steps when readiness is false", function() { + it("should remove steps when readiness doesn't resolve with true parameter", function() { - var checkReadinessPromises = [$q.defer(), $q.defer(), $q.defer(), $q.defer()]; + var checkReadinessPromises = [$q.defer(), $q.defer(), $q.defer(), $q.defer(), $q.defer()]; $scope.workflow = { steps: [ @@ -247,20 +247,25 @@ { id: 'five', checkReadiness: function() { return checkReadinessPromises[3].promise; } + }, + { + id: 'six', + checkReadiness: function() { return checkReadinessPromises[4].promise; } } ] }; checkReadinessPromises[0].reject(); - checkReadinessPromises[1].resolve(); + checkReadinessPromises[1].resolve(true); checkReadinessPromises[2].reject(); - checkReadinessPromises[3].resolve(); + checkReadinessPromises[3].resolve(false); + checkReadinessPromises[4].resolve(true); $scope.$apply(); expect($scope.steps.length).toBe(3); expect($scope.steps[0].id).toBe('one'); expect($scope.steps[1].id).toBe('three'); - expect($scope.steps[2].id).toBe('five'); + expect($scope.steps[2].id).toBe('six'); }); it('should pass result of submit function on to close function', function () { diff --git a/openstack_dashboard/static/app/core/workflow/decorator.service.js b/openstack_dashboard/static/app/core/workflow/decorator.service.js index 5afcec68e2..b7a8b6c824 100644 --- a/openstack_dashboard/static/app/core/workflow/decorator.service.js +++ b/openstack_dashboard/static/app/core/workflow/decorator.service.js @@ -87,7 +87,13 @@ } if (promises.length > 0) { step.checkReadiness = function () { - return $q.all(promises); + return $q.all(promises).then(function() { + // all promises have succeeded, return the readiness status to true + return true; + }, function() { + // at least one promise has failed, return the readiness status to false + return false; + }); }; } } diff --git a/openstack_dashboard/static/app/core/workflow/decorator.service.spec.js b/openstack_dashboard/static/app/core/workflow/decorator.service.spec.js index ee2e580cd2..94775d49d2 100644 --- a/openstack_dashboard/static/app/core/workflow/decorator.service.spec.js +++ b/openstack_dashboard/static/app/core/workflow/decorator.service.spec.js @@ -67,7 +67,7 @@ expect(novaExtensionsService.ifNameEnabled).toHaveBeenCalledWith('foo-novaExtension'); }); - it('step checkReadiness function returns correct results', function() { + it('step checkReadiness function returns true when promise is resolved', function() { decoratorService(spec); var readinessResult; deferred.resolve('foo'); @@ -75,7 +75,18 @@ readinessResult = result; }); $scope.$apply(); - expect(readinessResult).toEqual(['foo']); + expect(readinessResult).toEqual(true); + }); + + it('step checkReadiness function returns false when promise is rejected', function() { + decoratorService(spec); + var readinessResult; + deferred.reject(); + steps[1].checkReadiness().then(function(result) { + readinessResult = result; + }); + $scope.$apply(); + expect(readinessResult).toEqual(false); }); });