comparison test/unit/lib/redmine/helpers/gantt_test.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 8661b858af72
children cbb26bc654de
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
93 93
94 context "#number_of_rows_on_project" do 94 context "#number_of_rows_on_project" do
95 setup do 95 setup do
96 create_gantt 96 create_gantt
97 end 97 end
98 98
99 should "clear the @query.project so cross-project issues and versions can be counted" do 99 should "count 0 for an empty the project" do
100 assert @gantt.query.project 100 assert_equal 0, @gantt.number_of_rows_on_project(@project)
101 @gantt.number_of_rows_on_project(@project)
102 assert_nil @gantt.query.project
103 end
104
105 should "count 1 for the project itself" do
106 assert_equal 1, @gantt.number_of_rows_on_project(@project)
107 end 101 end
108 102
109 should "count the number of issues without a version" do 103 should "count the number of issues without a version" do
110 @project.issues << Issue.generate_for_project!(@project, :fixed_version => nil) 104 @project.issues << Issue.generate_for_project!(@project, :fixed_version => nil)
111 assert_equal 2, @gantt.number_of_rows_on_project(@project) 105 assert_equal 2, @gantt.number_of_rows_on_project(@project)
112 end
113
114 should "count the number of versions" do
115 @project.versions << Version.generate!
116 @project.versions << Version.generate!
117 assert_equal 3, @gantt.number_of_rows_on_project(@project)
118 end 106 end
119 107
120 should "count the number of issues on versions, including cross-project" do 108 should "count the number of issues on versions, including cross-project" do
121 version = Version.generate! 109 version = Version.generate!
122 @project.versions << version 110 @project.versions << version
123 @project.issues << Issue.generate_for_project!(@project, :fixed_version => version) 111 @project.issues << Issue.generate_for_project!(@project, :fixed_version => version)
124 112
125 assert_equal 3, @gantt.number_of_rows_on_project(@project) 113 assert_equal 3, @gantt.number_of_rows_on_project(@project)
126 end
127
128 should "recursive and count the number of rows on each subproject" do
129 @project.versions << Version.generate! # +1
130
131 @subproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
132 @subproject.set_parent!(@project)
133 @subproject.issues << Issue.generate_for_project!(@subproject) # +1
134 @subproject.issues << Issue.generate_for_project!(@subproject) # +1
135
136 @subsubproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
137 @subsubproject.set_parent!(@subproject)
138 @subsubproject.issues << Issue.generate_for_project!(@subsubproject) # +1
139
140 assert_equal 7, @gantt.number_of_rows_on_project(@project) # +1 for self
141 end 114 end
142 end 115 end
143 116
144 # TODO: more of an integration test 117 # TODO: more of an integration test
145 context "#subjects" do 118 context "#subjects" do
181 154
182 should "be indented 24 (one level)" do 155 should "be indented 24 (one level)" do
183 @response.body = @gantt.subjects 156 @response.body = @gantt.subjects
184 assert_select "div.version-name[style*=left:24px]" 157 assert_select "div.version-name[style*=left:24px]"
185 end 158 end
159
160 context "without assigned issues" do
161 setup do
162 @version = Version.generate!(:effective_date => 2.week.from_now.to_date, :sharing => 'none', :name => 'empty_version')
163 @project.versions << @version
164 end
165
166 should "not be rendered" do
167 @response.body = @gantt.subjects
168 assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0
169 end
170 end
186 end 171 end
187 172
188 context "issue" do 173 context "issue" do
189 should "be rendered" do 174 should "be rendered" do
190 @response.body = @gantt.subjects 175 @response.body = @gantt.subjects
192 end 177 end
193 178
194 should "be indented 44 (two levels)" do 179 should "be indented 44 (two levels)" do
195 @response.body = @gantt.subjects 180 @response.body = @gantt.subjects
196 assert_select "div.issue-subject[style*=left:44px]" 181 assert_select "div.issue-subject[style*=left:44px]"
182 end
183
184 context "assigned to a shared version of another project" do
185 setup do
186 p = Project.generate!
187 p.trackers << @tracker
188 p.enabled_module_names = [:issue_tracking]
189 @shared_version = Version.generate!(:sharing => 'system')
190 p.versions << @shared_version
191 # Reassign the issue to a shared version of another project
192
193 @issue = Issue.generate!(:fixed_version => @shared_version,
194 :subject => "gantt#assigned_to_shared_version",
195 :tracker => @tracker,
196 :project => @project,
197 :done_ratio => 30,
198 :start_date => Date.yesterday,
199 :due_date => 1.week.from_now.to_date)
200 @project.issues << @issue
201 end
202
203 should "be rendered" do
204 @response.body = @gantt.subjects
205 assert_select "div.issue-subject", /#{@issue.subject}/
206 end
197 end 207 end
198 208
199 context "with subtasks" do 209 context "with subtasks" do
200 setup do 210 setup do
201 attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version} 211 attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version}
535 should "start from the starting point on the left" do 545 should "start from the starting point on the left" do
536 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 546 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
537 assert_select "div.version.task_done[style*=left:28px]", true, @response.body 547 assert_select "div.version.task_done[style*=left:28px]", true, @response.body
538 end 548 end
539 549
540 should "Be the total done width of the version" do 550 should "be the total done width of the version" do
541 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 551 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
542 assert_select "div.version.task_done[style*=width:18px]", true, @response.body 552 assert_select "div.version.task_done[style*=width:16px]", true, @response.body
543 end 553 end
544 end 554 end
545 555
546 context "starting marker" do 556 context "starting marker" do
547 should "not appear if the starting point is off the gantt chart" do 557 should "not appear if the starting point is off the gantt chart" do
695 should "start from the starting point on the left" do 705 should "start from the starting point on the left" do
696 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 706 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
697 assert_select "div.task_done[style*=left:28px]", true, @response.body 707 assert_select "div.task_done[style*=left:28px]", true, @response.body
698 end 708 end
699 709
700 should "Be the total done width of the issue" do 710 should "be the total done width of the issue" do
701 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 711 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
702 assert_select "div.task_done[style*=width:18px]", true, @response.body 712 # 15 days * 4 px * 30% - 2 px for borders = 16 px
713 assert_select "div.task_done[style*=width:16px]", true, @response.body
703 end 714 end
704 715
705 should "not be the total done width if the chart starts after issue start date" do 716 should "not be the total done width if the chart starts after issue start date" do
706 create_gantt(@project, :date_from => 5.days.ago.to_date) 717 create_gantt(@project, :date_from => 5.days.ago.to_date)
707 718
708 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 719 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
709 assert_select "div.task_done[style*=left:0px]", true, @response.body 720 assert_select "div.task_done[style*=left:0px]", true, @response.body
710 assert_select "div.task_done[style*=width:10px]", true, @response.body 721 assert_select "div.task_done[style*=width:8px]", true, @response.body
722 end
723
724 context "for completed issue" do
725 setup do
726 @issue.done_ratio = 100
727 end
728
729 should "be the total width of the issue" do
730 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
731 assert_select "div.task_done[style*=width:58px]", true, @response.body
732 end
733
734 should "be the total width of the issue with due_date=start_date" do
735 @issue.due_date = @issue.start_date
736 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
737 assert_select "div.task_done[style*=width:2px]", true, @response.body
738 end
711 end 739 end
712 end 740 end
713 741
714 context "status content" do 742 context "status content" do
715 should "appear at the far left, even if it's far in the past" do 743 should "appear at the far left, even if it's far in the past" do