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 218985de7b45..993f3be0b3c8 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 @@ -631,6 +631,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' } }; + // Sets the values and names of the options in sourceSection and destSection from + // $scope.emsOptionsModel.provider_options_original_values if they exist there. $scope.updateProviderOptionsOldValues = function(sourceSection, destSection) { var section_name = _.snakeCase(sourceSection.label); sourceSection.section_name = section_name; 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 c18129ba5e06..261a31e86e80 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 @@ -380,6 +380,89 @@ describe('emsCommonFormController', function() { expect($scope.canValidateBasicInfo()).toBe(true); }); }); +}); + +describe('emsCommonFormController in the context of container provider', function() { + var $scope, $controller, $httpBackend, miqService, compile, API; + + var basic_options_example = { + image_inspector_options: { http_proxy: 'example.com'}, + proxy_settings: { http_proxy: 'example2.com' } + }; + + beforeEach(module('ManageIQ')); + + beforeEach(inject(function (_$httpBackend_, $rootScope, _$controller_, _miqService_, _$compile_, _API_) { + miqService = _miqService_; + API = _API_; + compile = _$compile_; + spyOn(miqService, 'miqAjaxButton'); + spyOn(miqService, 'restAjaxButton'); + spyOn(miqService, 'sparkleOn'); + spyOn(miqService, 'sparkleOff'); + spyOn(API, 'options').and.callFake(function(url){ return Promise.resolve({});}); + $scope = $rootScope.$new(); + + var emsCommonFormResponse = { + name: '', + emstype: 'kubernetes', + zone: 'default', + emstype_vm: false, + default_api_port: '', + provider_options: basic_options_example, + api_version: 'v2' + }; + $httpBackend = _$httpBackend_; + $httpBackend.whenGET('/ems_container/ems_container_form_fields/new').respond(emsCommonFormResponse); + $controller = _$controller_('emsCommonFormController', + { + $scope: $scope, + $attrs: { + 'formFieldsUrl': '/ems_container/ems_container_form_fields/', + 'createUrl': '/ems_container', + 'updateUrl': '/ems_container/12345' + }, + emsCommonFormId: 'new', + miqService: miqService, + API: API + }); + })); + + afterEach(function () { + $httpBackend.verifyNoOutstandingExpectation(); + $httpBackend.verifyNoOutstandingRequest(); + }); + + describe('when the emsCommonFormId is new', function () { + beforeEach(inject(function () { + $httpBackend.flush(); + })); + + it('sets the name to blank', function () { + expect($scope.emsCommonModel.name).toEqual(''); + }); + + it('sets the type to kubernetes', function () { + expect($scope.emsCommonModel.emstype).toEqual('kubernetes'); + }); + + it('sets the zone to default', function () { + expect($scope.emsCommonModel.zone).toEqual('default'); + }); + + it('sets the api_port to blank', function () { + expect($scope.emsCommonModel.default_api_port).toEqual(''); + }); + + it('sets the api_version to v2', function () { + expect($scope.emsCommonModel.api_version).toEqual('v2'); + }); + + it('sets the provider options to expected value', function () { + expect($scope.emsCommonModel.provider_options_original_values) + .toEqual(basic_options_example); + }); + }); describe('#updateProviderOptionsOldValues', function () { it('sets sourceSection options in destSection', function () { @@ -451,7 +534,7 @@ describe('emsCommonFormController', function() { .settings.hello.label).toEqual('hello'); }); }); -}); +}; describe('emsCommonFormController in the context of ems infra provider', function() { var $scope, $controller, $httpBackend, miqService, compile, API;