Mercurial > hg > soundsoftware-site
diff test/unit/lib/redmine/helpers/gantt_test.rb @ 119:8661b858af72
* Update to Redmine trunk rev 4705
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 14:12:06 +0000 |
parents | 40f7cfd4df19 |
children | cbce1fd3b1b7 |
line wrap: on
line diff
--- a/test/unit/lib/redmine/helpers/gantt_test.rb Fri Nov 19 14:05:24 2010 +0000 +++ b/test/unit/lib/redmine/helpers/gantt_test.rb Thu Jan 13 14:12:06 2011 +0000 @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.dirname(__FILE__) + '/../../../../test_helper' +require File.expand_path('../../../../../test_helper', __FILE__) class Redmine::Helpers::GanttTest < ActiveSupport::TestCase # Utility methods and classes so assert_select can be used. @@ -53,14 +53,14 @@ end # Creates a Gantt chart for a 4 week span - def create_gantt(project=Project.generate!) + def create_gantt(project=Project.generate!, options={}) @project = project - @gantt = Redmine::Helpers::Gantt.new + @gantt = Redmine::Helpers::Gantt.new(options) @gantt.project = @project @gantt.query = Query.generate_default!(:project => @project) @gantt.view = build_view - @gantt.instance_variable_set('@date_from', 2.weeks.ago.to_date) - @gantt.instance_variable_set('@date_to', 2.weeks.from_now.to_date) + @gantt.instance_variable_set('@date_from', options[:date_from] || 2.weeks.ago.to_date) + @gantt.instance_variable_set('@date_to', options[:date_to] || 2.weeks.from_now.to_date) end context "#number_of_rows" do @@ -73,6 +73,22 @@ should "return the total number of rows for all the projects, resursively" end + should "not exceed max_rows option" do + p = Project.generate! + 5.times do + Issue.generate_for_project!(p) + end + + create_gantt(p) + @gantt.render + assert_equal 6, @gantt.number_of_rows + assert !@gantt.truncated + + create_gantt(p, :max_rows => 3) + @gantt.render + assert_equal 3, @gantt.number_of_rows + assert @gantt.truncated + end end context "#number_of_rows_on_project" do @@ -142,39 +158,63 @@ :done_ratio => 30, :start_date => Date.yesterday, :due_date => 1.week.from_now.to_date) - @project.issues << @issue - - @response.body = @gantt.subjects + @project.issues << @issue end - + context "project" do should "be rendered" do + @response.body = @gantt.subjects assert_select "div.project-name a", /#{@project.name}/ end - + should "have an indent of 4" do + @response.body = @gantt.subjects assert_select "div.project-name[style*=left:4px]" end end - + context "version" do should "be rendered" do + @response.body = @gantt.subjects assert_select "div.version-name a", /#{@version.name}/ end - + should "be indented 24 (one level)" do + @response.body = @gantt.subjects assert_select "div.version-name[style*=left:24px]" end end - + context "issue" do should "be rendered" do + @response.body = @gantt.subjects assert_select "div.issue-subject", /#{@issue.subject}/ end - + should "be indented 44 (two levels)" do + @response.body = @gantt.subjects assert_select "div.issue-subject[style*=left:44px]" end + + context "with subtasks" do + setup do + attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version} + @child1 = Issue.generate!(attrs.merge(:subject => 'child1', :parent_issue_id => @issue.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date)) + @child2 = Issue.generate!(attrs.merge(:subject => 'child2', :parent_issue_id => @issue.id, :start_date => Date.today, :due_date => 1.week.from_now.to_date)) + @grandchild = Issue.generate!(attrs.merge(:subject => 'grandchild', :parent_issue_id => @child1.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date)) + end + + should "indent subtasks" do + @response.body = @gantt.subjects + # parent task 44px + assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/ + # children 64px + assert_select "div.issue-subject[style*=left:64px]", /child1/ + assert_select "div.issue-subject[style*=left:64px]", /child2/ + # grandchild 84px + assert_select "div.issue-subject[style*=left:84px]", /grandchild/, @response.body + end + end end end @@ -200,26 +240,26 @@ context "project" do should "be rendered" do - assert_select "div.project_todo" - assert_select "div.project-line.starting" - assert_select "div.project-line.ending" - assert_select "div.label.project-name", /#{@project.name}/ + assert_select "div.project.task_todo" + assert_select "div.project.starting" + assert_select "div.project.ending" + assert_select "div.label.project", /#{@project.name}/ end end context "version" do should "be rendered" do - assert_select "div.milestone_todo" - assert_select "div.milestone.starting" - assert_select "div.milestone.ending" - assert_select "div.label.version-name", /#{@version.name}/ + assert_select "div.version.task_todo" + assert_select "div.version.starting" + assert_select "div.version.ending" + assert_select "div.label.version", /#{@version.name}/ end end context "issue" do should "be rendered" do assert_select "div.task_todo" - assert_select "div.label.issue-name", /#{@issue.done_ratio}/ + assert_select "div.task.label", /#{@issue.done_ratio}/ assert_select "div.tooltip", /#{@issue.subject}/ end end @@ -294,7 +334,7 @@ :tracker => @tracker, :project => @project, :done_ratio => 30, - :start_date => Date.yesterday, + :start_date => 1.week.ago.to_date, :due_date => 1.week.from_now.to_date) end @@ -302,37 +342,37 @@ context "todo line" do should "start from the starting point on the left" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project_todo[style*=left:52px]" + assert_select "div.project.task_todo[style*=left:28px]", true, @response.body end should "be the total width of the project" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project_todo[style*=width:31px]" + assert_select "div.project.task_todo[style*=width:58px]", true, @response.body end end context "late line" do - should "start from the starting point on the left" do + should_eventually "start from the starting point on the left" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project_late[style*=left:52px]" + assert_select "div.project.task_late[style*=left:28px]", true, @response.body end - should "be the total delayed width of the project" do + should_eventually "be the total delayed width of the project" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project_late[style*=width:6px]" + assert_select "div.project.task_late[style*=width:30px]", true, @response.body end end context "done line" do - should "start from the starting point on the left" do + should_eventually "start from the starting point on the left" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project_done[style*=left:52px]" + assert_select "div.project.task_done[style*=left:28px]", true, @response.body end - should "Be the total done width of the project" do + should_eventually "Be the total done width of the project" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project_done[style*=left:52px]" + assert_select "div.project.task_done[style*=width:18px]", true, @response.body end end @@ -342,12 +382,12 @@ @gantt.instance_variable_set('@date_from', Date.today) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project-line.starting", false + assert_select "div.project.starting", false, @response.body end should "appear at the starting point" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project-line.starting[style*=left:52px]" + assert_select "div.project.starting[style*=left:28px]", true, @response.body end end @@ -357,13 +397,13 @@ @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project-line.ending", false + assert_select "div.project.ending", false, @response.body end should "appear at the end of the date range" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project-line.ending[style*=left:84px]" + assert_select "div.project.ending[style*=left:88px]", true, @response.body end end @@ -372,17 +412,17 @@ @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project-name", /#{@project.name}/ + assert_select "div.project.label", /#{@project.name}/ end should "show the project name" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project-name", /#{@project.name}/ + assert_select "div.project.label", /#{@project.name}/ end - should "show the percent complete" do + should_eventually "show the percent complete" do @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project-name", /0%/ + assert_select "div.project.label", /0%/ end end end @@ -461,7 +501,7 @@ :tracker => @tracker, :project => @project, :done_ratio => 30, - :start_date => Date.yesterday, + :start_date => 1.week.ago.to_date, :due_date => 1.week.from_now.to_date) end @@ -469,12 +509,12 @@ context "todo line" do should "start from the starting point on the left" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone_todo[style*=left:52px]" + assert_select "div.version.task_todo[style*=left:28px]", true, @response.body end should "be the total width of the version" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone_todo[style*=width:31px]" + assert_select "div.version.task_todo[style*=width:58px]", true, @response.body end end @@ -482,24 +522,24 @@ context "late line" do should "start from the starting point on the left" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone_late[style*=left:52px]" + assert_select "div.version.task_late[style*=left:28px]", true, @response.body end should "be the total delayed width of the version" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone_late[style*=width:6px]" + assert_select "div.version.task_late[style*=width:30px]", true, @response.body end end context "done line" do should "start from the starting point on the left" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone_done[style*=left:52px]" + assert_select "div.version.task_done[style*=left:28px]", true, @response.body end should "Be the total done width of the version" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone_done[style*=left:52px]" + assert_select "div.version.task_done[style*=width:18px]", true, @response.body end end @@ -509,12 +549,12 @@ @gantt.instance_variable_set('@date_from', Date.today) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone.starting", false + assert_select "div.version.starting", false end should "appear at the starting point" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone.starting[style*=left:52px]" + assert_select "div.version.starting[style*=left:28px]", true, @response.body end end @@ -524,13 +564,13 @@ @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone.ending", false + assert_select "div.version.ending", false end should "appear at the end of the date range" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.milestone.ending[style*=left:84px]" + assert_select "div.version.ending[style*=left:88px]", true, @response.body end end @@ -539,17 +579,17 @@ @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version-name", /#{@version.name}/ + assert_select "div.version.label", /#{@version.name}/ end should "show the version name" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version-name", /#{@version.name}/ + assert_select "div.version.label", /#{@version.name}/ end should "show the percent complete" do @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version-name", /30%/ + assert_select "div.version.label", /30%/ end end end @@ -620,7 +660,7 @@ :tracker => @tracker, :project => @project, :done_ratio => 30, - :start_date => Date.yesterday, + :start_date => 1.week.ago.to_date, :due_date => 1.week.from_now.to_date) @project.issues << @issue end @@ -629,12 +669,12 @@ context "todo line" do should "start from the starting point on the left" do @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_todo[style*=left:52px]" + assert_select "div.task_todo[style*=left:28px]", true, @response.body end should "be the total width of the issue" do @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_todo[style*=width:34px]" + assert_select "div.task_todo[style*=width:58px]", true, @response.body end end @@ -642,24 +682,32 @@ context "late line" do should "start from the starting point on the left" do @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_late[style*=left:52px]" + assert_select "div.task_late[style*=left:28px]", true, @response.body end should "be the total delayed width of the issue" do @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_late[style*=width:6px]" + assert_select "div.task_late[style*=width:30px]", true, @response.body end end context "done line" do should "start from the starting point on the left" do @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_done[style*=left:52px]" + assert_select "div.task_done[style*=left:28px]", true, @response.body end should "Be the total done width of the issue" do @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_done[style*=left:52px]" + assert_select "div.task_done[style*=width:18px]", true, @response.body + end + + should "not be the total done width if the chart starts after issue start date" do + create_gantt(@project, :date_from => 5.days.ago.to_date) + + @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) + assert_select "div.task_done[style*=left:0px]", true, @response.body + assert_select "div.task_done[style*=width:10px]", true, @response.body end end @@ -668,17 +716,17 @@ @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.issue-name" + assert_select "div.task.label", true, @response.body end should "show the issue status" do @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.issue-name", /#{@issue.status.name}/ + assert_select "div.task.label", /#{@issue.status.name}/ end should "show the percent complete" do @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.issue-name", /30%/ + assert_select "div.task.label", /30%/ end end end