comparison test/unit/lib/redmine/helpers/gantt_test.rb @ 523:0b6c82dead28 luisf

Merge from branch "cannam"
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 14:23:37 +0100
parents cbce1fd3b1b7
children cbb26bc654de
comparison
equal deleted inserted replaced
318:f7c525dc7585 523:0b6c82dead28
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.
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.dirname(__FILE__) + '/../../../../test_helper' 18 require File.expand_path('../../../../../test_helper', __FILE__)
19 19
20 class Redmine::Helpers::GanttTest < ActiveSupport::TestCase 20 class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
21 # Utility methods and classes so assert_select can be used. 21 # Utility methods and classes so assert_select can be used.
22 class GanttViewTest < ActionView::Base 22 class GanttViewTest < ActionView::Base
23 include ActionView::Helpers::UrlHelper 23 include ActionView::Helpers::UrlHelper
51 def html_document 51 def html_document
52 HTML::Document.new(@response.body) 52 HTML::Document.new(@response.body)
53 end 53 end
54 54
55 # Creates a Gantt chart for a 4 week span 55 # Creates a Gantt chart for a 4 week span
56 def create_gantt(project=Project.generate!) 56 def create_gantt(project=Project.generate!, options={})
57 @project = project 57 @project = project
58 @gantt = Redmine::Helpers::Gantt.new 58 @gantt = Redmine::Helpers::Gantt.new(options)
59 @gantt.project = @project 59 @gantt.project = @project
60 @gantt.query = Query.generate_default!(:project => @project) 60 @gantt.query = Query.generate_default!(:project => @project)
61 @gantt.view = build_view 61 @gantt.view = build_view
62 @gantt.instance_variable_set('@date_from', 2.weeks.ago.to_date) 62 @gantt.instance_variable_set('@date_from', options[:date_from] || 2.weeks.ago.to_date)
63 @gantt.instance_variable_set('@date_to', 2.weeks.from_now.to_date) 63 @gantt.instance_variable_set('@date_to', options[:date_to] || 2.weeks.from_now.to_date)
64 end 64 end
65 65
66 context "#number_of_rows" do 66 context "#number_of_rows" do
67 67
68 context "with one project" do 68 context "with one project" do
71 71
72 context "with no project" do 72 context "with no project" do
73 should "return the total number of rows for all the projects, resursively" 73 should "return the total number of rows for all the projects, resursively"
74 end 74 end
75 75
76 should "not exceed max_rows option" do
77 p = Project.generate!
78 5.times do
79 Issue.generate_for_project!(p)
80 end
81
82 create_gantt(p)
83 @gantt.render
84 assert_equal 6, @gantt.number_of_rows
85 assert !@gantt.truncated
86
87 create_gantt(p, :max_rows => 3)
88 @gantt.render
89 assert_equal 3, @gantt.number_of_rows
90 assert @gantt.truncated
91 end
76 end 92 end
77 93
78 context "#number_of_rows_on_project" do 94 context "#number_of_rows_on_project" do
79 setup do 95 setup do
80 create_gantt 96 create_gantt
81 end 97 end
82 98
83 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
84 assert @gantt.query.project 100 assert_equal 0, @gantt.number_of_rows_on_project(@project)
85 @gantt.number_of_rows_on_project(@project)
86 assert_nil @gantt.query.project
87 end
88
89 should "count 1 for the project itself" do
90 assert_equal 1, @gantt.number_of_rows_on_project(@project)
91 end 101 end
92 102
93 should "count the number of issues without a version" do 103 should "count the number of issues without a version" do
94 @project.issues << Issue.generate_for_project!(@project, :fixed_version => nil) 104 @project.issues << Issue.generate_for_project!(@project, :fixed_version => nil)
95 assert_equal 2, @gantt.number_of_rows_on_project(@project) 105 assert_equal 2, @gantt.number_of_rows_on_project(@project)
96 end
97
98 should "count the number of versions" do
99 @project.versions << Version.generate!
100 @project.versions << Version.generate!
101 assert_equal 3, @gantt.number_of_rows_on_project(@project)
102 end 106 end
103 107
104 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
105 version = Version.generate! 109 version = Version.generate!
106 @project.versions << version 110 @project.versions << version
107 @project.issues << Issue.generate_for_project!(@project, :fixed_version => version) 111 @project.issues << Issue.generate_for_project!(@project, :fixed_version => version)
108 112
109 assert_equal 3, @gantt.number_of_rows_on_project(@project) 113 assert_equal 3, @gantt.number_of_rows_on_project(@project)
110 end
111
112 should "recursive and count the number of rows on each subproject" do
113 @project.versions << Version.generate! # +1
114
115 @subproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
116 @subproject.set_parent!(@project)
117 @subproject.issues << Issue.generate_for_project!(@subproject) # +1
118 @subproject.issues << Issue.generate_for_project!(@subproject) # +1
119
120 @subsubproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
121 @subsubproject.set_parent!(@subproject)
122 @subsubproject.issues << Issue.generate_for_project!(@subsubproject) # +1
123
124 assert_equal 7, @gantt.number_of_rows_on_project(@project) # +1 for self
125 end 114 end
126 end 115 end
127 116
128 # TODO: more of an integration test 117 # TODO: more of an integration test
129 context "#subjects" do 118 context "#subjects" do
140 :tracker => @tracker, 129 :tracker => @tracker,
141 :project => @project, 130 :project => @project,
142 :done_ratio => 30, 131 :done_ratio => 30,
143 :start_date => Date.yesterday, 132 :start_date => Date.yesterday,
144 :due_date => 1.week.from_now.to_date) 133 :due_date => 1.week.from_now.to_date)
145 @project.issues << @issue 134 @project.issues << @issue
146 135 end
147 @response.body = @gantt.subjects 136
148 end
149
150 context "project" do 137 context "project" do
151 should "be rendered" do 138 should "be rendered" do
139 @response.body = @gantt.subjects
152 assert_select "div.project-name a", /#{@project.name}/ 140 assert_select "div.project-name a", /#{@project.name}/
153 end 141 end
154 142
155 should "have an indent of 4" do 143 should "have an indent of 4" do
144 @response.body = @gantt.subjects
156 assert_select "div.project-name[style*=left:4px]" 145 assert_select "div.project-name[style*=left:4px]"
157 end 146 end
158 end 147 end
159 148
160 context "version" do 149 context "version" do
161 should "be rendered" do 150 should "be rendered" do
151 @response.body = @gantt.subjects
162 assert_select "div.version-name a", /#{@version.name}/ 152 assert_select "div.version-name a", /#{@version.name}/
163 end 153 end
164 154
165 should "be indented 24 (one level)" do 155 should "be indented 24 (one level)" do
156 @response.body = @gantt.subjects
166 assert_select "div.version-name[style*=left:24px]" 157 assert_select "div.version-name[style*=left:24px]"
167 end 158 end
168 end 159
169 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
171 end
172
170 context "issue" do 173 context "issue" do
171 should "be rendered" do 174 should "be rendered" do
175 @response.body = @gantt.subjects
172 assert_select "div.issue-subject", /#{@issue.subject}/ 176 assert_select "div.issue-subject", /#{@issue.subject}/
173 end 177 end
174 178
175 should "be indented 44 (two levels)" do 179 should "be indented 44 (two levels)" do
180 @response.body = @gantt.subjects
176 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
207 end
208
209 context "with subtasks" do
210 setup do
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))
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))
215 end
216
217 should "indent subtasks" do
218 @response.body = @gantt.subjects
219 # parent task 44px
220 assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/
221 # children 64px
222 assert_select "div.issue-subject[style*=left:64px]", /child1/
223 assert_select "div.issue-subject[style*=left:64px]", /child2/
224 # grandchild 84px
225 assert_select "div.issue-subject[style*=left:84px]", /grandchild/, @response.body
226 end
177 end 227 end
178 end 228 end
179 end 229 end
180 230
181 context "#lines" do 231 context "#lines" do
198 @response.body = @gantt.lines 248 @response.body = @gantt.lines
199 end 249 end
200 250
201 context "project" do 251 context "project" do
202 should "be rendered" do 252 should "be rendered" do
203 assert_select "div.project_todo" 253 assert_select "div.project.task_todo"
204 assert_select "div.project-line.starting" 254 assert_select "div.project.starting"
205 assert_select "div.project-line.ending" 255 assert_select "div.project.ending"
206 assert_select "div.label.project-name", /#{@project.name}/ 256 assert_select "div.label.project", /#{@project.name}/
207 end 257 end
208 end 258 end
209 259
210 context "version" do 260 context "version" do
211 should "be rendered" do 261 should "be rendered" do
212 assert_select "div.milestone_todo" 262 assert_select "div.version.task_todo"
213 assert_select "div.milestone.starting" 263 assert_select "div.version.starting"
214 assert_select "div.milestone.ending" 264 assert_select "div.version.ending"
215 assert_select "div.label.version-name", /#{@version.name}/ 265 assert_select "div.label.version", /#{@version.name}/
216 end 266 end
217 end 267 end
218 268
219 context "issue" do 269 context "issue" do
220 should "be rendered" do 270 should "be rendered" do
221 assert_select "div.task_todo" 271 assert_select "div.task_todo"
222 assert_select "div.label.issue-name", /#{@issue.done_ratio}/ 272 assert_select "div.task.label", /#{@issue.done_ratio}/
223 assert_select "div.tooltip", /#{@issue.subject}/ 273 assert_select "div.tooltip", /#{@issue.subject}/
224 end 274 end
225 end 275 end
226 end 276 end
227 277
292 @project.issues << Issue.generate!(:fixed_version => @version, 342 @project.issues << Issue.generate!(:fixed_version => @version,
293 :subject => "gantt#line_for_project", 343 :subject => "gantt#line_for_project",
294 :tracker => @tracker, 344 :tracker => @tracker,
295 :project => @project, 345 :project => @project,
296 :done_ratio => 30, 346 :done_ratio => 30,
297 :start_date => Date.yesterday, 347 :start_date => 1.week.ago.to_date,
298 :due_date => 1.week.from_now.to_date) 348 :due_date => 1.week.from_now.to_date)
299 end 349 end
300 350
301 context ":html format" do 351 context ":html format" do
302 context "todo line" do 352 context "todo line" do
303 should "start from the starting point on the left" do 353 should "start from the starting point on the left" do
304 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 354 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
305 assert_select "div.project_todo[style*=left:52px]" 355 assert_select "div.project.task_todo[style*=left:28px]", true, @response.body
306 end 356 end
307 357
308 should "be the total width of the project" do 358 should "be the total width of the project" do
309 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 359 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
310 assert_select "div.project_todo[style*=width:31px]" 360 assert_select "div.project.task_todo[style*=width:58px]", true, @response.body
311 end 361 end
312 362
313 end 363 end
314 364
315 context "late line" do 365 context "late line" do
316 should "start from the starting point on the left" do 366 should_eventually "start from the starting point on the left" do
317 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 367 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
318 assert_select "div.project_late[style*=left:52px]" 368 assert_select "div.project.task_late[style*=left:28px]", true, @response.body
319 end 369 end
320 370
321 should "be the total delayed width of the project" do 371 should_eventually "be the total delayed width of the project" do
322 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 372 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
323 assert_select "div.project_late[style*=width:6px]" 373 assert_select "div.project.task_late[style*=width:30px]", true, @response.body
324 end 374 end
325 end 375 end
326 376
327 context "done line" do 377 context "done line" do
328 should "start from the starting point on the left" do 378 should_eventually "start from the starting point on the left" do
329 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 379 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
330 assert_select "div.project_done[style*=left:52px]" 380 assert_select "div.project.task_done[style*=left:28px]", true, @response.body
331 end 381 end
332 382
333 should "Be the total done width of the project" do 383 should_eventually "Be the total done width of the project" do
334 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 384 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
335 assert_select "div.project_done[style*=left:52px]" 385 assert_select "div.project.task_done[style*=width:18px]", true, @response.body
336 end 386 end
337 end 387 end
338 388
339 context "starting marker" do 389 context "starting marker" do
340 should "not appear if the starting point is off the gantt chart" do 390 should "not appear if the starting point is off the gantt chart" do
341 # Shift the date range of the chart 391 # Shift the date range of the chart
342 @gantt.instance_variable_set('@date_from', Date.today) 392 @gantt.instance_variable_set('@date_from', Date.today)
343 393
344 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 394 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
345 assert_select "div.project-line.starting", false 395 assert_select "div.project.starting", false, @response.body
346 end 396 end
347 397
348 should "appear at the starting point" do 398 should "appear at the starting point" do
349 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 399 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
350 assert_select "div.project-line.starting[style*=left:52px]" 400 assert_select "div.project.starting[style*=left:28px]", true, @response.body
351 end 401 end
352 end 402 end
353 403
354 context "ending marker" do 404 context "ending marker" do
355 should "not appear if the starting point is off the gantt chart" do 405 should "not appear if the starting point is off the gantt chart" do
356 # Shift the date range of the chart 406 # Shift the date range of the chart
357 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) 407 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
358 408
359 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 409 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
360 assert_select "div.project-line.ending", false 410 assert_select "div.project.ending", false, @response.body
361 411
362 end 412 end
363 413
364 should "appear at the end of the date range" do 414 should "appear at the end of the date range" do
365 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 415 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
366 assert_select "div.project-line.ending[style*=left:84px]" 416 assert_select "div.project.ending[style*=left:88px]", true, @response.body
367 end 417 end
368 end 418 end
369 419
370 context "status content" do 420 context "status content" do
371 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
372 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) 422 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
373 423
374 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 424 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
375 assert_select "div.project-name", /#{@project.name}/ 425 assert_select "div.project.label", /#{@project.name}/
376 end 426 end
377 427
378 should "show the project name" do 428 should "show the project name" do
379 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 429 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
380 assert_select "div.project-name", /#{@project.name}/ 430 assert_select "div.project.label", /#{@project.name}/
381 end 431 end
382 432
383 should "show the percent complete" do 433 should_eventually "show the percent complete" do
384 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) 434 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
385 assert_select "div.project-name", /0%/ 435 assert_select "div.project.label", /0%/
386 end 436 end
387 end 437 end
388 end 438 end
389 439
390 should "test the PNG format" 440 should "test the PNG format"
459 @project.issues << Issue.generate!(:fixed_version => @version, 509 @project.issues << Issue.generate!(:fixed_version => @version,
460 :subject => "gantt#line_for_project", 510 :subject => "gantt#line_for_project",
461 :tracker => @tracker, 511 :tracker => @tracker,
462 :project => @project, 512 :project => @project,
463 :done_ratio => 30, 513 :done_ratio => 30,
464 :start_date => Date.yesterday, 514 :start_date => 1.week.ago.to_date,
465 :due_date => 1.week.from_now.to_date) 515 :due_date => 1.week.from_now.to_date)
466 end 516 end
467 517
468 context ":html format" do 518 context ":html format" do
469 context "todo line" do 519 context "todo line" do
470 should "start from the starting point on the left" do 520 should "start from the starting point on the left" do
471 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 521 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
472 assert_select "div.milestone_todo[style*=left:52px]" 522 assert_select "div.version.task_todo[style*=left:28px]", true, @response.body
473 end 523 end
474 524
475 should "be the total width of the version" do 525 should "be the total width of the version" do
476 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 526 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
477 assert_select "div.milestone_todo[style*=width:31px]" 527 assert_select "div.version.task_todo[style*=width:58px]", true, @response.body
478 end 528 end
479 529
480 end 530 end
481 531
482 context "late line" do 532 context "late line" do
483 should "start from the starting point on the left" do 533 should "start from the starting point on the left" do
484 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 534 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
485 assert_select "div.milestone_late[style*=left:52px]" 535 assert_select "div.version.task_late[style*=left:28px]", true, @response.body
486 end 536 end
487 537
488 should "be the total delayed width of the version" do 538 should "be the total delayed width of the version" do
489 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 539 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
490 assert_select "div.milestone_late[style*=width:6px]" 540 assert_select "div.version.task_late[style*=width:30px]", true, @response.body
491 end 541 end
492 end 542 end
493 543
494 context "done line" do 544 context "done line" do
495 should "start from the starting point on the left" do 545 should "start from the starting point on the left" do
496 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 546 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
497 assert_select "div.milestone_done[style*=left:52px]" 547 assert_select "div.version.task_done[style*=left:28px]", true, @response.body
498 end 548 end
499 549
500 should "Be the total done width of the version" do 550 should "be the total done width of the version" do
501 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 551 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
502 assert_select "div.milestone_done[style*=left:52px]" 552 assert_select "div.version.task_done[style*=width:16px]", true, @response.body
503 end 553 end
504 end 554 end
505 555
506 context "starting marker" do 556 context "starting marker" do
507 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
508 # Shift the date range of the chart 558 # Shift the date range of the chart
509 @gantt.instance_variable_set('@date_from', Date.today) 559 @gantt.instance_variable_set('@date_from', Date.today)
510 560
511 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 561 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
512 assert_select "div.milestone.starting", false 562 assert_select "div.version.starting", false
513 end 563 end
514 564
515 should "appear at the starting point" do 565 should "appear at the starting point" do
516 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 566 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
517 assert_select "div.milestone.starting[style*=left:52px]" 567 assert_select "div.version.starting[style*=left:28px]", true, @response.body
518 end 568 end
519 end 569 end
520 570
521 context "ending marker" do 571 context "ending marker" do
522 should "not appear if the starting point is off the gantt chart" do 572 should "not appear if the starting point is off the gantt chart" do
523 # Shift the date range of the chart 573 # Shift the date range of the chart
524 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) 574 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
525 575
526 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 576 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
527 assert_select "div.milestone.ending", false 577 assert_select "div.version.ending", false
528 578
529 end 579 end
530 580
531 should "appear at the end of the date range" do 581 should "appear at the end of the date range" do
532 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 582 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
533 assert_select "div.milestone.ending[style*=left:84px]" 583 assert_select "div.version.ending[style*=left:88px]", true, @response.body
534 end 584 end
535 end 585 end
536 586
537 context "status content" do 587 context "status content" do
538 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
539 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) 589 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
540 590
541 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 591 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
542 assert_select "div.version-name", /#{@version.name}/ 592 assert_select "div.version.label", /#{@version.name}/
543 end 593 end
544 594
545 should "show the version name" do 595 should "show the version name" do
546 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 596 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
547 assert_select "div.version-name", /#{@version.name}/ 597 assert_select "div.version.label", /#{@version.name}/
548 end 598 end
549 599
550 should "show the percent complete" do 600 should "show the percent complete" do
551 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) 601 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
552 assert_select "div.version-name", /30%/ 602 assert_select "div.version.label", /30%/
553 end 603 end
554 end 604 end
555 end 605 end
556 606
557 should "test the PNG format" 607 should "test the PNG format"
618 @issue = Issue.generate!(:fixed_version => @version, 668 @issue = Issue.generate!(:fixed_version => @version,
619 :subject => "gantt#line_for_project", 669 :subject => "gantt#line_for_project",
620 :tracker => @tracker, 670 :tracker => @tracker,
621 :project => @project, 671 :project => @project,
622 :done_ratio => 30, 672 :done_ratio => 30,
623 :start_date => Date.yesterday, 673 :start_date => 1.week.ago.to_date,
624 :due_date => 1.week.from_now.to_date) 674 :due_date => 1.week.from_now.to_date)
625 @project.issues << @issue 675 @project.issues << @issue
626 end 676 end
627 677
628 context ":html format" do 678 context ":html format" do
629 context "todo line" do 679 context "todo line" do
630 should "start from the starting point on the left" do 680 should "start from the starting point on the left" do
631 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 681 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
632 assert_select "div.task_todo[style*=left:52px]" 682 assert_select "div.task_todo[style*=left:28px]", true, @response.body
633 end 683 end
634 684
635 should "be the total width of the issue" do 685 should "be the total width of the issue" do
636 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 686 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
637 assert_select "div.task_todo[style*=width:34px]" 687 assert_select "div.task_todo[style*=width:58px]", true, @response.body
638 end 688 end
639 689
640 end 690 end
641 691
642 context "late line" do 692 context "late line" do
643 should "start from the starting point on the left" do 693 should "start from the starting point on the left" do
644 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 694 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
645 assert_select "div.task_late[style*=left:52px]" 695 assert_select "div.task_late[style*=left:28px]", true, @response.body
646 end 696 end
647 697
648 should "be the total delayed width of the issue" do 698 should "be the total delayed width of the issue" do
649 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 699 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
650 assert_select "div.task_late[style*=width:6px]" 700 assert_select "div.task_late[style*=width:30px]", true, @response.body
651 end 701 end
652 end 702 end
653 703
654 context "done line" do 704 context "done line" do
655 should "start from the starting point on the left" do 705 should "start from the starting point on the left" do
656 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 706 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
657 assert_select "div.task_done[style*=left:52px]" 707 assert_select "div.task_done[style*=left:28px]", true, @response.body
658 end 708 end
659 709
660 should "Be the total done width of the issue" do 710 should "be the total done width of the issue" do
661 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 711 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
662 assert_select "div.task_done[style*=left:52px]" 712 # 15 days * 4 px * 30% - 2 px for borders = 16 px
713 assert_select "div.task_done[style*=width:16px]", true, @response.body
714 end
715
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)
718
719 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
720 assert_select "div.task_done[style*=left:0px]", 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
663 end 739 end
664 end 740 end
665 741
666 context "status content" do 742 context "status content" do
667 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
668 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) 744 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
669 745
670 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 746 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
671 assert_select "div.issue-name" 747 assert_select "div.task.label", true, @response.body
672 end 748 end
673 749
674 should "show the issue status" do 750 should "show the issue status" do
675 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 751 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
676 assert_select "div.issue-name", /#{@issue.status.name}/ 752 assert_select "div.task.label", /#{@issue.status.name}/
677 end 753 end
678 754
679 should "show the percent complete" do 755 should "show the percent complete" do
680 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) 756 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
681 assert_select "div.issue-name", /30%/ 757 assert_select "div.task.label", /30%/
682 end 758 end
683 end 759 end
684 end 760 end
685 761
686 should "have an issue tooltip" do 762 should "have an issue tooltip" do