summaryrefslogtreecommitdiff
path: root/horizon
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-04-06 22:27:37 +0000
committerGerrit Code Review <review@openstack.org>2015-04-06 22:27:37 +0000
commitaee940186bddd83e4da23d3428bcc7a16fc95c89 (patch)
treebbe6bcc5f8b5daa34f36e7c24039dcfb314c349f /horizon
parentda433ef7c486308e367cc575c974fd0d716828e6 (diff)
parent1f8377d9eb4b8987782060a254538172145013f7 (diff)
downloadhorizon-aee940186bddd83e4da23d3428bcc7a16fc95c89.tar.gz
Merge "[Launch Instance Fix] Add better coverage for widgets"
Diffstat (limited to 'horizon')
-rw-r--r--horizon/static/angular/modal/modal-wait-spinner.js (renamed from horizon/static/angular/modal-wait-spinner/modal-wait-spinner.js)0
-rw-r--r--horizon/static/angular/modal/modal-wait-spinner.scss (renamed from horizon/static/angular/modal-wait-spinner/modal-wait-spinner.scss)0
-rw-r--r--horizon/static/angular/modal/modal-wait-spinner.spec.js101
-rw-r--r--horizon/static/angular/modal/modal.js2
-rw-r--r--horizon/static/angular/modal/modal.spec.js169
-rw-r--r--horizon/static/angular/modal/simple-modal.spec.js56
-rw-r--r--horizon/static/angular/styles.scss2
-rw-r--r--horizon/static/angular/transfer-table/transfer-table.spec.js76
-rw-r--r--horizon/templates/horizon/_scripts.html2
-rw-r--r--horizon/templates/horizon/jasmine/jasmine.html2
-rw-r--r--horizon/test/jasmine/jasmine_tests.py5
11 files changed, 352 insertions, 63 deletions
diff --git a/horizon/static/angular/modal-wait-spinner/modal-wait-spinner.js b/horizon/static/angular/modal/modal-wait-spinner.js
index 2c5cf51e9..2c5cf51e9 100644
--- a/horizon/static/angular/modal-wait-spinner/modal-wait-spinner.js
+++ b/horizon/static/angular/modal/modal-wait-spinner.js
diff --git a/horizon/static/angular/modal-wait-spinner/modal-wait-spinner.scss b/horizon/static/angular/modal/modal-wait-spinner.scss
index 44ec53749..44ec53749 100644
--- a/horizon/static/angular/modal-wait-spinner/modal-wait-spinner.scss
+++ b/horizon/static/angular/modal/modal-wait-spinner.scss
diff --git a/horizon/static/angular/modal/modal-wait-spinner.spec.js b/horizon/static/angular/modal/modal-wait-spinner.spec.js
new file mode 100644
index 000000000..363495923
--- /dev/null
+++ b/horizon/static/angular/modal/modal-wait-spinner.spec.js
@@ -0,0 +1,101 @@
+/*
+ * (c) Copyright 2015 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('Wait Spinner Tests', function() {
+
+ var service, modal;
+
+ beforeEach(module('hz.widget.modal-wait-spinner'));
+
+ beforeEach(inject(function(modalWaitSpinnerService) {
+ service = modalWaitSpinnerService;
+ }));
+
+ beforeEach(inject(function($modal) {
+ modal = $modal;
+ }));
+
+ it('returns the service', function() {
+ expect(service).toBeDefined();
+ });
+
+ describe('showModalSpinner', function() {
+
+ it('is defined', function() {
+ expect(service.showModalSpinner).toBeDefined();
+ });
+
+ it('opens modal with the correct object', inject(function($modal) {
+ var wanted = { backdrop: 'static',
+ template: '<div wait-spinner class="modal-body" text="my text"></div>',
+ windowClass: 'modal-wait-spinner modal_wrapper loading'
+ };
+ spyOn($modal, 'open');
+ service.showModalSpinner('my text');
+ expect($modal.open).toHaveBeenCalled();
+ expect($modal.open.calls.count()).toBe(1);
+ expect($modal.open.calls.argsFor(0)).toEqual([wanted]);
+ }));
+
+ });
+
+ describe('hideModalSpinner', function() {
+
+ it('has hideModalSpinner', function() {
+ expect(service.hideModalSpinner).toBeDefined();
+ });
+
+ it("dismisses modal when it has been opened", inject(function($modal) {
+ var modal = {dismiss: function() {}};
+ spyOn($modal, 'open').and.returnValue(modal);
+ service.showModalSpinner('asdf');
+ spyOn(modal, 'dismiss');
+ service.hideModalSpinner();
+ expect(modal.dismiss).toHaveBeenCalled();
+ }));
+
+ });
+
+ });
+
+ describe('Wait Spinner Directive', function() {
+ var $scope, $element, $timeout;
+
+ beforeEach(module('ui.bootstrap'));
+ beforeEach(module('hz.widget.modal-wait-spinner'));
+
+ beforeEach(inject(function($injector) {
+ var $compile = $injector.get('$compile');
+ $scope = $injector.get('$rootScope').$new();
+ $timeout = $injector.get('$timeout');
+
+ var markup = '<div wait-spinner text="hello!"></div>';
+ $element = angular.element(markup);
+ $compile($element)($scope);
+
+ $scope.$digest();
+ }));
+
+ it("creates a p element", function() {
+ var elems = $element.find('p');
+ expect(elems.length).toBe(1);
+ });
+
+ });
+
+})();
diff --git a/horizon/static/angular/modal/modal.js b/horizon/static/angular/modal/modal.js
index a3af9f901..e71d3c3a3 100644
--- a/horizon/static/angular/modal/modal.js
+++ b/horizon/static/angular/modal/modal.js
@@ -92,4 +92,4 @@
} // end of function
]); // end of factory
-})(); \ No newline at end of file
+})();
diff --git a/horizon/static/angular/modal/modal.spec.js b/horizon/static/angular/modal/modal.spec.js
new file mode 100644
index 000000000..5977b1bf8
--- /dev/null
+++ b/horizon/static/angular/modal/modal.spec.js
@@ -0,0 +1,169 @@
+/*
+ * (c) Copyright 2015 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('hz.widget.modal module', function() {
+
+ //beforeEach(module('ui.bootstrap'));
+ beforeEach(module('hz.widget.modal'));
+
+ describe('simpleModalCtrl', function() {
+ var scope, modalInstance, context, ctrl;
+
+ beforeEach(inject(function($controller) {
+ scope = {};
+ modalInstance = {
+ close: function() {},
+ dismiss: function() {}
+ };
+ context = { what: 'is it' };
+ ctrl = $controller('simpleModalCtrl',
+ {$scope: scope, $modalInstance: modalInstance,
+ context: context});
+ }));
+
+ it('establishes a controller', function() {
+ expect(ctrl).toBeDefined();
+ });
+
+ it('sets context on the scope', function() {
+ expect(scope.context).toBeDefined();
+ expect(scope.context).toEqual({ what: 'is it' });
+ });
+
+ it('sets action functions', function() {
+ expect(scope.submit).toBeDefined();
+ expect(scope.cancel).toBeDefined();
+ });
+
+ it('makes submit close the modal instance', function() {
+ expect(scope.submit).toBeDefined();
+ spyOn(modalInstance, 'close');
+ scope.submit();
+ expect(modalInstance.close.calls.count()).toBe(1);
+ });
+
+ it('makes cancel close the modal instance', function() {
+ expect(scope.cancel).toBeDefined();
+ spyOn(modalInstance, 'dismiss');
+ scope.cancel();
+ expect(modalInstance.dismiss).toHaveBeenCalledWith('cancel');
+ });
+
+ });
+
+ describe('simpleModalService', function() {
+ var service, modal;
+
+ beforeEach(module(function($provide) {
+ modal = { open: function() {return 'val';} };
+ $provide.value('basePath', '/this/path/');
+ $provide.value('$modal', modal);
+ }));
+
+ beforeEach(inject(function(simpleModalService) {
+ service = simpleModalService;
+ }));
+
+ it('defines the service', function() {
+ expect(service).toBeDefined();
+ });
+
+ it('returns undefined if called with no parameters', function() {
+ expect(service()).toBeUndefined();
+ });
+
+ it('returns undefined if called without required parameters', function() {
+ expect(service({title: {}})).toBeUndefined();
+ expect(service({body: {}})).toBeUndefined();
+ });
+
+ describe('Maximal Values Passed to the Modal', function() {
+
+ var returned, passed, passedContext;
+
+ beforeEach(function() {
+ var opts = { title: 'my title', body: 'my body', submit: 'Yes',
+ cancel: 'No' };
+ spyOn(modal, 'open');
+ returned = service(opts);
+ passed = modal.open.calls.argsFor(0)[0];
+ passedContext = passed.resolve.context();
+ });
+
+ it('sets the controller', function() {
+ expect(passed.controller).toBe('simpleModalCtrl');
+ });
+
+ it('sets the template URL', function() {
+ expect(passed.templateUrl).toBe('/this/path/modal/simple-modal.html');
+ });
+
+ it('sets the title', function() {
+ expect(passedContext.title).toBe('my title');
+ });
+
+ it('sets the body', function() {
+ expect(passedContext.body).toBe('my body');
+ });
+
+ it('sets the submit', function() {
+ expect(passedContext.submit).toBe('Yes');
+ });
+
+ // THIS IS AN EXTANT FAILURE
+ xit('sets the cancel', function() {
+ expect(passedContext.cancel).toBe('No');
+ });
+
+ });
+
+ describe('Minimal Values Passed to the Modal', function() {
+
+ var returned, passed, passedContext;
+
+ beforeEach(function() {
+ var opts = { title: 'my title', body: 'my body' };
+ spyOn(modal, 'open');
+ returned = service(opts);
+ passed = modal.open.calls.argsFor(0)[0];
+ passedContext = passed.resolve.context();
+ });
+
+ it('sets the title', function() {
+ expect(passedContext.title).toBe('my title');
+ });
+
+ it('sets the body', function() {
+ expect(passedContext.body).toBe('my body');
+ });
+
+ it('defaults the submit', function() {
+ expect(passedContext.submit).toBe('Submit');
+ });
+
+ it('defaults the cancel', function() {
+ expect(passedContext.cancel).toBe('Cancel');
+ });
+
+ });
+
+ });
+
+ });
+
+})();
diff --git a/horizon/static/angular/modal/simple-modal.spec.js b/horizon/static/angular/modal/simple-modal.spec.js
deleted file mode 100644
index 1b66a531e..000000000
--- a/horizon/static/angular/modal/simple-modal.spec.js
+++ /dev/null
@@ -1,56 +0,0 @@
-/* jshint globalstrict: true */
-'use strict';
-
-describe('hz.widget.modal module', function(){
- it('should have been defined', function(){
- expect(angular.module('hz.widget.modal')).toBeDefined();
- });
-});
-
-describe('modal factory', function(){
-
- var modal;
- var modalData = {
- title: 'Confirm deletion',
- body: 'Are you sure?',
- submit: 'Yes',
- cancel: 'No'
- };
-
- beforeEach(module('ui.bootstrap'));
- beforeEach(module('hz'));
- beforeEach(module('hz.widgets'));
- beforeEach(module('hz.widget.modal'));
- beforeEach(inject(function($injector, simpleModalService){
- modal = simpleModalService;
- }));
-
- it('should fail without any params', function(){
- expect(modal()).toBeUndefined();
- });
-
- it('should fail without a title', function(){
- var data = angular.copy(modalData);
- delete data.title;
- expect(modal(data)).toBeUndefined();
- });
-
- it('should fail without a body', function(){
- var data = angular.copy(modalData);
- delete data.body;
- expect(modal(data)).toBeUndefined();
- });
-
- it('should have default submit and cancel labels', function(){
- var data = angular.copy(modalData);
- delete data.submit;
- delete data.cancel;
- expect(modal(data)).toBeDefined();
- });
-
- it('should work when all params are supplied', function(){
- var data = angular.copy(modalData);
- expect(modal(data)).toBeDefined();
- });
-
-});
diff --git a/horizon/static/angular/styles.scss b/horizon/static/angular/styles.scss
index e165ee8bd..e074878d4 100644
--- a/horizon/static/angular/styles.scss
+++ b/horizon/static/angular/styles.scss
@@ -5,7 +5,7 @@
@import "charts/chart-tooltip";
@import "charts/pie-chart";
@import "action-list/action-list";
-@import "modal-wait-spinner/modal-wait-spinner";
+@import "modal/modal-wait-spinner";
@import "metadata-tree/metadata-tree";
@import "metadata-display/metadata-display";
@import "magic-search/magic-search.scss";
diff --git a/horizon/static/angular/transfer-table/transfer-table.spec.js b/horizon/static/angular/transfer-table/transfer-table.spec.js
index d8d424448..854106a68 100644
--- a/horizon/static/angular/transfer-table/transfer-table.spec.js
+++ b/horizon/static/angular/transfer-table/transfer-table.spec.js
@@ -1,4 +1,18 @@
-/* jshint browser: true */
+/*
+ * (c) Copyright 2015 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';
@@ -8,6 +22,64 @@
});
});
+ describe("Filters", function() {
+ var filter;
+
+ beforeEach(module('hz.widget.transfer-table'));
+
+ describe("warningText", function() {
+
+ beforeEach(inject(function(warningTextFilter) {
+ filter = warningTextFilter;
+ }));
+
+ it('returns value if present', function() {
+ expect(filter({ thing: 'stuff'}, 'thing')).toBe('stuff');
+ });
+
+ it('returns empty string if not present', function() {
+ expect(filter({ thing: 'stuff'}, 'other')).toBe('');
+ });
+
+ });
+
+ describe("rowFilter", function() {
+
+ beforeEach(inject(function(rowFilterFilter) {
+ filter = rowFilterFilter;
+ }));
+
+ it('returns item if field is falsy', function() {
+ expect(filter({ hi: 'there' }, false)).toEqual({ hi: 'there' });
+ });
+
+ it('returns items only where field property is falsy', function() {
+ var items = [
+ {hi: 'there'},
+ {},
+ {hi: true},
+ {hi: false}
+ ];
+ expect(filter(items, 'hi')).toEqual([{}, {hi: false}]);
+ });
+
+ });
+
+ describe("foundText", function() {
+
+ beforeEach(inject(function(foundTextFilter) {
+ filter = foundTextFilter;
+ }));
+
+ it('returns expected text', function() {
+ var items = [1,2,3];
+ expect(filter(items, 6)).toBe('Found 3 of 6');
+ });
+
+ });
+
+ });
+
describe('transfer-table directive', function() {
var $scope, $timeout, $element;
@@ -193,4 +265,4 @@
});
});
});
-})(); \ No newline at end of file
+})();
diff --git a/horizon/templates/horizon/_scripts.html b/horizon/templates/horizon/_scripts.html
index e53d28488..18dbe1155 100644
--- a/horizon/templates/horizon/_scripts.html
+++ b/horizon/templates/horizon/_scripts.html
@@ -46,7 +46,7 @@
<script src='{{ STATIC_URL }}angular/table/basic-table.js'></script>
<script src="{{ STATIC_URL }}angular/login/login.js"></script>
<script src='{{ STATIC_URL }}angular/modal/modal.js'></script>
-<script src='{{ STATIC_URL }}angular/modal-wait-spinner/modal-wait-spinner.js'></script>
+<script src='{{ STATIC_URL }}angular/modal/modal-wait-spinner.js'></script>
<script src='{{ STATIC_URL }}angular/bind-scope/bind-scope.js'></script>
<script src='{{ STATIC_URL }}angular/transfer-table/transfer-table.js'></script>
<script src='{{ STATIC_URL }}angular/charts/charts.js'></script>
diff --git a/horizon/templates/horizon/jasmine/jasmine.html b/horizon/templates/horizon/jasmine/jasmine.html
index 2c5338c58..74f60d52c 100644
--- a/horizon/templates/horizon/jasmine/jasmine.html
+++ b/horizon/templates/horizon/jasmine/jasmine.html
@@ -10,6 +10,8 @@
<script src="{{ STATIC_URL }}horizon/lib/jasmine/jasmine-html.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/jasmine/boot.js"></script>
<script src='{{ STATIC_URL }}horizon/lib/jquery/jquery.js'></script>
+ <script src='{{ STATIC_URL }}horizon/lib/spin.js'></script>
+ <script src='{{ STATIC_URL }}horizon/lib/spin.jquery.js'></script>
<script src="{{ STATIC_URL }}horizon/lib/angular/angular.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/angular/angular-mocks.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/angular/angular-cookies.js"></script>
diff --git a/horizon/test/jasmine/jasmine_tests.py b/horizon/test/jasmine/jasmine_tests.py
index f97bf15f7..01f41a2ce 100644
--- a/horizon/test/jasmine/jasmine_tests.py
+++ b/horizon/test/jasmine/jasmine_tests.py
@@ -35,7 +35,7 @@ class ServicesTests(test.JasmineTests):
'angular/metadata-tree/metadata-tree.js',
'angular/metadata-tree/metadata-tree-service.js',
'angular/modal/modal.js',
- 'angular/modal-wait-spinner/modal-wait-spinner.js',
+ 'angular/modal/modal-wait-spinner.js',
'angular/table/table.js',
'angular/table/basic-table.js',
'angular/transfer-table/transfer-table.js',
@@ -54,7 +54,8 @@ class ServicesTests(test.JasmineTests):
'angular/form/form.spec.js',
'angular/help-panel/help-panel.spec.js',
'angular/login/login.spec.js',
- 'angular/modal/simple-modal.spec.js',
+ 'angular/modal/modal.spec.js',
+ 'angular/modal/modal-wait-spinner.spec.js',
'angular/table/table.spec.js',
'angular/table/basic-table.spec.js',
'angular/transfer-table/transfer-table.spec.js',