From 2cbee6cb01670a7742a043a426475459aefb5223 Mon Sep 17 00:00:00 2001 From: Erez Freiberger Date: Wed, 18 Oct 2017 13:30:15 +0300 Subject: [PATCH] adding more tests --- .../ems_common/ems_common_form_controller.js | 2 + .../ems_common_form_controller_spec.js | 123 ++++++++++++++++++ 2 files changed, 125 insertions(+) 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 e58c0f0dbb1d..9669860b1898 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 @@ -633,6 +633,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..398154b89772 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,129 @@ describe('emsCommonFormController', function() { expect($scope.canValidateBasicInfo()).toBe(true); }); }); +}); + +describe('emsCommonFormController in the context of container provider', function() { + var $scope, $controller, $httpBackend, miqService, compile, API; + + 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: '', + zone: 'default', + emstype_vm: false, + default_api_port: '', + 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(''); + }); + + 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'); + }); + }); + + describe('when the emsCommonFormId of existing provider', function () { + var basic_options_example = { + image_inspector_options: { http_proxy: 'example.com'}, + proxy_settings: { http_proxy: 'example2.com' } + }; + + var emsCommonFormResponse = { + name: 'osp1', + emstype: 'kubernetes', + zone: 'default', + emstype_vm: false, + default_api_port: '', + provider_options: basic_options_example, + api_version: 'v2' + }; + + beforeEach(inject(function (_$controller_) { + $httpBackend.whenGET('/ems_container/ems_container_form_fields/12345').respond(emsCommonFormResponse); + + $controller = _$controller_('emsCommonFormController', + { + $scope: $scope, + $attrs: { + 'formFieldsUrl': '/ems_container/ems_container_form_fields/', + 'createUrl': '/ems_container', + 'updateUrl': '/ems_container/12345' + }, + emsCommonFormId: 12345, + miqService: miqService, + API: API + }); + $httpBackend.flush(); + })); + + it('sets the name to osp1', function () { + expect($scope.emsCommonModel.name).toEqual(emsCommonFormResponse.name); + }); + + it('sets the type to kubernetes', function () { + expect($scope.emsCommonModel.emstype).toEqual(emsCommonFormResponse.emstype); + }); + + 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.emsOptionsModel.provider_options_original_values).toEqual(basic_options_example); + }); + }); describe('#updateProviderOptionsOldValues', function () { it('sets sourceSection options in destSection', function () {