OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/karma/tests/dialogs/sorting-modal-test.js

130 lines
3.9 KiB

//-- 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.
//++
/*jshint expr: true*/
describe('sortingModal', function() {
var $rootScope, scope;
var ctrl, buildController;
var QueryService, $httpBackend;
var columns = [
{ name: 'parent', title: 'Parent', sortable: true },
{ name: 'cheese', title: 'Cheesy column', sortable: true },
{ name: 'cake', title: 'Cake', sortable: true }
];
beforeEach(module('openproject.workPackages.controllers',
'openproject.services',
'openproject.models'));
beforeEach(inject(function($rootScope, $controller, $timeout, $filter, Sortation) {
scope = $rootScope.$new();
scope.sortElements = [];
buildController = function() {
ctrl = $controller('SortingModalController', {
$scope: scope,
sortingModal: {},
I18n: { t: angular.noop },
$filter: $filter,
QueryService: {
loadAvailableColumns: function() {
return $timeout(function() {
return columns;
});
},
getSortation: function() {
return new Sortation();
}
}
});
$timeout.flush();
};
}));
describe('initialisation', function() {
it('should initialise', function() {
buildController();
});
});
describe('setup', function() {
beforeEach(function() {
buildController();
});
it('formats the columns for select2', function() {
expect(scope.availableColumnsData).to.deep.equal([
{id: 'parent', label: 'Parent', other: 'Parent'},
{id: 'cheese', label: 'Cheesy column', other: 'Cheesy column'},
{id: 'cake', label: 'Cake', other: 'Cake'}
]);
});
});
describe('when a column is not sortable', function() {
var unsortableColumn = { name: 'author', title: 'Author' };
beforeEach(function() {
columns.push(unsortableColumn);
buildController();
});
it('is not contained by the available columns data', function() {
expect(scope.availableColumnsData).to.not.contain({id: 'author', label: 'Author', other: 'Author'});
});
});
describe('when a sort element has been selected', function() {
var selectableColumns;
beforeEach(function() {
scope.sortElements = [
[
{ id: 'parent', label: 'Parent', other: 'Parent' },
{ id: 'desc', label: 'Descending' }
]
];
buildController();
selectableColumns = scope.getAvailableColumnsData(undefined, angular.identity);
});
it('subtracts the sort elements from the selectable sort options', function() {
expect(selectableColumns).to.have.length(2);
expect(selectableColumns).to.not.contain(scope.availableColumnsData[0]);
});
});
});