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.
259 lines
8.1 KiB
259 lines
8.1 KiB
10 years ago
|
//-- 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.
|
||
|
//++
|
||
|
|
||
10 years ago
|
describe('Work Package Relations Directive', function() {
|
||
10 years ago
|
var I18n, PathHelper, compile, element, scope;
|
||
10 years ago
|
|
||
10 years ago
|
beforeEach(angular.mock.module('openproject.workPackages.tabs', 'openproject.api', 'openproject.helpers', 'ngSanitize'));
|
||
10 years ago
|
beforeEach(module('templates', function($provide) {
|
||
|
}));
|
||
|
|
||
10 years ago
|
beforeEach(inject(function($rootScope, $compile, _I18n_, _PathHelper_) {
|
||
10 years ago
|
scope = $rootScope.$new();
|
||
|
|
||
|
compile = function(html) {
|
||
|
element = $compile(html)(scope);
|
||
|
scope.$digest();
|
||
|
};
|
||
|
|
||
|
I18n = _I18n_;
|
||
10 years ago
|
PathHelper = _PathHelper_;
|
||
10 years ago
|
|
||
|
var stub = sinon.stub(I18n, 't');
|
||
|
|
||
|
stub.withArgs('js.work_packages.properties.subject').returns('Column0');
|
||
|
stub.withArgs('js.work_packages.properties.status').returns('Column1');
|
||
|
stub.withArgs('js.work_packages.properties.assignee').returns('Column2');
|
||
|
}));
|
||
|
|
||
|
afterEach(function() {
|
||
|
I18n.t.restore();
|
||
|
});
|
||
|
|
||
10 years ago
|
var multiElementHtml = "<work-package-relations title='MyRelation' work-package='workPackage' relations='relations' button-title='Add Relation' button-icon='%MyIcon%'></work-package-relation>"
|
||
|
var singleElementHtml = "<work-package-relations title='MyRelation' work-package='workPackage' relations='relations' button-title='Add Relation' button-icon='%MyIcon%' singleton-relation='true'></work-package-relation>"
|
||
10 years ago
|
|
||
10 years ago
|
|
||
|
var workPackage1;
|
||
|
var workPackage2;
|
||
10 years ago
|
|
||
10 years ago
|
beforeEach(inject(function($q) {
|
||
10 years ago
|
workPackage1 = {
|
||
|
props: {
|
||
|
id: "1",
|
||
|
subject: "Subject 1",
|
||
|
status: "Status 1"
|
||
|
},
|
||
|
embedded: {
|
||
|
assignee: {
|
||
|
props: {
|
||
10 years ago
|
name: "Assignee 1",
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
},
|
||
|
links: {
|
||
|
self: { href: "/work_packages/1" }
|
||
10 years ago
|
}
|
||
|
};
|
||
|
workPackage2 = {
|
||
|
props: {
|
||
|
id: "2",
|
||
|
subject: "Subject 2",
|
||
|
status: "Status 2"
|
||
|
},
|
||
|
embedded: {
|
||
|
assignee: {
|
||
|
props: {
|
||
10 years ago
|
name: "Assignee 2",
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
},
|
||
|
links: {
|
||
|
self: { href: "/work_packages/1" }
|
||
10 years ago
|
}
|
||
|
};
|
||
10 years ago
|
relation1 = {
|
||
|
links: {
|
||
|
self: { href: "/work_packages/1" },
|
||
|
relatedTo: {
|
||
|
href: "/work_packages/1",
|
||
|
fetch: function() {
|
||
|
$q.when(function() { return { props: { id: 1 }}; } )
|
||
|
}
|
||
|
},
|
||
|
relatedFrom: {
|
||
|
href: "/work_packages/2",
|
||
|
fetch: function() {
|
||
|
$q.when(function() { return { props: { id: 2 }}; } )
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}));
|
||
10 years ago
|
|
||
10 years ago
|
var shouldBehaveLikeRelationsDirective = function() {
|
||
10 years ago
|
it('should have a title', function() {
|
||
|
var title = angular.element(element.find('h3'));
|
||
|
|
||
|
expect(title.text()).to.include('MyRelation');
|
||
|
});
|
||
|
|
||
10 years ago
|
//it('should have a button', function() {
|
||
|
// var button = angular.element(element.find('button.button'));
|
||
10 years ago
|
|
||
10 years ago
|
// expect(button.attr('title')).to.include('Add Relation');
|
||
|
// expect(button.text()).to.include('Add Relation');
|
||
|
// expect(button.text()).to.include('%MyIcon%');
|
||
|
//});
|
||
10 years ago
|
};
|
||
|
|
||
|
var shouldBehaveLikeHasTableHeader = function() {
|
||
|
it('should have a table head', function() {
|
||
|
var column0 = angular.element(element.find('.workpackages table thead td:nth-child(1)'));
|
||
|
var column1 = angular.element(element.find('.workpackages table thead td:nth-child(2)'));
|
||
|
var column2 = angular.element(element.find('.workpackages table thead td:nth-child(3)'));
|
||
|
|
||
|
expect(angular.element(column0).text()).to.eq(I18n.t('js.work_packages.properties.subject'));
|
||
|
expect(angular.element(column1).text()).to.eq(I18n.t('js.work_packages.properties.status'));
|
||
|
expect(angular.element(column2).text()).to.eq(I18n.t('js.work_packages.properties.assignee'));
|
||
|
});
|
||
|
};
|
||
|
|
||
|
var shouldBehaveLikeHasTableContent = function(count) {
|
||
|
it('should have table content', function() {
|
||
|
for (var x = 1; x <= count; x++) {
|
||
|
var column0 = angular.element(element.find('.workpackages table tbody:nth-of-type(' + x + ') tr td:nth-child(1)'));
|
||
|
var column1 = angular.element(element.find('.workpackages table tbody:nth-of-type(' + x + ') tr td:nth-child(2)'));
|
||
|
var column2 = angular.element(element.find('.workpackages table tbody:nth-of-type(' + x + ') tr td:nth-child(3)'));
|
||
|
|
||
10 years ago
|
expect(angular.element(column0).text()).to.include('Subject ' + x);
|
||
|
expect(angular.element(column1).text()).to.include('Status ' + x);
|
||
|
expect(angular.element(column2).text()).to.include('Assignee ' + x);
|
||
10 years ago
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
var shouldBehaveLikeCollapsedRelationsDirective = function() {
|
||
|
|
||
10 years ago
|
shouldBehaveLikeRelationsDirective();
|
||
10 years ago
|
|
||
|
it('should be initially collapsed', function() {
|
||
|
var content = angular.element(element.find('div.content'));
|
||
|
expect(content.hasClass('ng-hide')).to.eq(true);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
var shouldBehaveLikeExpandedRelationsDirective = function() {
|
||
|
|
||
10 years ago
|
shouldBehaveLikeRelationsDirective();
|
||
10 years ago
|
|
||
|
it('should be initially expanded', function() {
|
||
|
var content = angular.element(element.find('div.content'));
|
||
|
expect(content.hasClass('ng-hide')).to.eq(false);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
var shouldBehaveLikeSingleRelationDirective = function() {
|
||
|
it('should not have an elements count', function() {
|
||
|
var title = angular.element(element.find('h3'));
|
||
|
|
||
|
expect(title.text()).not.to.include('(');
|
||
|
expect(title.text()).not.to.include(')');
|
||
|
});
|
||
|
};
|
||
|
|
||
|
var shouldBehaveLikeMultiRelationDirective = function() {
|
||
|
it('should have an elements count', function() {
|
||
|
var title = angular.element(element.find('h3'));
|
||
|
|
||
|
expect(title.text()).to.include('(' + scope.relations.length + ')');
|
||
|
});
|
||
|
};
|
||
|
|
||
|
describe('no element markup', function() {
|
||
10 years ago
|
describe('single element behavior', function() {
|
||
|
beforeEach(function() {
|
||
|
compile(singleElementHtml);
|
||
|
});
|
||
|
|
||
|
shouldBehaveLikeSingleRelationDirective();
|
||
|
|
||
|
shouldBehaveLikeCollapsedRelationsDirective();
|
||
10 years ago
|
});
|
||
|
|
||
10 years ago
|
describe('multi element behavior', function() {
|
||
|
beforeEach(function() {
|
||
|
scope.relations = [];
|
||
|
|
||
|
compile(multiElementHtml);
|
||
|
});
|
||
10 years ago
|
|
||
10 years ago
|
shouldBehaveLikeMultiRelationDirective();
|
||
|
|
||
|
shouldBehaveLikeCollapsedRelationsDirective();
|
||
|
});
|
||
10 years ago
|
});
|
||
|
|
||
|
describe('single element markup', function() {
|
||
|
beforeEach(function() {
|
||
10 years ago
|
scope.workPackage = workPackage2;
|
||
|
scope.relations = [relation1];
|
||
10 years ago
|
|
||
10 years ago
|
compile(singleElementHtml);
|
||
10 years ago
|
});
|
||
|
|
||
10 years ago
|
shouldBehaveLikeRelationsDirective();
|
||
10 years ago
|
|
||
|
shouldBehaveLikeSingleRelationDirective();
|
||
|
|
||
|
shouldBehaveLikeExpandedRelationsDirective();
|
||
|
|
||
|
shouldBehaveLikeHasTableHeader();
|
||
|
|
||
|
shouldBehaveLikeHasTableContent(1);
|
||
|
});
|
||
|
|
||
10 years ago
|
// describe('multi element markup', function() {
|
||
|
// beforeEach(function() {
|
||
|
// scope.relations = [workPackage1, workPackage2];
|
||
10 years ago
|
|
||
10 years ago
|
// compile(multiElementHtml);
|
||
|
// });
|
||
10 years ago
|
|
||
10 years ago
|
// shouldBehaveLikeRelationsDirective();
|
||
10 years ago
|
|
||
10 years ago
|
// shouldBehaveLikeMultiRelationDirective();
|
||
10 years ago
|
|
||
10 years ago
|
// shouldBehaveLikeExpandedRelationsDirective();
|
||
10 years ago
|
|
||
10 years ago
|
// shouldBehaveLikeHasTableHeader();
|
||
10 years ago
|
|
||
10 years ago
|
// shouldBehaveLikeHasTableContent(2);
|
||
|
// });
|
||
10 years ago
|
});
|