comparison test/unit/lib/redmine/helpers/gantt_test.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents cbce1fd3b1b7
children 433d4f72a19b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
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.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../../../../test_helper', __FILE__) 18 require File.expand_path('../../../../../test_helper', __FILE__)
24 include ActionView::Helpers::TextHelper 24 include ActionView::Helpers::TextHelper
25 include ActionController::UrlWriter 25 include ActionController::UrlWriter
26 include ApplicationHelper 26 include ApplicationHelper
27 include ProjectsHelper 27 include ProjectsHelper
28 include IssuesHelper 28 include IssuesHelper
29 29
30 def self.default_url_options 30 def self.default_url_options
31 {:only_path => true } 31 {:only_path => true }
32 end 32 end
33 33
34 end 34 end
76 should "not exceed max_rows option" do 76 should "not exceed max_rows option" do
77 p = Project.generate! 77 p = Project.generate!
78 5.times do 78 5.times do
79 Issue.generate_for_project!(p) 79 Issue.generate_for_project!(p)
80 end 80 end
81 81
82 create_gantt(p) 82 create_gantt(p)
83 @gantt.render 83 @gantt.render
84 assert_equal 6, @gantt.number_of_rows 84 assert_equal 6, @gantt.number_of_rows
85 assert !@gantt.truncated 85 assert !@gantt.truncated
86 86
107 107
108 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
109 version = Version.generate! 109 version = Version.generate!
110 @project.versions << version 110 @project.versions << version
111 @project.issues << Issue.generate_for_project!(@project, :fixed_version => version) 111 @project.issues << Issue.generate_for_project!(@project, :fixed_version => version)
112 112
113 assert_equal 3, @gantt.number_of_rows_on_project(@project) 113 assert_equal 3, @gantt.number_of_rows_on_project(@project)
114 end 114 end
115 end 115 end
116 116
117 # TODO: more of an integration test 117 # TODO: more of an integration test
129 :tracker => @tracker, 129 :tracker => @tracker,
130 :project => @project, 130 :project => @project,
131 :done_ratio => 30, 131 :done_ratio => 30,
132 :start_date => Date.yesterday, 132 :start_date => Date.yesterday,
133 :due_date => 1.week.from_now.to_date) 133 :due_date => 1.week.from_now.to_date)
134 @project.issues << @issue 134 @project.issues << @issue
135 end 135 end
136 136
137 context "project" do 137 context "project" do
138 should "be rendered" do 138 should "be rendered" do
139 @response.body = @gantt.subjects 139 @response.body = @gantt.subjects
140 assert_select "div.project-name a", /#{@project.name}/ 140 assert_select "div.project-name a", /#{@project.name}/
141 end 141 end
142 142
143 should "have an indent of 4" do 143 should "have an indent of 4" do
144 @response.body = @gantt.subjects 144 @response.body = @gantt.subjects
145 assert_select "div.project-name[style*=left:4px]" 145 assert_select "div.project-name[style*=left:4px]"
146 end 146 end
147 end 147 end
148 148
149 context "version" do 149 context "version" do
150 should "be rendered" do 150 should "be rendered" do
151 @response.body = @gantt.subjects 151 @response.body = @gantt.subjects
152 assert_select "div.version-name a", /#{@version.name}/ 152 assert_select "div.version-name a", /#{@version.name}/
153 end 153 end
154 154
155 should "be indented 24 (one level)" do 155 should "be indented 24 (one level)" do
156 @response.body = @gantt.subjects 156 @response.body = @gantt.subjects
157 assert_select "div.version-name[style*=left:24px]" 157 assert_select "div.version-name[style*=left:24px]"
158 end 158 end
159 159
160 context "without assigned issues" do 160 context "without assigned issues" do
161 setup do 161 setup do
162 @version = Version.generate!(:effective_date => 2.week.from_now.to_date, :sharing => 'none', :name => 'empty_version') 162 @version = Version.generate!(:effective_date => 2.week.from_now.to_date, :sharing => 'none', :name => 'empty_version')
163 @project.versions << @version 163 @project.versions << @version
164 end 164 end
165 165
166 should "not be rendered" do 166 should "not be rendered" do
167 @response.body = @gantt.subjects 167 @response.body = @gantt.subjects
168 assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0 168 assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0
169 end 169 end
170 end 170 end
171 end 171 end
172 172
173 context "issue" do 173 context "issue" do
174 should "be rendered" do 174 should "be rendered" do
175 @response.body = @gantt.subjects 175 @response.body = @gantt.subjects
176 assert_select "div.issue-subject", /#{@issue.subject}/ 176 assert_select "div.issue-subject", /#{@issue.subject}/
177 end 177 end
178 178
179 should "be indented 44 (two levels)" do 179 should "be indented 44 (two levels)" do
180 @response.body = @gantt.subjects 180 @response.body = @gantt.subjects
181 assert_select "div.issue-subject[style*=left:44px]" 181 assert_select "div.issue-subject[style*=left:44px]"
182 end 182 end
183 183
184 context "assigned to a shared version of another project" do 184 context "assigned to a shared version of another project" do
185 setup do 185 setup do
186 p = Project.generate! 186 p = Project.generate!
187 p.trackers << @tracker 187 p.trackers << @tracker
188 p.enabled_module_names = [:issue_tracking] 188 p.enabled_module_names = [:issue_tracking]
189 @shared_version = Version.generate!(:sharing => 'system') 189 @shared_version = Version.generate!(:sharing => 'system')
190 p.versions << @shared_version 190 p.versions << @shared_version
191 # Reassign the issue to a shared version of another project 191 # Reassign the issue to a shared version of another project
192 192
193 @issue = Issue.generate!(:fixed_version => @shared_version, 193 @issue = Issue.generate!(:fixed_version => @shared_version,
194 :subject => "gantt#assigned_to_shared_version", 194 :subject => "gantt#assigned_to_shared_version",
195 :tracker => @tracker, 195 :tracker => @tracker,
196 :project => @project, 196 :project => @project,
197 :done_ratio => 30, 197 :done_ratio => 30,
198 :start_date => Date.yesterday, 198 :start_date => Date.yesterday,
199 :due_date => 1.week.from_now.to_date) 199 :due_date => 1.week.from_now.to_date)
200 @project.issues << @issue 200 @project.issues << @issue
201 end 201 end
202 202
203 should "be rendered" do 203 should "be rendered" do
204 @response.body = @gantt.subjects 204 @response.body = @gantt.subjects
205 assert_select "div.issue-subject", /#{@issue.subject}/ 205 assert_select "div.issue-subject", /#{@issue.subject}/
206 end 206 end
207 end 207 end
208 208
209 context "with subtasks" do 209 context "with subtasks" do
210 setup do 210 setup do
211 attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version} 211 attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version}
212 @child1 = Issue.generate!(attrs.merge(:subject => 'child1', :parent_issue_id => @issue.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date)) 212 @child1 = Issue.generate!(attrs.merge(:subject => 'child1', :parent_issue_id => @issue.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date))
213 @child2 = Issue.generate!(attrs.merge(:subject => 'child2', :parent_issue_id => @issue.id, :start_date => Date.today, :due_date => 1.week.from_now.to_date)) 213 @child2 = Issue.generate!(attrs.merge(:subject => 'child2', :parent_issue_id => @issue.id, :start_date => Date.today, :due_date => 1.week.from_now.to_date))
214 @grandchild = Issue.generate!(attrs.merge(:subject => 'grandchild', :parent_issue_id => @child1.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date)) 214 @grandchild = Issue.generate!(attrs.merge(:subject => 'grandchild', :parent_issue_id => @child1.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date))
215 end 215 end
216 216
217 should "indent subtasks" do 217 should "indent subtasks" do
218 @response.body = @gantt.subjects 218 @response.body = @gantt.subjects
219 # parent task 44px 219 # parent task 44px
220 assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/ 220 assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/
221 # children 64px 221 # children 64px
289 289
290 context "#subject_for_project" do 290 context "#subject_for_project" do
291 setup do 291 setup do
292 create_gantt 292 create_gantt
293 end 293 end
294 294
295 context ":html format" do 295 context ":html format" do
296 should "add an absolute positioned div" do 296 should "add an absolute positioned div" do
297 @response.body = @gantt.subject_for_project(@project, {:format => :html}) 297 @response.body = @gantt.subject_for_project(@project, {:format => :html})
298 assert_select "div[style*=absolute]" 298 assert_select "div[style*=absolute]"
299 end 299 end
414 should "appear at the end of the date range" do 414 should "appear at the end of the date range" do
415 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 415 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
416 assert_select "div.project.ending[style*=left:88px]", true, @response.body 416 assert_select "div.project.ending[style*=left:88px]", true, @response.body
417 end 417 end
418 end 418 end
419 419
420 context "status content" do 420 context "status content" do
421 should "appear at the far left, even if it's far in the past" do 421 should "appear at the far left, even if it's far in the past" do
422 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) 422 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
423 423
424 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 424 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
474 assert_select 'div', :text => /#{@version.name}/ 474 assert_select 'div', :text => /#{@version.name}/
475 end 475 end
476 476
477 should "include a link to the version" do 477 should "include a link to the version" do
478 @response.body = @gantt.subject_for_version(@version, {:format => :html}) 478 @response.body = @gantt.subject_for_version(@version, {:format => :html})
479 assert_select 'a[href=?]', Regexp.escape("/versions/show/#{@version.to_param}"), :text => /#{@version.name}/ 479 assert_select 'a[href=?]', Regexp.escape("/versions/#{@version.to_param}"), :text => /#{@version.name}/
480 end 480 end
481 481
482 should "style late versions" do 482 should "style late versions" do
483 assert @version.overdue?, "Need an overdue version for this test" 483 assert @version.overdue?, "Need an overdue version for this test"
484 @response.body = @gantt.subject_for_version(@version, {:format => :html}) 484 @response.body = @gantt.subject_for_version(@version, {:format => :html})
581 should "appear at the end of the date range" do 581 should "appear at the end of the date range" do
582 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 582 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
583 assert_select "div.version.ending[style*=left:88px]", true, @response.body 583 assert_select "div.version.ending[style*=left:88px]", true, @response.body
584 end 584 end
585 end 585 end
586 586
587 context "status content" do 587 context "status content" do
588 should "appear at the far left, even if it's far in the past" do 588 should "appear at the far left, even if it's far in the past" do
589 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) 589 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
590 590
591 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 591 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
713 assert_select "div.task_done[style*=width:16px]", true, @response.body 713 assert_select "div.task_done[style*=width:16px]", true, @response.body
714 end 714 end
715 715
716 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
717 create_gantt(@project, :date_from => 5.days.ago.to_date) 717 create_gantt(@project, :date_from => 5.days.ago.to_date)
718 718
719 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 719 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
720 assert_select "div.task_done[style*=left:0px]", true, @response.body 720 assert_select "div.task_done[style*=left:0px]", true, @response.body
721 assert_select "div.task_done[style*=width:8px]", true, @response.body 721 assert_select "div.task_done[style*=width:8px]", true, @response.body
722 end 722 end
723 723
724 context "for completed issue" do 724 context "for completed issue" do
725 setup do 725 setup do
726 @issue.done_ratio = 100 726 @issue.done_ratio = 100
727 end 727 end
728 728
729 should "be the total width of the issue" do 729 should "be the total width of the issue" do
730 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 730 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
731 assert_select "div.task_done[style*=width:58px]", true, @response.body 731 assert_select "div.task_done[style*=width:58px]", true, @response.body
732 end 732 end
733 733
734 should "be the total width of the issue with due_date=start_date" do 734 should "be the total width of the issue with due_date=start_date" do
735 @issue.due_date = @issue.start_date 735 @issue.due_date = @issue.start_date
736 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 736 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
737 assert_select "div.task_done[style*=width:2px]", true, @response.body 737 assert_select "div.task_done[style*=width:2px]", true, @response.body
738 end 738 end
773 end 773 end
774 774
775 context "#to_pdf" do 775 context "#to_pdf" do
776 should "be tested" 776 should "be tested"
777 end 777 end
778 778
779 end 779 end