kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
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.
125 lines
3.7 KiB
125 lines
3.7 KiB
9 years ago
|
//-- copyright
|
||
|
// OpenProject is a project management system.
|
||
|
// Copyright (C) 2012-2015 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('WorkPackageAttachmentsDirective', function() {
|
||
9 years ago
|
var compile;
|
||
|
var element;
|
||
|
var rootScope;
|
||
|
var scope;
|
||
|
var isolatedScope;
|
||
|
var workPackage = {$links: {}};
|
||
9 years ago
|
|
||
|
beforeEach(angular.mock.module('openproject.workPackages.directives'));
|
||
9 years ago
|
beforeEach(angular.mock.module('openproject.templates'));
|
||
9 years ago
|
|
||
|
var loadPromise,
|
||
|
workPackageAttachmentsService = {
|
||
|
load: function() {
|
||
|
return loadPromise;
|
||
9 years ago
|
},
|
||
|
upload: angular.noop
|
||
9 years ago
|
},
|
||
|
apiPromise,
|
||
|
configurationService = {
|
||
|
api: function() {
|
||
|
return apiPromise;
|
||
|
}
|
||
|
};
|
||
|
|
||
9 years ago
|
beforeEach(angular.mock.module('openproject.workPackages.services', function($provide) {
|
||
9 years ago
|
$provide.constant('WorkPackageAttachmentsService', workPackageAttachmentsService);
|
||
|
}));
|
||
|
|
||
9 years ago
|
beforeEach(angular.mock.module('openproject.config', function($provide) {
|
||
9 years ago
|
$provide.constant('ConfigurationService', configurationService);
|
||
|
}));
|
||
|
|
||
9 years ago
|
beforeEach(angular.mock.inject(function($rootScope, $compile, $q) {
|
||
9 years ago
|
apiPromise = $q(function(resolve) {
|
||
|
return resolve('');
|
||
|
});
|
||
|
|
||
|
loadPromise = $q(function(resolve) {
|
||
|
return resolve([]);
|
||
|
});
|
||
|
|
||
9 years ago
|
var html = '<work-package-attachments edit work-package="workPackage">' +
|
||
|
'</work-package-attachments>';
|
||
9 years ago
|
|
||
|
element = angular.element(html);
|
||
|
rootScope = $rootScope;
|
||
|
scope = $rootScope.$new();
|
||
|
|
||
9 years ago
|
scope.workPackage = workPackage;
|
||
|
|
||
9 years ago
|
compile = function() {
|
||
|
$compile(element)(scope);
|
||
|
scope.$digest();
|
||
|
};
|
||
|
}));
|
||
|
|
||
9 years ago
|
describe('filterFiles', function() {
|
||
9 years ago
|
beforeEach(function() {
|
||
|
compile();
|
||
|
isolatedScope = element.isolateScope();
|
||
|
});
|
||
|
|
||
|
it('filters out attachments of type directory', function() {
|
||
9 years ago
|
var files = [{type: 'directory'}, {type: 'file'}];
|
||
|
|
||
|
isolatedScope.filterFiles(files, {}, {}, false);
|
||
9 years ago
|
|
||
|
expect(files).to.eql([{type: 'file'}]);
|
||
|
});
|
||
9 years ago
|
});
|
||
|
|
||
|
|
||
|
describe('uploadFilteredFiles', function() {
|
||
|
var files = [{type: 'directory'}, {type: 'file'}],
|
||
|
dumbPromise = {
|
||
|
then: function(call) { return call(); }
|
||
|
};
|
||
|
|
||
|
beforeEach(function() {
|
||
|
compile();
|
||
|
isolatedScope = element.isolateScope();
|
||
|
});
|
||
9 years ago
|
|
||
9 years ago
|
it('triggers uploading of non directory files', function() {
|
||
9 years ago
|
//need to have files to be able to trigger uploads
|
||
9 years ago
|
isolatedScope.files = files;
|
||
9 years ago
|
|
||
|
var uploadStub = workPackageAttachmentsService.upload = sinon.stub().returns(dumbPromise);
|
||
|
|
||
9 years ago
|
isolatedScope.uploadFilteredFiles(files, {}, {}, true);
|
||
9 years ago
|
|
||
9 years ago
|
expect(uploadStub.calledWith(workPackage, [{type: 'file'}])).to.be.true;
|
||
9 years ago
|
});
|
||
|
});
|
||
|
});
|