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.
336 lines
10 KiB
336 lines
10 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('DetailsTabOverviewController', function() {
|
|
var scope;
|
|
var buildController;
|
|
var I18n = { t: angular.identity },
|
|
WorkPackagesHelper = {
|
|
formatWorkPackageProperty: angular.identity
|
|
},
|
|
UserService = {
|
|
getUser: angular.identity
|
|
},
|
|
CustomFieldHelper = {
|
|
formatCustomFieldValue: angular.identity
|
|
},
|
|
workPackage = {
|
|
props: {
|
|
status: 'open',
|
|
versionName: null,
|
|
percentageDone: 0,
|
|
estimatedTime: undefined,
|
|
customProperties: [
|
|
{ format: 'text', name: 'color', value: 'red' },
|
|
]
|
|
},
|
|
embedded: {
|
|
activities: [],
|
|
watchers: [],
|
|
attachments: []
|
|
},
|
|
};
|
|
|
|
function buildWorkPackageWithId(id) {
|
|
angular.extend(workPackage.props, {id: id});
|
|
return workPackage;
|
|
}
|
|
|
|
beforeEach(module('openproject.api',
|
|
'openproject.services',
|
|
'openproject.config',
|
|
'openproject.workPackages.controllers'));
|
|
|
|
beforeEach(inject(function($rootScope, $controller, $timeout) {
|
|
var workPackageId = 99;
|
|
|
|
buildController = function() {
|
|
scope = $rootScope.$new();
|
|
scope.workPackage = workPackage;
|
|
|
|
ctrl = $controller("DetailsTabOverviewController", {
|
|
$scope: scope,
|
|
I18n: I18n,
|
|
UserService: UserService,
|
|
CustomFieldHelper: CustomFieldHelper,
|
|
});
|
|
|
|
$timeout.flush();
|
|
};
|
|
|
|
}));
|
|
|
|
describe('initialisation', function() {
|
|
it('should initialise', function() {
|
|
buildController();
|
|
});
|
|
});
|
|
|
|
describe('work package properties', function() {
|
|
function fetchPresentPropertiesWithName(propertyName) {
|
|
return scope.presentWorkPackageProperties.filter(function(propertyData) {
|
|
return propertyData.property === propertyName;
|
|
});
|
|
}
|
|
|
|
function fetchEmptyPropertiesWithName(propertyName) {
|
|
return scope.emptyWorkPackageProperties.filter(function(propertyData) {
|
|
return propertyData.property === propertyName;
|
|
});
|
|
}
|
|
|
|
var shouldBehaveLikePropertyWithValue = function(propertyName) {
|
|
it('adds property to present properties', function() {
|
|
expect(fetchPresentPropertiesWithName(propertyName)).to.have.length(1);
|
|
});
|
|
}
|
|
|
|
var shouldBehaveLikePropertyWithNoValue = function(propertyName) {
|
|
it('adds property to present properties', function() {
|
|
expect(fetchEmptyPropertiesWithName(propertyName)).to.have.length(1);
|
|
});
|
|
}
|
|
|
|
describe('when the property has a value', function() {
|
|
beforeEach(function() {
|
|
buildController();
|
|
});
|
|
|
|
describe('status', function() {
|
|
var propertyName = 'status';
|
|
|
|
shouldBehaveLikePropertyWithValue(propertyName);
|
|
});
|
|
|
|
describe('percentage done', function() {
|
|
var propertyName = 'percentageDone';
|
|
|
|
shouldBehaveLikePropertyWithValue(propertyName);
|
|
});
|
|
});
|
|
|
|
describe('when the property has NO value', function() {
|
|
beforeEach(function() {
|
|
buildController();
|
|
});
|
|
|
|
describe('estimated Time', function() {
|
|
var propertyName = 'estimatedTime';
|
|
|
|
});
|
|
});
|
|
|
|
describe('when the property is among the first 3 properties', function() {
|
|
var propertyName = 'responsible';
|
|
|
|
beforeEach(function() {
|
|
buildController();
|
|
});
|
|
|
|
it('is added to present properties even if it is empty', function() {
|
|
expect(fetchPresentPropertiesWithName(propertyName)).to.have.length(1);
|
|
});
|
|
});
|
|
|
|
describe('when the property is among the second group of 3 properties', function() {
|
|
var propertyName = 'priority',
|
|
label = 'Priority';
|
|
|
|
beforeEach(function() {
|
|
sinon.stub(I18n, 't')
|
|
.withArgs('js.work_packages.properties.' + propertyName)
|
|
.returns(label);
|
|
|
|
buildController();
|
|
});
|
|
|
|
afterEach(function() {
|
|
I18n.t.restore();
|
|
});
|
|
|
|
describe('and none of these 3 properties is present', function() {
|
|
beforeEach(function() {
|
|
buildController();
|
|
});
|
|
|
|
it('is added to the empty properties', function() {
|
|
expect(scope.emptyWorkPackageProperties.indexOf(label)).to.be.greaterThan(-1);
|
|
});
|
|
});
|
|
|
|
describe('and at least one of these 3 properties is present', function() {
|
|
beforeEach(function() {
|
|
workPackage.props.percentageDone = '20';
|
|
buildController();
|
|
});
|
|
|
|
it('is added to the present properties', function() {
|
|
expect(fetchPresentPropertiesWithName(propertyName)).to.have.length(1);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when the property is not among the first 6 properties', function() {
|
|
var propertyName = 'versionName',
|
|
label = 'Version';
|
|
|
|
beforeEach(function() {
|
|
sinon.stub(I18n, 't')
|
|
.withArgs('js.work_packages.properties.' + propertyName)
|
|
.returns(label);
|
|
|
|
buildController();
|
|
});
|
|
|
|
afterEach(function() {
|
|
I18n.t.restore();
|
|
});
|
|
|
|
it('adds properties that without values to empty properties', function() {
|
|
expect(scope.emptyWorkPackageProperties.indexOf(label)).to.be.greaterThan(-1);
|
|
});
|
|
});
|
|
|
|
describe('date property', function() {
|
|
var startDate = '2014-07-09',
|
|
dueDate = '2014-07-10',
|
|
placeholder = 'placeholder';
|
|
|
|
|
|
describe('when only the due date is present', function() {
|
|
beforeEach(function() {
|
|
sinon.stub(I18n, 't')
|
|
.withArgs('js.label_no_start_date')
|
|
.returns(placeholder);
|
|
|
|
workPackage.props.startDate = null;
|
|
workPackage.props.dueDate = dueDate;
|
|
|
|
buildController();
|
|
});
|
|
|
|
afterEach(function() {
|
|
I18n.t.restore();
|
|
});
|
|
|
|
it('renders the due date and a placeholder for the start date as date property', function() {
|
|
expect(fetchPresentPropertiesWithName('date')[0].value).to.equal(placeholder + ' - 07/10/2014');
|
|
});
|
|
});
|
|
|
|
describe('when only the start date is present', function() {
|
|
beforeEach(function() {
|
|
sinon.stub(I18n, 't')
|
|
.withArgs('js.label_no_due_date')
|
|
.returns(placeholder);
|
|
|
|
workPackage.props.startDate = startDate;
|
|
workPackage.props.dueDate = null;
|
|
|
|
buildController();
|
|
});
|
|
|
|
afterEach(function() {
|
|
I18n.t.restore();
|
|
});
|
|
|
|
it('renders the start date and a placeholder for the due date as date property', function() {
|
|
expect(fetchPresentPropertiesWithName('date')[0].value).to.equal('07/09/2014 - ' + placeholder);
|
|
});
|
|
});
|
|
|
|
describe('when both - start and due date are present', function() {
|
|
beforeEach(function() {
|
|
workPackage.props.startDate = startDate;
|
|
workPackage.props.dueDate = dueDate;
|
|
|
|
buildController();
|
|
});
|
|
|
|
it('combines them and renders them as date property', function() {
|
|
expect(fetchPresentPropertiesWithName('date')[0].value).to.equal('07/09/2014 - 07/10/2014');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('custom field properties', function() {
|
|
var customPropertyName = 'color';
|
|
|
|
describe('when the property has a value', function() {
|
|
beforeEach(function() {
|
|
formatCustomFieldValueSpy = sinon.spy(CustomFieldHelper, 'formatCustomFieldValue');
|
|
|
|
buildController();
|
|
});
|
|
|
|
afterEach(function() {
|
|
CustomFieldHelper.formatCustomFieldValue.restore();
|
|
});
|
|
|
|
it('adds properties to present properties', function() {
|
|
expect(fetchPresentPropertiesWithName(customPropertyName)).to.have.length(1);
|
|
});
|
|
|
|
it('formats values using the custom field helper', function() {
|
|
expect(CustomFieldHelper.formatCustomFieldValue.calledWith('red', 'text')).to.be.true;
|
|
});
|
|
});
|
|
|
|
describe('when the property does not have a value', function() {
|
|
beforeEach(function() {
|
|
workPackage.props.customProperties[0].value = null;
|
|
buildController();
|
|
});
|
|
|
|
it('adds the custom property to empty properties', function() {
|
|
expect(scope.emptyWorkPackageProperties.indexOf(customPropertyName)).to.be.greaterThan(-1);
|
|
});
|
|
});
|
|
|
|
describe('user custom property', function() {
|
|
var userId = '1';
|
|
|
|
beforeEach(function() {
|
|
workPackage.props.customProperties[0].value = userId;
|
|
workPackage.props.customProperties[0].format = 'user';
|
|
|
|
getUserSpy = sinon.spy(UserService, 'getUser');
|
|
buildController();
|
|
});
|
|
|
|
it('fetches the user using the user service', function() {
|
|
expect(UserService.getUser.calledWith(userId)).to.be.true;
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
});
|
|
|