annotate test/unit/lib/redmine/helpers/gantt_test.rb @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents af80e5618e9b
children cbce1fd3b1b7
rev   line source
chris@22 1 # redMine - project management software
chris@22 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
chris@22 3 #
chris@22 4 # This program is free software; you can redistribute it and/or
chris@22 5 # modify it under the terms of the GNU General Public License
chris@22 6 # as published by the Free Software Foundation; either version 2
chris@22 7 # of the License, or (at your option) any later version.
chris@22 8 #
chris@22 9 # This program is distributed in the hope that it will be useful,
chris@22 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
chris@22 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
chris@22 12 # GNU General Public License for more details.
chris@22 13 #
chris@22 14 # You should have received a copy of the GNU General Public License
chris@22 15 # along with this program; if not, write to the Free Software
chris@22 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
chris@22 17
Chris@117 18 require File.expand_path('../../../../../test_helper', __FILE__)
chris@22 19
chris@22 20 class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
chris@22 21 # Utility methods and classes so assert_select can be used.
chris@22 22 class GanttViewTest < ActionView::Base
chris@22 23 include ActionView::Helpers::UrlHelper
chris@22 24 include ActionView::Helpers::TextHelper
chris@22 25 include ActionController::UrlWriter
chris@22 26 include ApplicationHelper
chris@22 27 include ProjectsHelper
chris@22 28 include IssuesHelper
chris@22 29
chris@22 30 def self.default_url_options
chris@22 31 {:only_path => true }
chris@22 32 end
chris@22 33
chris@22 34 end
chris@22 35
chris@22 36 include ActionController::Assertions::SelectorAssertions
chris@22 37
chris@22 38 def setup
chris@22 39 @response = ActionController::TestResponse.new
chris@22 40 # Fixtures
chris@22 41 ProjectCustomField.delete_all
chris@22 42 Project.destroy_all
chris@22 43
chris@22 44 User.current = User.find(1)
chris@22 45 end
chris@22 46
chris@22 47 def build_view
chris@22 48 @view = GanttViewTest.new
chris@22 49 end
chris@22 50
chris@22 51 def html_document
chris@22 52 HTML::Document.new(@response.body)
chris@22 53 end
chris@22 54
chris@22 55 # Creates a Gantt chart for a 4 week span
Chris@117 56 def create_gantt(project=Project.generate!, options={})
chris@22 57 @project = project
Chris@117 58 @gantt = Redmine::Helpers::Gantt.new(options)
chris@22 59 @gantt.project = @project
chris@22 60 @gantt.query = Query.generate_default!(:project => @project)
chris@22 61 @gantt.view = build_view
Chris@117 62 @gantt.instance_variable_set('@date_from', options[:date_from] || 2.weeks.ago.to_date)
Chris@117 63 @gantt.instance_variable_set('@date_to', options[:date_to] || 2.weeks.from_now.to_date)
chris@22 64 end
chris@22 65
chris@22 66 context "#number_of_rows" do
chris@22 67
chris@22 68 context "with one project" do
chris@22 69 should "return the number of rows just for that project"
chris@22 70 end
chris@22 71
chris@22 72 context "with no project" do
chris@22 73 should "return the total number of rows for all the projects, resursively"
chris@22 74 end
chris@22 75
Chris@117 76 should "not exceed max_rows option" do
Chris@117 77 p = Project.generate!
Chris@117 78 5.times do
Chris@117 79 Issue.generate_for_project!(p)
Chris@117 80 end
Chris@117 81
Chris@117 82 create_gantt(p)
Chris@117 83 @gantt.render
Chris@117 84 assert_equal 6, @gantt.number_of_rows
Chris@117 85 assert !@gantt.truncated
Chris@117 86
Chris@117 87 create_gantt(p, :max_rows => 3)
Chris@117 88 @gantt.render
Chris@117 89 assert_equal 3, @gantt.number_of_rows
Chris@117 90 assert @gantt.truncated
Chris@117 91 end
chris@22 92 end
chris@22 93
chris@22 94 context "#number_of_rows_on_project" do
chris@22 95 setup do
chris@22 96 create_gantt
chris@22 97 end
chris@22 98
chris@22 99 should "clear the @query.project so cross-project issues and versions can be counted" do
chris@22 100 assert @gantt.query.project
chris@22 101 @gantt.number_of_rows_on_project(@project)
chris@22 102 assert_nil @gantt.query.project
chris@22 103 end
chris@22 104
chris@22 105 should "count 1 for the project itself" do
chris@22 106 assert_equal 1, @gantt.number_of_rows_on_project(@project)
chris@22 107 end
chris@22 108
chris@22 109 should "count the number of issues without a version" do
chris@22 110 @project.issues << Issue.generate_for_project!(@project, :fixed_version => nil)
chris@22 111 assert_equal 2, @gantt.number_of_rows_on_project(@project)
chris@22 112 end
chris@22 113
chris@22 114 should "count the number of versions" do
chris@22 115 @project.versions << Version.generate!
chris@22 116 @project.versions << Version.generate!
chris@22 117 assert_equal 3, @gantt.number_of_rows_on_project(@project)
chris@22 118 end
chris@22 119
chris@22 120 should "count the number of issues on versions, including cross-project" do
chris@22 121 version = Version.generate!
chris@22 122 @project.versions << version
chris@22 123 @project.issues << Issue.generate_for_project!(@project, :fixed_version => version)
chris@22 124
chris@22 125 assert_equal 3, @gantt.number_of_rows_on_project(@project)
chris@22 126 end
chris@22 127
chris@22 128 should "recursive and count the number of rows on each subproject" do
chris@22 129 @project.versions << Version.generate! # +1
chris@22 130
chris@22 131 @subproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
chris@22 132 @subproject.set_parent!(@project)
chris@22 133 @subproject.issues << Issue.generate_for_project!(@subproject) # +1
chris@22 134 @subproject.issues << Issue.generate_for_project!(@subproject) # +1
chris@22 135
chris@22 136 @subsubproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
chris@22 137 @subsubproject.set_parent!(@subproject)
chris@22 138 @subsubproject.issues << Issue.generate_for_project!(@subsubproject) # +1
chris@22 139
chris@22 140 assert_equal 7, @gantt.number_of_rows_on_project(@project) # +1 for self
chris@22 141 end
chris@22 142 end
chris@22 143
chris@22 144 # TODO: more of an integration test
chris@22 145 context "#subjects" do
chris@22 146 setup do
chris@22 147 create_gantt
chris@22 148 @project.enabled_module_names = [:issue_tracking]
chris@22 149 @tracker = Tracker.generate!
chris@22 150 @project.trackers << @tracker
chris@22 151 @version = Version.generate!(:effective_date => 1.week.from_now.to_date, :sharing => 'none')
chris@22 152 @project.versions << @version
chris@22 153
chris@22 154 @issue = Issue.generate!(:fixed_version => @version,
chris@22 155 :subject => "gantt#line_for_project",
chris@22 156 :tracker => @tracker,
chris@22 157 :project => @project,
chris@22 158 :done_ratio => 30,
chris@22 159 :start_date => Date.yesterday,
chris@22 160 :due_date => 1.week.from_now.to_date)
Chris@117 161 @project.issues << @issue
chris@22 162 end
Chris@117 163
chris@22 164 context "project" do
chris@22 165 should "be rendered" do
Chris@117 166 @response.body = @gantt.subjects
chris@22 167 assert_select "div.project-name a", /#{@project.name}/
chris@22 168 end
Chris@117 169
chris@22 170 should "have an indent of 4" do
Chris@117 171 @response.body = @gantt.subjects
chris@22 172 assert_select "div.project-name[style*=left:4px]"
chris@22 173 end
chris@22 174 end
Chris@117 175
chris@22 176 context "version" do
chris@22 177 should "be rendered" do
Chris@117 178 @response.body = @gantt.subjects
chris@22 179 assert_select "div.version-name a", /#{@version.name}/
chris@22 180 end
Chris@117 181
chris@22 182 should "be indented 24 (one level)" do
Chris@117 183 @response.body = @gantt.subjects
chris@22 184 assert_select "div.version-name[style*=left:24px]"
chris@22 185 end
chris@22 186 end
Chris@117 187
chris@22 188 context "issue" do
chris@22 189 should "be rendered" do
Chris@117 190 @response.body = @gantt.subjects
chris@22 191 assert_select "div.issue-subject", /#{@issue.subject}/
chris@22 192 end
Chris@117 193
chris@22 194 should "be indented 44 (two levels)" do
Chris@117 195 @response.body = @gantt.subjects
chris@22 196 assert_select "div.issue-subject[style*=left:44px]"
chris@22 197 end
Chris@117 198
Chris@117 199 context "with subtasks" do
Chris@117 200 setup do
Chris@117 201 attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version}
Chris@117 202 @child1 = Issue.generate!(attrs.merge(:subject => 'child1', :parent_issue_id => @issue.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date))
Chris@117 203 @child2 = Issue.generate!(attrs.merge(:subject => 'child2', :parent_issue_id => @issue.id, :start_date => Date.today, :due_date => 1.week.from_now.to_date))
Chris@117 204 @grandchild = Issue.generate!(attrs.merge(:subject => 'grandchild', :parent_issue_id => @child1.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date))
Chris@117 205 end
Chris@117 206
Chris@117 207 should "indent subtasks" do
Chris@117 208 @response.body = @gantt.subjects
Chris@117 209 # parent task 44px
Chris@117 210 assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/
Chris@117 211 # children 64px
Chris@117 212 assert_select "div.issue-subject[style*=left:64px]", /child1/
Chris@117 213 assert_select "div.issue-subject[style*=left:64px]", /child2/
Chris@117 214 # grandchild 84px
Chris@117 215 assert_select "div.issue-subject[style*=left:84px]", /grandchild/, @response.body
Chris@117 216 end
Chris@117 217 end
chris@22 218 end
chris@22 219 end
chris@22 220
chris@22 221 context "#lines" do
chris@22 222 setup do
chris@22 223 create_gantt
chris@22 224 @project.enabled_module_names = [:issue_tracking]
chris@22 225 @tracker = Tracker.generate!
chris@22 226 @project.trackers << @tracker
chris@22 227 @version = Version.generate!(:effective_date => 1.week.from_now.to_date)
chris@22 228 @project.versions << @version
chris@22 229 @issue = Issue.generate!(:fixed_version => @version,
chris@22 230 :subject => "gantt#line_for_project",
chris@22 231 :tracker => @tracker,
chris@22 232 :project => @project,
chris@22 233 :done_ratio => 30,
chris@22 234 :start_date => Date.yesterday,
chris@22 235 :due_date => 1.week.from_now.to_date)
chris@22 236 @project.issues << @issue
chris@22 237
chris@22 238 @response.body = @gantt.lines
chris@22 239 end
chris@22 240
chris@22 241 context "project" do
chris@22 242 should "be rendered" do
Chris@117 243 assert_select "div.project.task_todo"
Chris@117 244 assert_select "div.project.starting"
Chris@117 245 assert_select "div.project.ending"
Chris@117 246 assert_select "div.label.project", /#{@project.name}/
chris@22 247 end
chris@22 248 end
chris@22 249
chris@22 250 context "version" do
chris@22 251 should "be rendered" do
Chris@117 252 assert_select "div.version.task_todo"
Chris@117 253 assert_select "div.version.starting"
Chris@117 254 assert_select "div.version.ending"
Chris@117 255 assert_select "div.label.version", /#{@version.name}/
chris@22 256 end
chris@22 257 end
chris@22 258
chris@22 259 context "issue" do
chris@22 260 should "be rendered" do
chris@22 261 assert_select "div.task_todo"
Chris@117 262 assert_select "div.task.label", /#{@issue.done_ratio}/
chris@22 263 assert_select "div.tooltip", /#{@issue.subject}/
chris@22 264 end
chris@22 265 end
chris@22 266 end
chris@22 267
chris@22 268 context "#render_project" do
chris@22 269 should "be tested"
chris@22 270 end
chris@22 271
chris@22 272 context "#render_issues" do
chris@22 273 should "be tested"
chris@22 274 end
chris@22 275
chris@22 276 context "#render_version" do
chris@22 277 should "be tested"
chris@22 278 end
chris@22 279
chris@22 280 context "#subject_for_project" do
chris@22 281 setup do
chris@22 282 create_gantt
chris@22 283 end
chris@22 284
chris@22 285 context ":html format" do
chris@22 286 should "add an absolute positioned div" do
chris@22 287 @response.body = @gantt.subject_for_project(@project, {:format => :html})
chris@22 288 assert_select "div[style*=absolute]"
chris@22 289 end
chris@22 290
chris@22 291 should "use the indent option to move the div to the right" do
chris@22 292 @response.body = @gantt.subject_for_project(@project, {:format => :html, :indent => 40})
chris@22 293 assert_select "div[style*=left:40]"
chris@22 294 end
chris@22 295
chris@22 296 should "include the project name" do
chris@22 297 @response.body = @gantt.subject_for_project(@project, {:format => :html})
chris@22 298 assert_select 'div', :text => /#{@project.name}/
chris@22 299 end
chris@22 300
chris@22 301 should "include a link to the project" do
chris@22 302 @response.body = @gantt.subject_for_project(@project, {:format => :html})
chris@22 303 assert_select 'a[href=?]', "/projects/#{@project.identifier}", :text => /#{@project.name}/
chris@22 304 end
chris@22 305
chris@22 306 should "style overdue projects" do
chris@22 307 @project.enabled_module_names = [:issue_tracking]
chris@22 308 @project.versions << Version.generate!(:effective_date => Date.yesterday)
chris@22 309
chris@22 310 assert @project.overdue?, "Need an overdue project for this test"
chris@22 311 @response.body = @gantt.subject_for_project(@project, {:format => :html})
chris@22 312
chris@22 313 assert_select 'div span.project-overdue'
chris@22 314 end
chris@22 315
chris@22 316
chris@22 317 end
chris@22 318
chris@22 319 should "test the PNG format"
chris@22 320 should "test the PDF format"
chris@22 321 end
chris@22 322
chris@22 323 context "#line_for_project" do
chris@22 324 setup do
chris@22 325 create_gantt
chris@22 326 @project.enabled_module_names = [:issue_tracking]
chris@22 327 @tracker = Tracker.generate!
chris@22 328 @project.trackers << @tracker
chris@22 329 @version = Version.generate!(:effective_date => Date.yesterday)
chris@22 330 @project.versions << @version
chris@22 331
chris@22 332 @project.issues << Issue.generate!(:fixed_version => @version,
chris@22 333 :subject => "gantt#line_for_project",
chris@22 334 :tracker => @tracker,
chris@22 335 :project => @project,
chris@22 336 :done_ratio => 30,
Chris@117 337 :start_date => 1.week.ago.to_date,
chris@22 338 :due_date => 1.week.from_now.to_date)
chris@22 339 end
chris@22 340
chris@22 341 context ":html format" do
chris@22 342 context "todo line" do
chris@22 343 should "start from the starting point on the left" do
chris@22 344 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 345 assert_select "div.project.task_todo[style*=left:28px]", true, @response.body
chris@22 346 end
chris@22 347
chris@22 348 should "be the total width of the project" do
chris@22 349 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 350 assert_select "div.project.task_todo[style*=width:58px]", true, @response.body
chris@22 351 end
chris@22 352
chris@22 353 end
chris@22 354
chris@22 355 context "late line" do
Chris@117 356 should_eventually "start from the starting point on the left" do
chris@22 357 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 358 assert_select "div.project.task_late[style*=left:28px]", true, @response.body
chris@22 359 end
chris@22 360
Chris@117 361 should_eventually "be the total delayed width of the project" do
chris@22 362 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 363 assert_select "div.project.task_late[style*=width:30px]", true, @response.body
chris@22 364 end
chris@22 365 end
chris@22 366
chris@22 367 context "done line" do
Chris@117 368 should_eventually "start from the starting point on the left" do
chris@22 369 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 370 assert_select "div.project.task_done[style*=left:28px]", true, @response.body
chris@22 371 end
chris@22 372
Chris@117 373 should_eventually "Be the total done width of the project" do
chris@22 374 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 375 assert_select "div.project.task_done[style*=width:18px]", true, @response.body
chris@22 376 end
chris@22 377 end
chris@22 378
chris@22 379 context "starting marker" do
chris@22 380 should "not appear if the starting point is off the gantt chart" do
chris@22 381 # Shift the date range of the chart
chris@22 382 @gantt.instance_variable_set('@date_from', Date.today)
chris@22 383
chris@22 384 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 385 assert_select "div.project.starting", false, @response.body
chris@22 386 end
chris@22 387
chris@22 388 should "appear at the starting point" do
chris@22 389 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 390 assert_select "div.project.starting[style*=left:28px]", true, @response.body
chris@22 391 end
chris@22 392 end
chris@22 393
chris@22 394 context "ending marker" do
chris@22 395 should "not appear if the starting point is off the gantt chart" do
chris@22 396 # Shift the date range of the chart
chris@22 397 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
chris@22 398
chris@22 399 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 400 assert_select "div.project.ending", false, @response.body
chris@22 401
chris@22 402 end
chris@22 403
chris@22 404 should "appear at the end of the date range" do
chris@22 405 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 406 assert_select "div.project.ending[style*=left:88px]", true, @response.body
chris@22 407 end
chris@22 408 end
chris@22 409
chris@22 410 context "status content" do
chris@22 411 should "appear at the far left, even if it's far in the past" do
chris@22 412 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
chris@22 413
chris@22 414 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 415 assert_select "div.project.label", /#{@project.name}/
chris@22 416 end
chris@22 417
chris@22 418 should "show the project name" do
chris@22 419 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 420 assert_select "div.project.label", /#{@project.name}/
chris@22 421 end
chris@22 422
Chris@117 423 should_eventually "show the percent complete" do
chris@22 424 @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@117 425 assert_select "div.project.label", /0%/
chris@22 426 end
chris@22 427 end
chris@22 428 end
chris@22 429
chris@22 430 should "test the PNG format"
chris@22 431 should "test the PDF format"
chris@22 432 end
chris@22 433
chris@22 434 context "#subject_for_version" do
chris@22 435 setup do
chris@22 436 create_gantt
chris@22 437 @project.enabled_module_names = [:issue_tracking]
chris@22 438 @tracker = Tracker.generate!
chris@22 439 @project.trackers << @tracker
chris@22 440 @version = Version.generate!(:effective_date => Date.yesterday)
chris@22 441 @project.versions << @version
chris@22 442
chris@22 443 @project.issues << Issue.generate!(:fixed_version => @version,
chris@22 444 :subject => "gantt#subject_for_version",
chris@22 445 :tracker => @tracker,
chris@22 446 :project => @project,
chris@22 447 :start_date => Date.today)
chris@22 448
chris@22 449 end
chris@22 450
chris@22 451 context ":html format" do
chris@22 452 should "add an absolute positioned div" do
chris@22 453 @response.body = @gantt.subject_for_version(@version, {:format => :html})
chris@22 454 assert_select "div[style*=absolute]"
chris@22 455 end
chris@22 456
chris@22 457 should "use the indent option to move the div to the right" do
chris@22 458 @response.body = @gantt.subject_for_version(@version, {:format => :html, :indent => 40})
chris@22 459 assert_select "div[style*=left:40]"
chris@22 460 end
chris@22 461
chris@22 462 should "include the version name" do
chris@22 463 @response.body = @gantt.subject_for_version(@version, {:format => :html})
chris@22 464 assert_select 'div', :text => /#{@version.name}/
chris@22 465 end
chris@22 466
chris@22 467 should "include a link to the version" do
chris@22 468 @response.body = @gantt.subject_for_version(@version, {:format => :html})
chris@22 469 assert_select 'a[href=?]', Regexp.escape("/versions/show/#{@version.to_param}"), :text => /#{@version.name}/
chris@22 470 end
chris@22 471
chris@22 472 should "style late versions" do
chris@22 473 assert @version.overdue?, "Need an overdue version for this test"
chris@22 474 @response.body = @gantt.subject_for_version(@version, {:format => :html})
chris@22 475
chris@22 476 assert_select 'div span.version-behind-schedule'
chris@22 477 end
chris@22 478
chris@22 479 should "style behind schedule versions" do
chris@22 480 assert @version.behind_schedule?, "Need a behind schedule version for this test"
chris@22 481 @response.body = @gantt.subject_for_version(@version, {:format => :html})
chris@22 482
chris@22 483 assert_select 'div span.version-behind-schedule'
chris@22 484 end
chris@22 485 end
chris@22 486 should "test the PNG format"
chris@22 487 should "test the PDF format"
chris@22 488 end
chris@22 489
chris@22 490 context "#line_for_version" do
chris@22 491 setup do
chris@22 492 create_gantt
chris@22 493 @project.enabled_module_names = [:issue_tracking]
chris@22 494 @tracker = Tracker.generate!
chris@22 495 @project.trackers << @tracker
chris@22 496 @version = Version.generate!(:effective_date => 1.week.from_now.to_date)
chris@22 497 @project.versions << @version
chris@22 498
chris@22 499 @project.issues << Issue.generate!(:fixed_version => @version,
chris@22 500 :subject => "gantt#line_for_project",
chris@22 501 :tracker => @tracker,
chris@22 502 :project => @project,
chris@22 503 :done_ratio => 30,
Chris@117 504 :start_date => 1.week.ago.to_date,
chris@22 505 :due_date => 1.week.from_now.to_date)
chris@22 506 end
chris@22 507
chris@22 508 context ":html format" do
chris@22 509 context "todo line" do
chris@22 510 should "start from the starting point on the left" do
chris@22 511 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 512 assert_select "div.version.task_todo[style*=left:28px]", true, @response.body
chris@22 513 end
chris@22 514
chris@22 515 should "be the total width of the version" do
chris@22 516 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 517 assert_select "div.version.task_todo[style*=width:58px]", true, @response.body
chris@22 518 end
chris@22 519
chris@22 520 end
chris@22 521
chris@22 522 context "late line" do
chris@22 523 should "start from the starting point on the left" do
chris@22 524 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 525 assert_select "div.version.task_late[style*=left:28px]", true, @response.body
chris@22 526 end
chris@22 527
chris@22 528 should "be the total delayed width of the version" do
chris@22 529 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 530 assert_select "div.version.task_late[style*=width:30px]", true, @response.body
chris@22 531 end
chris@22 532 end
chris@22 533
chris@22 534 context "done line" do
chris@22 535 should "start from the starting point on the left" do
chris@22 536 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 537 assert_select "div.version.task_done[style*=left:28px]", true, @response.body
chris@22 538 end
chris@22 539
chris@22 540 should "Be the total done width of the version" do
chris@22 541 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 542 assert_select "div.version.task_done[style*=width:18px]", true, @response.body
chris@22 543 end
chris@22 544 end
chris@22 545
chris@22 546 context "starting marker" do
chris@22 547 should "not appear if the starting point is off the gantt chart" do
chris@22 548 # Shift the date range of the chart
chris@22 549 @gantt.instance_variable_set('@date_from', Date.today)
chris@22 550
chris@22 551 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 552 assert_select "div.version.starting", false
chris@22 553 end
chris@22 554
chris@22 555 should "appear at the starting point" do
chris@22 556 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 557 assert_select "div.version.starting[style*=left:28px]", true, @response.body
chris@22 558 end
chris@22 559 end
chris@22 560
chris@22 561 context "ending marker" do
chris@22 562 should "not appear if the starting point is off the gantt chart" do
chris@22 563 # Shift the date range of the chart
chris@22 564 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
chris@22 565
chris@22 566 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 567 assert_select "div.version.ending", false
chris@22 568
chris@22 569 end
chris@22 570
chris@22 571 should "appear at the end of the date range" do
chris@22 572 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 573 assert_select "div.version.ending[style*=left:88px]", true, @response.body
chris@22 574 end
chris@22 575 end
chris@22 576
chris@22 577 context "status content" do
chris@22 578 should "appear at the far left, even if it's far in the past" do
chris@22 579 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
chris@22 580
chris@22 581 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 582 assert_select "div.version.label", /#{@version.name}/
chris@22 583 end
chris@22 584
chris@22 585 should "show the version name" do
chris@22 586 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 587 assert_select "div.version.label", /#{@version.name}/
chris@22 588 end
chris@22 589
chris@22 590 should "show the percent complete" do
chris@22 591 @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@117 592 assert_select "div.version.label", /30%/
chris@22 593 end
chris@22 594 end
chris@22 595 end
chris@22 596
chris@22 597 should "test the PNG format"
chris@22 598 should "test the PDF format"
chris@22 599 end
chris@22 600
chris@22 601 context "#subject_for_issue" do
chris@22 602 setup do
chris@22 603 create_gantt
chris@22 604 @project.enabled_module_names = [:issue_tracking]
chris@22 605 @tracker = Tracker.generate!
chris@22 606 @project.trackers << @tracker
chris@22 607
chris@22 608 @issue = Issue.generate!(:subject => "gantt#subject_for_issue",
chris@22 609 :tracker => @tracker,
chris@22 610 :project => @project,
chris@22 611 :start_date => 3.days.ago.to_date,
chris@22 612 :due_date => Date.yesterday)
chris@22 613 @project.issues << @issue
chris@22 614
chris@22 615 end
chris@22 616
chris@22 617 context ":html format" do
chris@22 618 should "add an absolute positioned div" do
chris@22 619 @response.body = @gantt.subject_for_issue(@issue, {:format => :html})
chris@22 620 assert_select "div[style*=absolute]"
chris@22 621 end
chris@22 622
chris@22 623 should "use the indent option to move the div to the right" do
chris@22 624 @response.body = @gantt.subject_for_issue(@issue, {:format => :html, :indent => 40})
chris@22 625 assert_select "div[style*=left:40]"
chris@22 626 end
chris@22 627
chris@22 628 should "include the issue subject" do
chris@22 629 @response.body = @gantt.subject_for_issue(@issue, {:format => :html})
chris@22 630 assert_select 'div', :text => /#{@issue.subject}/
chris@22 631 end
chris@22 632
chris@22 633 should "include a link to the issue" do
chris@22 634 @response.body = @gantt.subject_for_issue(@issue, {:format => :html})
chris@22 635 assert_select 'a[href=?]', Regexp.escape("/issues/#{@issue.to_param}"), :text => /#{@tracker.name} ##{@issue.id}/
chris@22 636 end
chris@22 637
chris@22 638 should "style overdue issues" do
chris@22 639 assert @issue.overdue?, "Need an overdue issue for this test"
chris@22 640 @response.body = @gantt.subject_for_issue(@issue, {:format => :html})
chris@22 641
chris@22 642 assert_select 'div span.issue-overdue'
chris@22 643 end
chris@22 644
chris@22 645 end
chris@22 646 should "test the PNG format"
chris@22 647 should "test the PDF format"
chris@22 648 end
chris@22 649
chris@22 650 context "#line_for_issue" do
chris@22 651 setup do
chris@22 652 create_gantt
chris@22 653 @project.enabled_module_names = [:issue_tracking]
chris@22 654 @tracker = Tracker.generate!
chris@22 655 @project.trackers << @tracker
chris@22 656 @version = Version.generate!(:effective_date => 1.week.from_now.to_date)
chris@22 657 @project.versions << @version
chris@22 658 @issue = Issue.generate!(:fixed_version => @version,
chris@22 659 :subject => "gantt#line_for_project",
chris@22 660 :tracker => @tracker,
chris@22 661 :project => @project,
chris@22 662 :done_ratio => 30,
Chris@117 663 :start_date => 1.week.ago.to_date,
chris@22 664 :due_date => 1.week.from_now.to_date)
chris@22 665 @project.issues << @issue
chris@22 666 end
chris@22 667
chris@22 668 context ":html format" do
chris@22 669 context "todo line" do
chris@22 670 should "start from the starting point on the left" do
chris@22 671 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 672 assert_select "div.task_todo[style*=left:28px]", true, @response.body
chris@22 673 end
chris@22 674
chris@22 675 should "be the total width of the issue" do
chris@22 676 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 677 assert_select "div.task_todo[style*=width:58px]", true, @response.body
chris@22 678 end
chris@22 679
chris@22 680 end
chris@22 681
chris@22 682 context "late line" do
chris@22 683 should "start from the starting point on the left" do
chris@22 684 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 685 assert_select "div.task_late[style*=left:28px]", true, @response.body
chris@22 686 end
chris@22 687
chris@22 688 should "be the total delayed width of the issue" do
chris@22 689 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 690 assert_select "div.task_late[style*=width:30px]", true, @response.body
chris@22 691 end
chris@22 692 end
chris@22 693
chris@22 694 context "done line" do
chris@22 695 should "start from the starting point on the left" do
chris@22 696 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 697 assert_select "div.task_done[style*=left:28px]", true, @response.body
chris@22 698 end
chris@22 699
chris@22 700 should "Be the total done width of the issue" do
chris@22 701 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 702 assert_select "div.task_done[style*=width:18px]", true, @response.body
Chris@117 703 end
Chris@117 704
Chris@117 705 should "not be the total done width if the chart starts after issue start date" do
Chris@117 706 create_gantt(@project, :date_from => 5.days.ago.to_date)
Chris@117 707
Chris@117 708 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 709 assert_select "div.task_done[style*=left:0px]", true, @response.body
Chris@117 710 assert_select "div.task_done[style*=width:10px]", true, @response.body
chris@22 711 end
chris@22 712 end
chris@22 713
chris@22 714 context "status content" do
chris@22 715 should "appear at the far left, even if it's far in the past" do
chris@22 716 @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
chris@22 717
chris@22 718 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 719 assert_select "div.task.label", true, @response.body
chris@22 720 end
chris@22 721
chris@22 722 should "show the issue status" do
chris@22 723 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 724 assert_select "div.task.label", /#{@issue.status.name}/
chris@22 725 end
chris@22 726
chris@22 727 should "show the percent complete" do
chris@22 728 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@117 729 assert_select "div.task.label", /30%/
chris@22 730 end
chris@22 731 end
chris@22 732 end
chris@22 733
chris@22 734 should "have an issue tooltip" do
chris@22 735 @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
chris@22 736 assert_select "div.tooltip", /#{@issue.subject}/
chris@22 737 end
chris@22 738
chris@22 739 should "test the PNG format"
chris@22 740 should "test the PDF format"
chris@22 741 end
chris@22 742
chris@22 743 context "#to_image" do
chris@22 744 should "be tested"
chris@22 745 end
chris@22 746
chris@22 747 context "#to_pdf" do
chris@22 748 should "be tested"
chris@22 749 end
chris@22 750
chris@22 751 end