From 7da464ff49197efd3bda86f0cf4c80ef22535034 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 6 Oct 2014 15:56:07 +0200 Subject: [PATCH 1/4] Refactoring --- .../components/toggled-multiselect-directive-test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/karma/tests/directives/components/toggled-multiselect-directive-test.js b/karma/tests/directives/components/toggled-multiselect-directive-test.js index 564b2ad979..34e1d9bb0d 100644 --- a/karma/tests/directives/components/toggled-multiselect-directive-test.js +++ b/karma/tests/directives/components/toggled-multiselect-directive-test.js @@ -41,8 +41,7 @@ describe('toggledMultiselect Directive', function() { })); beforeEach(inject(function($rootScope, $compile) { - var html; - html = ''; + var html = ''; element = angular.element(html); rootScope = $rootScope; From 776ba10bca48c9b56c3b47044d42000fb6522b59 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 6 Oct 2014 15:59:45 +0200 Subject: [PATCH 2/4] Add scope for existing tests --- .../toggled-multiselect-directive-test.js | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/karma/tests/directives/components/toggled-multiselect-directive-test.js b/karma/tests/directives/components/toggled-multiselect-directive-test.js index 34e1d9bb0d..7b8470dd78 100644 --- a/karma/tests/directives/components/toggled-multiselect-directive-test.js +++ b/karma/tests/directives/components/toggled-multiselect-directive-test.js @@ -53,7 +53,7 @@ describe('toggledMultiselect Directive', function() { }; })); - describe('element', function() { + describe('with values', function() { beforeEach(function() { scope.name = "BO' SELECTA"; scope.values = [ @@ -67,30 +67,32 @@ describe('toggledMultiselect Directive', function() { compile(); }); - it('should render a div', function() { - expect(element.prop('tagName')).to.equal('DIV'); - }); + describe('element', function() { + it('should render a div', function() { + expect(element.prop('tagName')).to.equal('DIV'); + }); - it('should render only one select', function() { - expect(element.find('select').size()).to.equal(1); - expect(element.find('select.ng-hide').size()).to.equal(0); - }); + it('should render only one select', function() { + expect(element.find('select').size()).to.equal(1); + expect(element.find('select.ng-hide').size()).to.equal(0); + }); - it('should render two OPTIONs for displayed SELECT', function() { - var select = element.find('select:not(.ng-hide)').first(); - expect(select.find('option').size()).to.equal(2); + it('should render two OPTIONs for displayed SELECT', function() { + var select = element.find('select:not(.ng-hide)').first(); + expect(select.find('option').size()).to.equal(2); - var option = select.find('option').first(); - expect(option.val()).to.equal('NY'); - expect(option.text()).to.equal('New York'); - }); + var option = select.find('option').first(); + expect(option.val()).to.equal('NY'); + expect(option.text()).to.equal('New York'); + }); - xit('should render a link that toggles multi-select', function() { - var a = element.find('a'); - expect(element.find('select.ng-hide').size()).to.equal(1); - a.click(); - scope.$apply(); - expect(element.find('select.ng-hide').size()).to.equal(1); + xit('should render a link that toggles multi-select', function() { + var a = element.find('a'); + expect(element.find('select.ng-hide').size()).to.equal(1); + a.click(); + scope.$apply(); + expect(element.find('select.ng-hide').size()).to.equal(1); + }); }); }); }); From 39a7929cb24717caf6396aadc02708a7b90cf823 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 6 Oct 2014 16:00:41 +0200 Subject: [PATCH 3/4] Test handling of empty value selection --- .../toggled-multiselect-directive-test.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/karma/tests/directives/components/toggled-multiselect-directive-test.js b/karma/tests/directives/components/toggled-multiselect-directive-test.js index 7b8470dd78..5727f3cd6b 100644 --- a/karma/tests/directives/components/toggled-multiselect-directive-test.js +++ b/karma/tests/directives/components/toggled-multiselect-directive-test.js @@ -95,4 +95,29 @@ describe('toggledMultiselect Directive', function() { }); }); }); + + describe('w/o values', function() { + beforeEach(function() { + scope.name = "BO' SELECTA"; + scope.options = [ + ['New York', 'NY'], + ['California', 'CA'] + ]; + + compile(); + + var multiselectToggleElement = element.find('a'); + multiselectToggleElement.trigger('click'); + }); + + describe('scope.values', function() { + it('should not become an array', function() { + expect(Array.isArray(scope.values)).to.be.false; + }); + + it('should leave scope.values as undefined', function() { + expect(scope.values).to.be.undefined; + }); + }); + }); }); From eb5ef9633ea2d09f2ff67a39132d4a0a716653fc Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 6 Oct 2014 16:01:13 +0200 Subject: [PATCH 4/4] Don't create array with single undefined element --- .../directives/components/toggled-multiselect-directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/angular/directives/components/toggled-multiselect-directive.js b/app/assets/javascripts/angular/directives/components/toggled-multiselect-directive.js index 50da0ab5b6..c314be4a9f 100644 --- a/app/assets/javascripts/angular/directives/components/toggled-multiselect-directive.js +++ b/app/assets/javascripts/angular/directives/components/toggled-multiselect-directive.js @@ -50,7 +50,7 @@ angular.module('openproject.uiComponents') function switchToMultiSelect() { scope.isMultiselect = true; - if (!Array.isArray(scope.values)) { + if (scope.values && !Array.isArray(scope.values)) { scope.values = [scope.values]; } }