Skip to content

Commit

Permalink
adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Erez Freiberger committed Oct 18, 2017
1 parent a1f5ec2 commit 1f6202e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1f6202e

Please sign in to comment.