Merge "Fix spec file variable/ improve code coverage"

This commit is contained in:
Jenkins 2017-01-30 16:36:03 +00:00 committed by Gerrit Code Review
commit 5ecc28189d
2 changed files with 28 additions and 4 deletions

View File

@ -44,7 +44,7 @@
ctrl.image.properties = Object.keys(ctrl.image.properties).map(function mapProps(prop) {
var propValue = ctrl.image.properties[prop];
if ($.isArray(propValue) && propValue.length === 0) {
if (angular.isArray(propValue) && propValue.length === 0) {
propValue = '';
}
return {name: prop, value: propValue};

View File

@ -19,6 +19,7 @@
describe('image overview controller', function() {
var ctrl;
var sessionObj = {project_id: '12'};
var glance = {
getNamespaces: angular.noop
};
@ -29,8 +30,8 @@
var session = $injector.get('horizon.app.core.openstack-service-api.userSession');
var deferred = $q.defer();
var sessionDeferred = $q.defer();
deferred.resolve({data: {properties: {'a': 'apple'}}});
deferred.resolve({project_id: '12'});
deferred.resolve({data: {properties: [{'a': 'apple'}, [], {}]}});
sessionDeferred.resolve(sessionObj);
spyOn(glance, 'getNamespaces').and.returnValue(deferred.promise);
spyOn(session, 'get').and.returnValue(sessionDeferred.promise);
ctrl = $controller('ImageOverviewController',
@ -44,10 +45,33 @@
expect(ctrl.resourceType).toBeDefined();
});
it('sets ctrl.metadata', inject(function($timeout) {
it('sets ctrl.images.properties (metadata)', inject(function($timeout) {
$timeout.flush();
expect(ctrl.image).toBeDefined();
expect(ctrl.image.properties).toBeDefined();
expect(ctrl.image.properties[0].name).toEqual('0');
expect(ctrl.image.properties[0].value).toEqual({'a': 'apple'});
}));
it('sets ctrl.images.properties propValue if empty array', inject(function($timeout) {
$timeout.flush();
expect(ctrl.image).toBeDefined();
expect(ctrl.image.properties).toBeDefined();
expect(ctrl.image.properties[1].name).toEqual('1');
expect(ctrl.image.properties[1].value).toEqual('');
}));
it('sets ctrl.images.properties propValue if empty object', inject(function($timeout) {
$timeout.flush();
expect(ctrl.image).toBeDefined();
expect(ctrl.image.properties).toBeDefined();
expect(ctrl.image.properties[2].name).toEqual('2');
expect(ctrl.image.properties[2].value).toEqual({});
}));
it('sets ctrl.projectId', inject(function($timeout) {
$timeout.flush();
expect(ctrl.projectId).toBe(sessionObj.project_id);
}));
});