File size: 5,485 Bytes
cf0f72e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | /**
* (c) Copyright 2016 Hewlett-Packard Development Company, L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
(function() {
'use strict';
describe('horizon.app.core.images edit image controller', function() {
var controller, $scope, events, $q, settingsCall, $timeout;
///////////////////////
beforeEach(module('horizon.framework'));
beforeEach(module('horizon.app.core'));
beforeEach(module('horizon.app.core.images'));
beforeEach(inject(function ($injector, _$rootScope_, _$q_, _$timeout_) {
$scope = _$rootScope_.$new();
$q = _$q_;
$timeout = _$timeout_;
events = $injector.get('horizon.app.core.images.events');
controller = $injector.get('$controller');
}));
function createController() {
var settings = {
getSettings: function() {
settingsCall = $q.defer();
return settingsCall.promise;
}
};
return controller('horizon.app.core.images.steps.EditImageController as ctrl', {
$scope: $scope,
events: events,
'horizon.app.core.openstack-service-api.settings': settings
});
}
function setImagePromise(image) {
var deferred = $q.defer();
deferred.resolve({data: image});
$scope.imagePromise = deferred.promise;
}
it('should have options for visibility and protected', function() {
setImagePromise({id: '1', container_format: 'bare', is_public: false, properties: []});
var ctrl = createController();
expect(ctrl.imageVisibilityOptions.length).toEqual(2);
expect(ctrl.imageProtectedOptions.length).toEqual(2);
});
it('should map is_public', function() {
setImagePromise({id: '1', container_format: 'bare', is_public: false, properties: []});
var ctrl = createController();
$timeout.flush();
expect(ctrl.image.visibility).toEqual('private');
});
it('reads the data format settings', function() {
setImagePromise({id: '1', container_format: 'bare', is_public: false, properties: []});
var ctrl = createController();
settingsCall.resolve({OPENSTACK_IMAGE_FORMATS: ['aki', 'ami']});
$timeout.flush();
expect(ctrl.imageFormats.aki).toBeDefined();
expect(ctrl.imageFormats.ami).toBeDefined();
expect(Object.keys(ctrl.imageFormats).length).toBe(2);
});
it('should initialize image values correctly', function() {
setImagePromise({
id: '1',
container_format: 'bare',
disk_format: 'ova',
is_public: true,
properties: []
});
var ctrl = createController();
$timeout.flush();
expect(ctrl.image.disk_format).toEqual('ova');
expect(ctrl.image.visibility).toEqual('public');
});
it('should set local image_format to docker when container is docker', function() {
setImagePromise({id: '1', disk_format: 'raw', container_format: 'docker',
is_public: false, properties: []});
var ctrl = createController();
$timeout.flush();
expect(ctrl.image_format).toEqual('docker');
});
it('should set container to aki when disk format is same', function() {
setImagePromise({id: '1', disk_format: 'aki', container_format: '',
is_public: false, properties: []});
var ctrl = createController();
$timeout.flush();
expect(ctrl.image.container_format).toEqual('aki');
});
it('should set container to ami when disk format is same', function() {
setImagePromise({id: '1', disk_format: 'ami', container_format: '',
is_public: false, properties: []});
var ctrl = createController();
$timeout.flush();
expect(ctrl.image.container_format).toEqual('ami');
});
it('should set container to ari when disk format is same', function() {
setImagePromise({id: '1', disk_format: 'ari', container_format: '',
is_public: false, properties: []});
var ctrl = createController();
$timeout.flush();
expect(ctrl.image.container_format).toEqual('ari');
});
it('should emit events on image change', function() {
spyOn($scope, '$emit').and.callThrough();
setImagePromise({id: '1', container_format: 'bare', properties: []});
var ctrl = createController();
ctrl.image = 1;
$scope.$apply();
ctrl.image = 2;
$scope.$apply();
expect($scope.$emit).toHaveBeenCalledWith('horizon.app.core.images.IMAGE_CHANGED', 2);
});
it("should destroy the image changed watcher when the controller is destroyed", function() {
setImagePromise({id: '1', container_format: 'bare', properties: []});
spyOn($scope, '$emit').and.callThrough();
var ctrl = createController();
ctrl.image = 1;
$scope.$apply();
$scope.$emit("$destroy");
$scope.$emit.calls.reset();
ctrl.image = 2;
$scope.$apply();
expect($scope.$emit).not.toHaveBeenCalled();
});
});
})();
|