From 6a332cfb21d5b74affd276d908b2da2055b6ab11 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Fri, 12 Oct 2018 11:56:23 -0700 Subject: [PATCH 1/2] maintain a single source of truth in multi tab situation `$scope.currentTab` will always contain the correct tab value (prefix value for the endpoint validation) https://bugzilla.redhat.com/show_bug.cgi?id=1609735 --- .../controllers/ems_common/ems_common_form_controller.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js b/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js index 50b467e324f..e781b209e74 100644 --- a/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js +++ b/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js @@ -674,9 +674,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' } }; - $scope.validateClicked = function($event, authType, formSubmit) { - $scope.authType = authType; - miqService.validateWithREST($event, authType, $scope.actionUrl, formSubmit) + $scope.validateClicked = function($event, _authType, formSubmit) { + miqService.validateWithREST($event, $scope.currentTab, $scope.actionUrl, formSubmit) .then(function success(data) { // check if data object is a JSON, otherwise (recieved JS or HTML) output a warning to the user. if (data === Object(data)) { @@ -699,7 +698,7 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' }; $scope.updateAuthStatus = function(updatedValue) { - $scope.angularForm[$scope.authType + '_auth_status'].$setViewValue(updatedValue); + $scope.angularForm[$scope.currentTab + '_auth_status'].$setViewValue(updatedValue); }; $scope.updateHostname = function(value) { From f9109f75d326479b886a49044b4f154e14d95c0a Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Fri, 12 Oct 2018 12:00:32 -0700 Subject: [PATCH 2/2] verifies if currentTab value is sent for endpoint validation --- .../ems_common_form_controller_spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/javascripts/controllers/ems_common/ems_common_form_controller_spec.js b/spec/javascripts/controllers/ems_common/ems_common_form_controller_spec.js index 4a77e524a08..8f60983406c 100644 --- a/spec/javascripts/controllers/ems_common/ems_common_form_controller_spec.js +++ b/spec/javascripts/controllers/ems_common/ems_common_form_controller_spec.js @@ -12,6 +12,7 @@ describe('emsCommonFormController', function() { spyOn(miqService, 'sparkleOn'); spyOn(miqService, 'sparkleOff'); spyOn(API, 'options').and.callFake(function(url){ return Promise.resolve({}); }); + spyOn(miqService, 'validateWithREST').and.callFake(function(url){ return Promise.resolve({}); }); $scope = $rootScope.$new(); var emsCommonFormResponse = { @@ -369,6 +370,23 @@ describe('emsCommonFormController', function() { }); }); + describe('#validateClicked', function() { + beforeEach(function() { + $httpBackend.flush(); + $scope.currentTab = "console"; + $scope.actionUrl = "/xyz"; + $scope.validateClicked($.Event, "default", true); + }); + + it('turns the spinner on via the miqService', function() { + expect(miqService.sparkleOn).toHaveBeenCalled(); + }); + + it('delegates to miqService.validateClicked', function() { + expect(miqService.validateWithREST).toHaveBeenCalledWith($.Event, "console", "/xyz", true); + }); + }); + describe('Validates credential fields', function() { beforeEach(function() { $httpBackend.flush();