diff --git a/openstack_dashboard/static/app/core/images/details/overview.controller.js b/openstack_dashboard/static/app/core/images/details/overview.controller.js index 4b6849ef3..2d0ffecd6 100644 --- a/openstack_dashboard/static/app/core/images/details/overview.controller.js +++ b/openstack_dashboard/static/app/core/images/details/overview.controller.js @@ -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}; diff --git a/openstack_dashboard/static/app/core/images/details/overview.controller.spec.js b/openstack_dashboard/static/app/core/images/details/overview.controller.spec.js index e1672e80a..241f22df0 100644 --- a/openstack_dashboard/static/app/core/images/details/overview.controller.spec.js +++ b/openstack_dashboard/static/app/core/images/details/overview.controller.spec.js @@ -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); })); });