Mercurial > hg > soundsoftware-site
comparison test/unit/lib/redmine/helpers/gantt_test.rb @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | e248c7af89ec |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
27 :members, | 27 :members, |
28 :enabled_modules, | 28 :enabled_modules, |
29 :versions, | 29 :versions, |
30 :groups_users | 30 :groups_users |
31 | 31 |
32 include ApplicationHelper | |
33 include ProjectsHelper | 32 include ProjectsHelper |
34 include IssuesHelper | 33 include IssuesHelper |
35 include ERB::Util | 34 include ERB::Util |
36 include Rails.application.routes.url_helpers | 35 include Rails.application.routes.url_helpers |
37 | 36 |
41 end | 40 end |
42 | 41 |
43 def today | 42 def today |
44 @today ||= Date.today | 43 @today ||= Date.today |
45 end | 44 end |
45 private :today | |
46 | 46 |
47 # Creates a Gantt chart for a 4 week span | 47 # Creates a Gantt chart for a 4 week span |
48 def create_gantt(project=Project.generate!, options={}) | 48 def create_gantt(project=Project.generate!, options={}) |
49 @project = project | 49 @project = project |
50 @gantt = Redmine::Helpers::Gantt.new(options) | 50 @gantt = Redmine::Helpers::Gantt.new(options) |
52 @gantt.query = IssueQuery.create!(:project => @project, :name => 'Gantt') | 52 @gantt.query = IssueQuery.create!(:project => @project, :name => 'Gantt') |
53 @gantt.view = self | 53 @gantt.view = self |
54 @gantt.instance_variable_set('@date_from', options[:date_from] || (today - 14)) | 54 @gantt.instance_variable_set('@date_from', options[:date_from] || (today - 14)) |
55 @gantt.instance_variable_set('@date_to', options[:date_to] || (today + 14)) | 55 @gantt.instance_variable_set('@date_to', options[:date_to] || (today + 14)) |
56 end | 56 end |
57 | 57 private :create_gantt |
58 context "#number_of_rows" do | 58 |
59 context "with one project" do | 59 test "#number_of_rows with one project should return the number of rows just for that project" do |
60 should "return the number of rows just for that project" do | 60 p1, p2 = Project.generate!, Project.generate! |
61 p1, p2 = Project.generate!, Project.generate! | 61 i1, i2 = Issue.generate!(:project => p1), Issue.generate!(:project => p2) |
62 i1, i2 = Issue.generate!(:project => p1), Issue.generate!(:project => p2) | 62 create_gantt(p1) |
63 create_gantt(p1) | 63 assert_equal 2, @gantt.number_of_rows |
64 assert_equal 2, @gantt.number_of_rows | 64 end |
65 end | 65 |
66 end | 66 test "#number_of_rows with no project should return the total number of rows for all the projects, resursively" do |
67 | 67 p1, p2 = Project.generate!, Project.generate! |
68 context "with no project" do | 68 create_gantt(nil) |
69 should "return the total number of rows for all the projects, resursively" do | 69 # fix the return value of #number_of_rows_on_project() to an arbitrary value |
70 p1, p2 = Project.generate!, Project.generate! | 70 # so that we really only test #number_of_rows |
71 create_gantt(nil) | 71 @gantt.stubs(:number_of_rows_on_project).returns(7) |
72 #fix the return value of #number_of_rows_on_project() to an arbitrary value | 72 # also fix #projects because we want to test #number_of_rows in isolation |
73 #so that we really only test #number_of_rows | 73 @gantt.stubs(:projects).returns(Project.all) |
74 @gantt.stubs(:number_of_rows_on_project).returns(7) | 74 # actual test |
75 #also fix #projects because we want to test #number_of_rows in isolation | 75 assert_equal Project.count*7, @gantt.number_of_rows |
76 @gantt.stubs(:projects).returns(Project.all) | 76 end |
77 #actual test | 77 |
78 assert_equal Project.count*7, @gantt.number_of_rows | 78 test "#number_of_rows should not exceed max_rows option" do |
79 end | 79 p = Project.generate! |
80 end | 80 5.times do |
81 | 81 Issue.generate!(:project => p) |
82 should "not exceed max_rows option" do | 82 end |
83 p = Project.generate! | 83 create_gantt(p) |
84 5.times do | 84 @gantt.render |
85 Issue.generate!(:project => p) | 85 assert_equal 6, @gantt.number_of_rows |
86 end | 86 assert !@gantt.truncated |
87 create_gantt(p) | 87 create_gantt(p, :max_rows => 3) |
88 @gantt.render | 88 @gantt.render |
89 assert_equal 6, @gantt.number_of_rows | 89 assert_equal 3, @gantt.number_of_rows |
90 assert !@gantt.truncated | 90 assert @gantt.truncated |
91 create_gantt(p, :max_rows => 3) | 91 end |
92 @gantt.render | 92 |
93 assert_equal 3, @gantt.number_of_rows | 93 test "#number_of_rows_on_project should count 0 for an empty the project" do |
94 assert @gantt.truncated | 94 create_gantt |
95 end | 95 assert_equal 0, @gantt.number_of_rows_on_project(@project) |
96 end | 96 end |
97 | 97 |
98 context "#number_of_rows_on_project" do | 98 test "#number_of_rows_on_project should count the number of issues without a version" do |
99 setup do | 99 create_gantt |
100 create_gantt | 100 @project.issues << Issue.generate!(:project => @project, :fixed_version => nil) |
101 end | 101 assert_equal 2, @gantt.number_of_rows_on_project(@project) |
102 | 102 end |
103 should "count 0 for an empty the project" do | 103 |
104 assert_equal 0, @gantt.number_of_rows_on_project(@project) | 104 test "#number_of_rows_on_project should count the number of issues on versions, including cross-project" do |
105 end | 105 create_gantt |
106 | 106 version = Version.generate! |
107 should "count the number of issues without a version" do | 107 @project.versions << version |
108 @project.issues << Issue.generate!(:project => @project, :fixed_version => nil) | 108 @project.issues << Issue.generate!(:project => @project, :fixed_version => version) |
109 assert_equal 2, @gantt.number_of_rows_on_project(@project) | 109 assert_equal 3, @gantt.number_of_rows_on_project(@project) |
110 end | 110 end |
111 | 111 |
112 should "count the number of issues on versions, including cross-project" do | 112 def setup_subjects |
113 version = Version.generate! | 113 create_gantt |
114 @project.versions << version | 114 @project.enabled_module_names = [:issue_tracking] |
115 @project.issues << Issue.generate!(:project => @project, :fixed_version => version) | 115 @tracker = Tracker.generate! |
116 assert_equal 3, @gantt.number_of_rows_on_project(@project) | 116 @project.trackers << @tracker |
117 end | 117 @version = Version.generate!(:effective_date => (today + 7), :sharing => 'none') |
118 end | 118 @project.versions << @version |
119 | 119 @issue = Issue.generate!(:fixed_version => @version, |
120 # TODO: more of an integration test | |
121 context "#subjects" do | |
122 setup do | |
123 create_gantt | |
124 @project.enabled_module_names = [:issue_tracking] | |
125 @tracker = Tracker.generate! | |
126 @project.trackers << @tracker | |
127 @version = Version.generate!(:effective_date => (today + 7), :sharing => 'none') | |
128 @project.versions << @version | |
129 @issue = Issue.generate!(:fixed_version => @version, | |
130 :subject => "gantt#line_for_project", | 120 :subject => "gantt#line_for_project", |
131 :tracker => @tracker, | 121 :tracker => @tracker, |
132 :project => @project, | 122 :project => @project, |
133 :done_ratio => 30, | 123 :done_ratio => 30, |
134 :start_date => (today - 1), | 124 :start_date => (today - 1), |
135 :due_date => (today + 7)) | 125 :due_date => (today + 7)) |
136 @project.issues << @issue | 126 @project.issues << @issue |
137 end | 127 end |
138 | 128 private :setup_subjects |
139 context "project" do | 129 |
140 should "be rendered" do | 130 # TODO: more of an integration test |
141 @output_buffer = @gantt.subjects | 131 test "#subjects project should be rendered" do |
142 assert_select "div.project-name a", /#{@project.name}/ | 132 setup_subjects |
143 end | 133 @output_buffer = @gantt.subjects |
144 | 134 assert_select "div.project-name a", /#{@project.name}/ |
145 should "have an indent of 4" do | 135 end |
146 @output_buffer = @gantt.subjects | 136 |
147 assert_select "div.project-name[style*=left:4px]" | 137 test "#subjects project should have an indent of 4" do |
148 end | 138 setup_subjects |
149 end | 139 @output_buffer = @gantt.subjects |
150 | 140 assert_select "div.project-name[style*=left:4px]" |
151 context "version" do | 141 end |
152 should "be rendered" do | 142 |
153 @output_buffer = @gantt.subjects | 143 test "#subjects version should be rendered" do |
154 assert_select "div.version-name a", /#{@version.name}/ | 144 setup_subjects |
155 end | 145 @output_buffer = @gantt.subjects |
156 | 146 assert_select "div.version-name a", /#{@version.name}/ |
157 should "be indented 24 (one level)" do | 147 end |
158 @output_buffer = @gantt.subjects | 148 |
159 assert_select "div.version-name[style*=left:24px]" | 149 test "#subjects version should be indented 24 (one level)" do |
160 end | 150 setup_subjects |
161 | 151 @output_buffer = @gantt.subjects |
162 context "without assigned issues" do | 152 assert_select "div.version-name[style*=left:24px]" |
163 setup do | 153 end |
164 @version = Version.generate!(:effective_date => (today + 14), | 154 |
155 test "#subjects version without assigned issues should not be rendered" do | |
156 setup_subjects | |
157 @version = Version.generate!(:effective_date => (today + 14), | |
165 :sharing => 'none', | 158 :sharing => 'none', |
166 :name => 'empty_version') | 159 :name => 'empty_version') |
167 @project.versions << @version | 160 @project.versions << @version |
168 end | 161 @output_buffer = @gantt.subjects |
169 | 162 assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0 |
170 should "not be rendered" do | 163 end |
171 @output_buffer = @gantt.subjects | 164 |
172 assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0 | 165 test "#subjects issue should be rendered" do |
173 end | 166 setup_subjects |
174 end | 167 @output_buffer = @gantt.subjects |
175 end | 168 assert_select "div.issue-subject", /#{@issue.subject}/ |
176 | 169 end |
177 context "issue" do | 170 |
178 should "be rendered" do | 171 test "#subjects issue should be indented 44 (two levels)" do |
179 @output_buffer = @gantt.subjects | 172 setup_subjects |
180 assert_select "div.issue-subject", /#{@issue.subject}/ | 173 @output_buffer = @gantt.subjects |
181 end | 174 assert_select "div.issue-subject[style*=left:44px]" |
182 | 175 end |
183 should "be indented 44 (two levels)" do | 176 |
184 @output_buffer = @gantt.subjects | 177 test "#subjects issue assigned to a shared version of another project should be rendered" do |
185 assert_select "div.issue-subject[style*=left:44px]" | 178 setup_subjects |
186 end | 179 p = Project.generate! |
187 | 180 p.enabled_module_names = [:issue_tracking] |
188 context "assigned to a shared version of another project" do | 181 @shared_version = Version.generate!(:sharing => 'system') |
189 setup do | 182 p.versions << @shared_version |
190 p = Project.generate! | 183 # Reassign the issue to a shared version of another project |
191 p.enabled_module_names = [:issue_tracking] | 184 @issue = Issue.generate!(:fixed_version => @shared_version, |
192 @shared_version = Version.generate!(:sharing => 'system') | |
193 p.versions << @shared_version | |
194 # Reassign the issue to a shared version of another project | |
195 @issue = Issue.generate!(:fixed_version => @shared_version, | |
196 :subject => "gantt#assigned_to_shared_version", | 185 :subject => "gantt#assigned_to_shared_version", |
197 :tracker => @tracker, | 186 :tracker => @tracker, |
198 :project => @project, | 187 :project => @project, |
199 :done_ratio => 30, | 188 :done_ratio => 30, |
200 :start_date => (today - 1), | 189 :start_date => (today - 1), |
201 :due_date => (today + 7)) | 190 :due_date => (today + 7)) |
202 @project.issues << @issue | 191 @project.issues << @issue |
203 end | 192 @output_buffer = @gantt.subjects |
204 | 193 assert_select "div.issue-subject", /#{@issue.subject}/ |
205 should "be rendered" do | 194 end |
206 @output_buffer = @gantt.subjects | 195 |
207 assert_select "div.issue-subject", /#{@issue.subject}/ | 196 test "#subjects issue with subtasks should indent subtasks" do |
208 end | 197 setup_subjects |
209 end | 198 attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version} |
210 | 199 @child1 = Issue.generate!( |
211 context "with subtasks" do | |
212 setup do | |
213 attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version} | |
214 @child1 = Issue.generate!( | |
215 attrs.merge(:subject => 'child1', | 200 attrs.merge(:subject => 'child1', |
216 :parent_issue_id => @issue.id, | 201 :parent_issue_id => @issue.id, |
217 :start_date => (today - 1), | 202 :start_date => (today - 1), |
218 :due_date => (today + 2)) | 203 :due_date => (today + 2)) |
219 ) | 204 ) |
220 @child2 = Issue.generate!( | 205 @child2 = Issue.generate!( |
221 attrs.merge(:subject => 'child2', | 206 attrs.merge(:subject => 'child2', |
222 :parent_issue_id => @issue.id, | 207 :parent_issue_id => @issue.id, |
223 :start_date => today, | 208 :start_date => today, |
224 :due_date => (today + 7)) | 209 :due_date => (today + 7)) |
225 ) | 210 ) |
226 @grandchild = Issue.generate!( | 211 @grandchild = Issue.generate!( |
227 attrs.merge(:subject => 'grandchild', | 212 attrs.merge(:subject => 'grandchild', |
228 :parent_issue_id => @child1.id, | 213 :parent_issue_id => @child1.id, |
229 :start_date => (today - 1), | 214 :start_date => (today - 1), |
230 :due_date => (today + 2)) | 215 :due_date => (today + 2)) |
231 ) | 216 ) |
232 end | 217 @output_buffer = @gantt.subjects |
233 | 218 # parent task 44px |
234 should "indent subtasks" do | 219 assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/ |
235 @output_buffer = @gantt.subjects | 220 # children 64px |
236 # parent task 44px | 221 assert_select "div.issue-subject[style*=left:64px]", /child1/ |
237 assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/ | 222 assert_select "div.issue-subject[style*=left:64px]", /child2/ |
238 # children 64px | 223 # grandchild 84px |
239 assert_select "div.issue-subject[style*=left:64px]", /child1/ | 224 assert_select "div.issue-subject[style*=left:84px]", /grandchild/, @output_buffer |
240 assert_select "div.issue-subject[style*=left:64px]", /child2/ | |
241 # grandchild 84px | |
242 assert_select "div.issue-subject[style*=left:84px]", /grandchild/, @output_buffer | |
243 end | |
244 end | |
245 end | |
246 end | 225 end |
247 | 226 |
248 context "#lines" do | 227 context "#lines" do |
249 setup do | 228 setup do |
250 create_gantt | 229 create_gantt |
289 assert_select "div.tooltip", /#{@issue.subject}/ | 268 assert_select "div.tooltip", /#{@issue.subject}/ |
290 end | 269 end |
291 end | 270 end |
292 end | 271 end |
293 | 272 |
294 context "#render_project" do | |
295 should "be tested" | |
296 end | |
297 | |
298 context "#render_issues" do | |
299 should "be tested" | |
300 end | |
301 | |
302 context "#render_version" do | |
303 should "be tested" | |
304 end | |
305 | |
306 context "#subject_for_project" do | 273 context "#subject_for_project" do |
307 setup do | 274 setup do |
308 create_gantt | 275 create_gantt |
309 end | 276 end |
310 | 277 |
335 assert @project.reload.overdue?, "Need an overdue project for this test" | 302 assert @project.reload.overdue?, "Need an overdue project for this test" |
336 @output_buffer = @gantt.subject_for_project(@project, {:format => :html}) | 303 @output_buffer = @gantt.subject_for_project(@project, {:format => :html}) |
337 assert_select 'div span.project-overdue' | 304 assert_select 'div span.project-overdue' |
338 end | 305 end |
339 end | 306 end |
340 should "test the PNG format" | |
341 should "test the PDF format" | |
342 end | 307 end |
343 | 308 |
344 context "#line_for_project" do | 309 context "#line_for_project" do |
345 setup do | 310 setup do |
346 create_gantt | 311 create_gantt |
369 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) | 334 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) |
370 assert_select "div.project.task_todo[style*=width:58px]", true, @output_buffer | 335 assert_select "div.project.task_todo[style*=width:58px]", true, @output_buffer |
371 end | 336 end |
372 end | 337 end |
373 | 338 |
374 context "late line" do | |
375 should_eventually "start from the starting point on the left" do | |
376 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) | |
377 assert_select "div.project.task_late[style*=left:28px]", true, @output_buffer | |
378 end | |
379 | |
380 should_eventually "be the total delayed width of the project" do | |
381 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) | |
382 assert_select "div.project.task_late[style*=width:30px]", true, @output_buffer | |
383 end | |
384 end | |
385 | |
386 context "done line" do | |
387 should_eventually "start from the starting point on the left" do | |
388 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) | |
389 assert_select "div.project.task_done[style*=left:28px]", true, @output_buffer | |
390 end | |
391 | |
392 should_eventually "Be the total done width of the project" do | |
393 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) | |
394 assert_select "div.project.task_done[style*=width:18px]", true, @output_buffer | |
395 end | |
396 end | |
397 | |
398 context "starting marker" do | 339 context "starting marker" do |
399 should "not appear if the starting point is off the gantt chart" do | 340 should "not appear if the starting point is off the gantt chart" do |
400 # Shift the date range of the chart | 341 # Shift the date range of the chart |
401 @gantt.instance_variable_set('@date_from', today) | 342 @gantt.instance_variable_set('@date_from', today) |
402 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) | 343 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) |
432 | 373 |
433 should "show the project name" do | 374 should "show the project name" do |
434 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) | 375 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) |
435 assert_select "div.project.label", /#{@project.name}/ | 376 assert_select "div.project.label", /#{@project.name}/ |
436 end | 377 end |
437 | 378 end |
438 should_eventually "show the percent complete" do | 379 end |
439 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) | |
440 assert_select "div.project.label", /0%/ | |
441 end | |
442 end | |
443 end | |
444 should "test the PNG format" | |
445 should "test the PDF format" | |
446 end | 380 end |
447 | 381 |
448 context "#subject_for_version" do | 382 context "#subject_for_version" do |
449 setup do | 383 setup do |
450 create_gantt | 384 create_gantt |
492 assert @version.behind_schedule?, "Need a behind schedule version for this test" | 426 assert @version.behind_schedule?, "Need a behind schedule version for this test" |
493 @output_buffer = @gantt.subject_for_version(@version, {:format => :html}) | 427 @output_buffer = @gantt.subject_for_version(@version, {:format => :html}) |
494 assert_select 'div span.version-behind-schedule' | 428 assert_select 'div span.version-behind-schedule' |
495 end | 429 end |
496 end | 430 end |
497 should "test the PNG format" | |
498 should "test the PDF format" | |
499 end | 431 end |
500 | 432 |
501 context "#line_for_version" do | 433 context "#line_for_version" do |
502 setup do | 434 setup do |
503 create_gantt | 435 create_gantt |
596 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) | 528 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) |
597 assert_select "div.version.label", /30%/ | 529 assert_select "div.version.label", /30%/ |
598 end | 530 end |
599 end | 531 end |
600 end | 532 end |
601 should "test the PNG format" | |
602 should "test the PDF format" | |
603 end | 533 end |
604 | 534 |
605 context "#subject_for_issue" do | 535 context "#subject_for_issue" do |
606 setup do | 536 setup do |
607 create_gantt | 537 create_gantt |
641 assert @issue.overdue?, "Need an overdue issue for this test" | 571 assert @issue.overdue?, "Need an overdue issue for this test" |
642 @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html}) | 572 @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html}) |
643 assert_select 'div span.issue-overdue' | 573 assert_select 'div span.issue-overdue' |
644 end | 574 end |
645 end | 575 end |
646 should "test the PNG format" | |
647 should "test the PDF format" | |
648 end | 576 end |
649 | 577 |
650 context "#line_for_issue" do | 578 context "#line_for_issue" do |
651 setup do | 579 setup do |
652 create_gantt | 580 create_gantt |
748 | 676 |
749 should "have an issue tooltip" do | 677 should "have an issue tooltip" do |
750 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) | 678 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) |
751 assert_select "div.tooltip", /#{@issue.subject}/ | 679 assert_select "div.tooltip", /#{@issue.subject}/ |
752 end | 680 end |
753 should "test the PNG format" | |
754 should "test the PDF format" | |
755 end | |
756 | |
757 context "#to_image" do | |
758 should "be tested" | |
759 end | |
760 | |
761 context "#to_pdf" do | |
762 should "be tested" | |
763 end | 681 end |
764 | 682 |
765 def test_sort_issues_no_date | 683 def test_sort_issues_no_date |
766 project = Project.generate! | 684 project = Project.generate! |
767 issue1 = Issue.generate!(:subject => "test", :project => project) | 685 issue1 = Issue.generate!(:subject => "test", :project => project) |