diff --git a/app/assets/javascripts/angular/directives/work_packages/options-dropdown-directive.js b/app/assets/javascripts/angular/directives/work_packages/options-dropdown-directive.js index 38648544e5..af4af5de86 100644 --- a/app/assets/javascripts/angular/directives/work_packages/options-dropdown-directive.js +++ b/app/assets/javascripts/angular/directives/work_packages/options-dropdown-directive.js @@ -63,8 +63,8 @@ angular.module('openproject.workPackages.directives') } }; - scope.deleteQuery = function(){ - if( deleteConfirmed() ){ + scope.deleteQuery = function(event){ + if( preventDisabledAction(event) && deleteConfirmed() ){ QueryService.deleteQuery() .then(function(data){ settingsModal.deactivate(); diff --git a/karma.conf.js b/karma.conf.js index 806d7c000e..0c0e54335c 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -92,6 +92,13 @@ module.exports = function(config) { "app/assets/javascripts/angular/controllers/timelines-controller.js", "app/assets/javascripts/angular/controllers/work-packages-controller.js", "app/assets/javascripts/angular/controllers/work-package-details-controller.js", + "app/assets/javascripts/angular/controllers/dialogs/columns.js", + "app/assets/javascripts/angular/controllers/dialogs/export.js", + "app/assets/javascripts/angular/controllers/dialogs/group-by.js", + "app/assets/javascripts/angular/controllers/dialogs/save.js", + "app/assets/javascripts/angular/controllers/dialogs/settings.js", + "app/assets/javascripts/angular/controllers/dialogs/share.js", + "app/assets/javascripts/angular/controllers/dialogs/sorting.js", 'app/assets/javascripts/date-en-US.js', diff --git a/karma/tests/directives/work_packages/options-dropdown-directive-test.js b/karma/tests/directives/work_packages/options-dropdown-directive-test.js new file mode 100644 index 0000000000..9538872983 --- /dev/null +++ b/karma/tests/directives/work_packages/options-dropdown-directive-test.js @@ -0,0 +1,104 @@ +//-- copyright +// OpenProject is a project management system. +// Copyright (C) 2012-2014 the OpenProject Foundation (OPF) +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See doc/COPYRIGHT.rdoc for more details. +//++ + +describe('optionsDropdown Directive', function() { + var compile, element, rootScope, scope; + + beforeEach(angular.mock.module('openproject.workPackages.directives')); + beforeEach(module('templates', 'openproject.models', 'openproject.workPackages.controllers')); + + beforeEach(inject(function($rootScope, $compile) { + var optionsDropdownHtml; + optionsDropdownHtml = '
'; + + element = angular.element(optionsDropdownHtml); + rootScope = $rootScope; + scope = $rootScope.$new(); + + compile = function() { + $compile(element)(scope); + scope.$digest(); + }; + })); + + describe('element', function() { + + it('should render a div', function() { + expect(element.prop('tagName')).to.equal('DIV'); + }); + + describe('inactive options', function(){ + beforeEach(function(){ + var query = new Query({ + }); + scope.query = query; + + compile(); + }); + + it('should have an inactive save as option', function() { + var saveAsLink = element.find('a').first(); + expect(saveAsLink.hasClass('inactive')).to.be.ok; + }); + + it('should not open save as modal', function() { + var saveAsLink = element.find('a').first(); + saveAsLink.click(); + + expect(jQuery('.ng-modal-window').length).to.equal(0); + }); + + }); + + describe('active options', function(){ + beforeEach(function(){ + var query = new Query({ + id: 1 + }); + scope.query = query; + + compile(); + }) + + it('should have an active save as option', function() { + var saveAsLink = element.find('a').first(); + expect(saveAsLink.hasClass('inactive')).to.not.be.ok; + }); + + it('should open save as modal', function() { + var saveAsLink = element.find('a').first(); + saveAsLink.click(); + + expect(jQuery('.ng-modal-window').length).to.equal(1); + var modal = jQuery(jQuery('.ng-modal-window')[0]); + expect(modal.find('h3').text()).to.equal('Save as'); + }); + }); + + }); +});