annotate test/unit/lib/redmine/helpers/gantt_test.rb @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents e248c7af89ec
children dffacf8a6908
rev   line source
Chris@441 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 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@909 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@909 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@119 18 require File.expand_path('../../../../../test_helper', __FILE__)
chris@22 19
Chris@1115 20 class Redmine::Helpers::GanttHelperTest < ActionView::TestCase
Chris@1115 21 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@1115 22 :journals, :journal_details,
Chris@1115 23 :enumerations, :users, :issue_categories,
Chris@1115 24 :projects_trackers,
Chris@1115 25 :roles,
Chris@1115 26 :member_roles,
Chris@1115 27 :members,
Chris@1115 28 :enabled_modules,
Chris@1115 29 :versions,
Chris@1115 30 :groups_users
Chris@909 31
Chris@1115 32 include ApplicationHelper
Chris@1115 33 include ProjectsHelper
Chris@1115 34 include IssuesHelper
Chris@1115 35 include ERB::Util
Chris@1464 36 include Rails.application.routes.url_helpers
chris@22 37
chris@22 38 def setup
Chris@1115 39 setup_with_controller
chris@22 40 User.current = User.find(1)
chris@22 41 end
chris@22 42
Chris@1115 43 def today
Chris@1115 44 @today ||= Date.today
chris@22 45 end
chris@22 46
chris@22 47 # Creates a Gantt chart for a 4 week span
Chris@119 48 def create_gantt(project=Project.generate!, options={})
chris@22 49 @project = project
Chris@119 50 @gantt = Redmine::Helpers::Gantt.new(options)
chris@22 51 @gantt.project = @project
Chris@1464 52 @gantt.query = IssueQuery.create!(:project => @project, :name => 'Gantt')
Chris@1115 53 @gantt.view = self
Chris@1115 54 @gantt.instance_variable_set('@date_from', options[:date_from] || (today - 14))
Chris@1115 55 @gantt.instance_variable_set('@date_to', options[:date_to] || (today + 14))
chris@22 56 end
chris@22 57
chris@22 58 context "#number_of_rows" do
chris@22 59 context "with one project" do
Chris@1464 60 should "return the number of rows just for that project" do
Chris@1464 61 p1, p2 = Project.generate!, Project.generate!
Chris@1464 62 i1, i2 = Issue.generate!(:project => p1), Issue.generate!(:project => p2)
Chris@1464 63 create_gantt(p1)
Chris@1464 64 assert_equal 2, @gantt.number_of_rows
Chris@1464 65 end
chris@22 66 end
chris@22 67
chris@22 68 context "with no project" do
Chris@1464 69 should "return the total number of rows for all the projects, resursively" do
Chris@1464 70 p1, p2 = Project.generate!, Project.generate!
Chris@1464 71 create_gantt(nil)
Chris@1464 72 #fix the return value of #number_of_rows_on_project() to an arbitrary value
Chris@1464 73 #so that we really only test #number_of_rows
Chris@1464 74 @gantt.stubs(:number_of_rows_on_project).returns(7)
Chris@1464 75 #also fix #projects because we want to test #number_of_rows in isolation
Chris@1464 76 @gantt.stubs(:projects).returns(Project.all)
Chris@1464 77 #actual test
Chris@1464 78 assert_equal Project.count*7, @gantt.number_of_rows
Chris@1464 79 end
chris@22 80 end
chris@22 81
Chris@119 82 should "not exceed max_rows option" do
Chris@119 83 p = Project.generate!
Chris@119 84 5.times do
Chris@1115 85 Issue.generate!(:project => p)
Chris@119 86 end
Chris@119 87 create_gantt(p)
Chris@119 88 @gantt.render
Chris@119 89 assert_equal 6, @gantt.number_of_rows
Chris@119 90 assert !@gantt.truncated
Chris@119 91 create_gantt(p, :max_rows => 3)
Chris@119 92 @gantt.render
Chris@119 93 assert_equal 3, @gantt.number_of_rows
Chris@119 94 assert @gantt.truncated
Chris@119 95 end
chris@22 96 end
chris@22 97
chris@22 98 context "#number_of_rows_on_project" do
chris@22 99 setup do
chris@22 100 create_gantt
chris@22 101 end
chris@22 102
Chris@441 103 should "count 0 for an empty the project" do
Chris@441 104 assert_equal 0, @gantt.number_of_rows_on_project(@project)
chris@22 105 end
chris@22 106
chris@22 107 should "count the number of issues without a version" do
Chris@1115 108 @project.issues << Issue.generate!(:project => @project, :fixed_version => nil)
chris@22 109 assert_equal 2, @gantt.number_of_rows_on_project(@project)
chris@22 110 end
chris@22 111
chris@22 112 should "count the number of issues on versions, including cross-project" do
chris@22 113 version = Version.generate!
chris@22 114 @project.versions << version
Chris@1115 115 @project.issues << Issue.generate!(:project => @project, :fixed_version => version)
chris@22 116 assert_equal 3, @gantt.number_of_rows_on_project(@project)
chris@22 117 end
chris@22 118 end
chris@22 119
chris@22 120 # TODO: more of an integration test
chris@22 121 context "#subjects" do
chris@22 122 setup do
chris@22 123 create_gantt
chris@22 124 @project.enabled_module_names = [:issue_tracking]
chris@22 125 @tracker = Tracker.generate!
chris@22 126 @project.trackers << @tracker
Chris@1115 127 @version = Version.generate!(:effective_date => (today + 7), :sharing => 'none')
chris@22 128 @project.versions << @version
chris@22 129 @issue = Issue.generate!(:fixed_version => @version,
chris@22 130 :subject => "gantt#line_for_project",
chris@22 131 :tracker => @tracker,
chris@22 132 :project => @project,
chris@22 133 :done_ratio => 30,
Chris@1115 134 :start_date => (today - 1),
Chris@1115 135 :due_date => (today + 7))
Chris@909 136 @project.issues << @issue
chris@22 137 end
Chris@909 138
chris@22 139 context "project" do
chris@22 140 should "be rendered" do
Chris@1115 141 @output_buffer = @gantt.subjects
chris@22 142 assert_select "div.project-name a", /#{@project.name}/
chris@22 143 end
Chris@909 144
chris@22 145 should "have an indent of 4" do
Chris@1115 146 @output_buffer = @gantt.subjects
chris@22 147 assert_select "div.project-name[style*=left:4px]"
chris@22 148 end
chris@22 149 end
Chris@909 150
chris@22 151 context "version" do
chris@22 152 should "be rendered" do
Chris@1115 153 @output_buffer = @gantt.subjects
chris@22 154 assert_select "div.version-name a", /#{@version.name}/
chris@22 155 end
Chris@909 156
chris@22 157 should "be indented 24 (one level)" do
Chris@1115 158 @output_buffer = @gantt.subjects
chris@22 159 assert_select "div.version-name[style*=left:24px]"
chris@22 160 end
Chris@909 161
Chris@441 162 context "without assigned issues" do
Chris@441 163 setup do
Chris@1115 164 @version = Version.generate!(:effective_date => (today + 14),
Chris@1115 165 :sharing => 'none',
Chris@1115 166 :name => 'empty_version')
Chris@441 167 @project.versions << @version
Chris@441 168 end
Chris@909 169
Chris@441 170 should "not be rendered" do
Chris@1115 171 @output_buffer = @gantt.subjects
Chris@441 172 assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0
Chris@441 173 end
Chris@441 174 end
chris@22 175 end
Chris@909 176
chris@22 177 context "issue" do
chris@22 178 should "be rendered" do
Chris@1115 179 @output_buffer = @gantt.subjects
chris@22 180 assert_select "div.issue-subject", /#{@issue.subject}/
chris@22 181 end
Chris@909 182
chris@22 183 should "be indented 44 (two levels)" do
Chris@1115 184 @output_buffer = @gantt.subjects
chris@22 185 assert_select "div.issue-subject[style*=left:44px]"
chris@22 186 end
Chris@909 187
Chris@441 188 context "assigned to a shared version of another project" do
Chris@441 189 setup do
Chris@441 190 p = Project.generate!
Chris@441 191 p.enabled_module_names = [:issue_tracking]
Chris@441 192 @shared_version = Version.generate!(:sharing => 'system')
Chris@441 193 p.versions << @shared_version
Chris@441 194 # Reassign the issue to a shared version of another project
Chris@441 195 @issue = Issue.generate!(:fixed_version => @shared_version,
Chris@441 196 :subject => "gantt#assigned_to_shared_version",
Chris@441 197 :tracker => @tracker,
Chris@441 198 :project => @project,
Chris@441 199 :done_ratio => 30,
Chris@1115 200 :start_date => (today - 1),
Chris@1115 201 :due_date => (today + 7))
Chris@441 202 @project.issues << @issue
Chris@441 203 end
Chris@909 204
Chris@441 205 should "be rendered" do
Chris@1115 206 @output_buffer = @gantt.subjects
Chris@441 207 assert_select "div.issue-subject", /#{@issue.subject}/
Chris@441 208 end
Chris@441 209 end
Chris@909 210
Chris@119 211 context "with subtasks" do
Chris@119 212 setup do
Chris@119 213 attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version}
Chris@1115 214 @child1 = Issue.generate!(
Chris@1115 215 attrs.merge(:subject => 'child1',
Chris@1115 216 :parent_issue_id => @issue.id,
Chris@1115 217 :start_date => (today - 1),
Chris@1115 218 :due_date => (today + 2))
Chris@1115 219 )
Chris@1115 220 @child2 = Issue.generate!(
Chris@1115 221 attrs.merge(:subject => 'child2',
Chris@1115 222 :parent_issue_id => @issue.id,
Chris@1115 223 :start_date => today,
Chris@1115 224 :due_date => (today + 7))
Chris@1115 225 )
Chris@1115 226 @grandchild = Issue.generate!(
Chris@1115 227 attrs.merge(:subject => 'grandchild',
Chris@1115 228 :parent_issue_id => @child1.id,
Chris@1115 229 :start_date => (today - 1),
Chris@1115 230 :due_date => (today + 2))
Chris@1115 231 )
Chris@119 232 end
Chris@909 233
Chris@119 234 should "indent subtasks" do
Chris@1115 235 @output_buffer = @gantt.subjects
Chris@119 236 # parent task 44px
Chris@119 237 assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/
Chris@119 238 # children 64px
Chris@119 239 assert_select "div.issue-subject[style*=left:64px]", /child1/
Chris@119 240 assert_select "div.issue-subject[style*=left:64px]", /child2/
Chris@119 241 # grandchild 84px
Chris@1115 242 assert_select "div.issue-subject[style*=left:84px]", /grandchild/, @output_buffer
Chris@119 243 end
Chris@119 244 end
chris@22 245 end
chris@22 246 end
chris@22 247
chris@22 248 context "#lines" do
chris@22 249 setup do
chris@22 250 create_gantt
chris@22 251 @project.enabled_module_names = [:issue_tracking]
chris@22 252 @tracker = Tracker.generate!
chris@22 253 @project.trackers << @tracker
Chris@1115 254 @version = Version.generate!(:effective_date => (today + 7))
chris@22 255 @project.versions << @version
chris@22 256 @issue = Issue.generate!(:fixed_version => @version,
chris@22 257 :subject => "gantt#line_for_project",
chris@22 258 :tracker => @tracker,
chris@22 259 :project => @project,
chris@22 260 :done_ratio => 30,
Chris@1115 261 :start_date => (today - 1),
Chris@1115 262 :due_date => (today + 7))
chris@22 263 @project.issues << @issue
Chris@1115 264 @output_buffer = @gantt.lines
chris@22 265 end
chris@22 266
chris@22 267 context "project" do
chris@22 268 should "be rendered" do
Chris@119 269 assert_select "div.project.task_todo"
Chris@119 270 assert_select "div.project.starting"
Chris@119 271 assert_select "div.project.ending"
Chris@119 272 assert_select "div.label.project", /#{@project.name}/
chris@22 273 end
chris@22 274 end
chris@22 275
chris@22 276 context "version" do
chris@22 277 should "be rendered" do
Chris@119 278 assert_select "div.version.task_todo"
Chris@119 279 assert_select "div.version.starting"
Chris@119 280 assert_select "div.version.ending"
Chris@119 281 assert_select "div.label.version", /#{@version.name}/
chris@22 282 end
chris@22 283 end
chris@22 284
chris@22 285 context "issue" do
chris@22 286 should "be rendered" do
chris@22 287 assert_select "div.task_todo"
Chris@119 288 assert_select "div.task.label", /#{@issue.done_ratio}/
chris@22 289 assert_select "div.tooltip", /#{@issue.subject}/
chris@22 290 end
chris@22 291 end
chris@22 292 end
chris@22 293
chris@22 294 context "#render_project" do
chris@22 295 should "be tested"
chris@22 296 end
chris@22 297
chris@22 298 context "#render_issues" do
chris@22 299 should "be tested"
chris@22 300 end
chris@22 301
chris@22 302 context "#render_version" do
chris@22 303 should "be tested"
chris@22 304 end
chris@22 305
chris@22 306 context "#subject_for_project" do
chris@22 307 setup do
chris@22 308 create_gantt
chris@22 309 end
Chris@909 310
chris@22 311 context ":html format" do
chris@22 312 should "add an absolute positioned div" do
Chris@1115 313 @output_buffer = @gantt.subject_for_project(@project, {:format => :html})
chris@22 314 assert_select "div[style*=absolute]"
chris@22 315 end
chris@22 316
chris@22 317 should "use the indent option to move the div to the right" do
Chris@1115 318 @output_buffer = @gantt.subject_for_project(@project, {:format => :html, :indent => 40})
chris@22 319 assert_select "div[style*=left:40]"
chris@22 320 end
chris@22 321
chris@22 322 should "include the project name" do
Chris@1115 323 @output_buffer = @gantt.subject_for_project(@project, {:format => :html})
chris@22 324 assert_select 'div', :text => /#{@project.name}/
chris@22 325 end
chris@22 326
chris@22 327 should "include a link to the project" do
Chris@1115 328 @output_buffer = @gantt.subject_for_project(@project, {:format => :html})
chris@22 329 assert_select 'a[href=?]', "/projects/#{@project.identifier}", :text => /#{@project.name}/
chris@22 330 end
chris@22 331
chris@22 332 should "style overdue projects" do
chris@22 333 @project.enabled_module_names = [:issue_tracking]
Chris@1115 334 @project.versions << Version.generate!(:effective_date => (today - 1))
Chris@1115 335 assert @project.reload.overdue?, "Need an overdue project for this test"
Chris@1115 336 @output_buffer = @gantt.subject_for_project(@project, {:format => :html})
chris@22 337 assert_select 'div span.project-overdue'
chris@22 338 end
chris@22 339 end
chris@22 340 should "test the PNG format"
chris@22 341 should "test the PDF format"
chris@22 342 end
chris@22 343
chris@22 344 context "#line_for_project" do
chris@22 345 setup do
chris@22 346 create_gantt
chris@22 347 @project.enabled_module_names = [:issue_tracking]
chris@22 348 @tracker = Tracker.generate!
chris@22 349 @project.trackers << @tracker
Chris@1115 350 @version = Version.generate!(:effective_date => (today - 1))
chris@22 351 @project.versions << @version
chris@22 352 @project.issues << Issue.generate!(:fixed_version => @version,
chris@22 353 :subject => "gantt#line_for_project",
chris@22 354 :tracker => @tracker,
chris@22 355 :project => @project,
chris@22 356 :done_ratio => 30,
Chris@1115 357 :start_date => (today - 7),
Chris@1115 358 :due_date => (today + 7))
chris@22 359 end
chris@22 360
chris@22 361 context ":html format" do
chris@22 362 context "todo line" do
chris@22 363 should "start from the starting point on the left" do
Chris@1115 364 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 365 assert_select "div.project.task_todo[style*=left:28px]", true, @output_buffer
chris@22 366 end
chris@22 367
chris@22 368 should "be the total width of the project" do
Chris@1115 369 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 370 assert_select "div.project.task_todo[style*=width:58px]", true, @output_buffer
chris@22 371 end
chris@22 372 end
chris@22 373
chris@22 374 context "late line" do
Chris@119 375 should_eventually "start from the starting point on the left" do
Chris@1115 376 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 377 assert_select "div.project.task_late[style*=left:28px]", true, @output_buffer
chris@22 378 end
chris@22 379
Chris@119 380 should_eventually "be the total delayed width of the project" do
Chris@1115 381 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 382 assert_select "div.project.task_late[style*=width:30px]", true, @output_buffer
chris@22 383 end
chris@22 384 end
chris@22 385
chris@22 386 context "done line" do
Chris@119 387 should_eventually "start from the starting point on the left" do
Chris@1115 388 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 389 assert_select "div.project.task_done[style*=left:28px]", true, @output_buffer
chris@22 390 end
chris@22 391
Chris@119 392 should_eventually "Be the total done width of the project" do
Chris@1115 393 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 394 assert_select "div.project.task_done[style*=width:18px]", true, @output_buffer
chris@22 395 end
chris@22 396 end
chris@22 397
chris@22 398 context "starting marker" do
chris@22 399 should "not appear if the starting point is off the gantt chart" do
chris@22 400 # Shift the date range of the chart
Chris@1115 401 @gantt.instance_variable_set('@date_from', today)
Chris@1115 402 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 403 assert_select "div.project.starting", false, @output_buffer
chris@22 404 end
chris@22 405
chris@22 406 should "appear at the starting point" do
Chris@1115 407 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 408 assert_select "div.project.starting[style*=left:28px]", true, @output_buffer
chris@22 409 end
chris@22 410 end
chris@22 411
chris@22 412 context "ending marker" do
chris@22 413 should "not appear if the starting point is off the gantt chart" do
chris@22 414 # Shift the date range of the chart
Chris@1115 415 @gantt.instance_variable_set('@date_to', (today - 14))
Chris@1115 416 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 417 assert_select "div.project.ending", false, @output_buffer
chris@22 418 end
chris@22 419
chris@22 420 should "appear at the end of the date range" do
Chris@1115 421 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@1115 422 assert_select "div.project.ending[style*=left:88px]", true, @output_buffer
chris@22 423 end
chris@22 424 end
Chris@909 425
chris@22 426 context "status content" do
chris@22 427 should "appear at the far left, even if it's far in the past" do
Chris@1115 428 @gantt.instance_variable_set('@date_to', (today - 14))
Chris@1115 429 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@119 430 assert_select "div.project.label", /#{@project.name}/
chris@22 431 end
chris@22 432
chris@22 433 should "show the project name" do
Chris@1115 434 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@119 435 assert_select "div.project.label", /#{@project.name}/
chris@22 436 end
chris@22 437
Chris@119 438 should_eventually "show the percent complete" do
Chris@1115 439 @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
Chris@119 440 assert_select "div.project.label", /0%/
chris@22 441 end
chris@22 442 end
chris@22 443 end
chris@22 444 should "test the PNG format"
chris@22 445 should "test the PDF format"
chris@22 446 end
chris@22 447
chris@22 448 context "#subject_for_version" do
chris@22 449 setup do
chris@22 450 create_gantt
chris@22 451 @project.enabled_module_names = [:issue_tracking]
chris@22 452 @tracker = Tracker.generate!
chris@22 453 @project.trackers << @tracker
Chris@1115 454 @version = Version.generate!(:effective_date => (today - 1))
chris@22 455 @project.versions << @version
chris@22 456 @project.issues << Issue.generate!(:fixed_version => @version,
chris@22 457 :subject => "gantt#subject_for_version",
chris@22 458 :tracker => @tracker,
chris@22 459 :project => @project,
Chris@1115 460 :start_date => today)
chris@22 461
chris@22 462 end
chris@22 463
chris@22 464 context ":html format" do
chris@22 465 should "add an absolute positioned div" do
Chris@1115 466 @output_buffer = @gantt.subject_for_version(@version, {:format => :html})
chris@22 467 assert_select "div[style*=absolute]"
chris@22 468 end
chris@22 469
chris@22 470 should "use the indent option to move the div to the right" do
Chris@1115 471 @output_buffer = @gantt.subject_for_version(@version, {:format => :html, :indent => 40})
chris@22 472 assert_select "div[style*=left:40]"
chris@22 473 end
chris@22 474
chris@22 475 should "include the version name" do
Chris@1115 476 @output_buffer = @gantt.subject_for_version(@version, {:format => :html})
chris@22 477 assert_select 'div', :text => /#{@version.name}/
chris@22 478 end
chris@22 479
chris@22 480 should "include a link to the version" do
Chris@1115 481 @output_buffer = @gantt.subject_for_version(@version, {:format => :html})
Chris@909 482 assert_select 'a[href=?]', Regexp.escape("/versions/#{@version.to_param}"), :text => /#{@version.name}/
chris@22 483 end
chris@22 484
chris@22 485 should "style late versions" do
chris@22 486 assert @version.overdue?, "Need an overdue version for this test"
Chris@1115 487 @output_buffer = @gantt.subject_for_version(@version, {:format => :html})
chris@22 488 assert_select 'div span.version-behind-schedule'
chris@22 489 end
chris@22 490
chris@22 491 should "style behind schedule versions" do
chris@22 492 assert @version.behind_schedule?, "Need a behind schedule version for this test"
Chris@1115 493 @output_buffer = @gantt.subject_for_version(@version, {:format => :html})
chris@22 494 assert_select 'div span.version-behind-schedule'
chris@22 495 end
chris@22 496 end
chris@22 497 should "test the PNG format"
chris@22 498 should "test the PDF format"
chris@22 499 end
chris@22 500
chris@22 501 context "#line_for_version" do
chris@22 502 setup do
chris@22 503 create_gantt
chris@22 504 @project.enabled_module_names = [:issue_tracking]
chris@22 505 @tracker = Tracker.generate!
chris@22 506 @project.trackers << @tracker
Chris@1115 507 @version = Version.generate!(:effective_date => (today + 7))
chris@22 508 @project.versions << @version
chris@22 509 @project.issues << Issue.generate!(:fixed_version => @version,
chris@22 510 :subject => "gantt#line_for_project",
chris@22 511 :tracker => @tracker,
chris@22 512 :project => @project,
chris@22 513 :done_ratio => 30,
Chris@1115 514 :start_date => (today - 7),
Chris@1115 515 :due_date => (today + 7))
chris@22 516 end
chris@22 517
chris@22 518 context ":html format" do
chris@22 519 context "todo line" do
chris@22 520 should "start from the starting point on the left" do
Chris@1115 521 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@1115 522 assert_select "div.version.task_todo[style*=left:28px]", true, @output_buffer
chris@22 523 end
chris@22 524
chris@22 525 should "be the total width of the version" do
Chris@1115 526 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@1115 527 assert_select "div.version.task_todo[style*=width:58px]", true, @output_buffer
chris@22 528 end
chris@22 529 end
chris@22 530
chris@22 531 context "late line" do
chris@22 532 should "start from the starting point on the left" do
Chris@1115 533 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@1115 534 assert_select "div.version.task_late[style*=left:28px]", true, @output_buffer
chris@22 535 end
chris@22 536
chris@22 537 should "be the total delayed width of the version" do
Chris@1115 538 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@1115 539 assert_select "div.version.task_late[style*=width:30px]", true, @output_buffer
chris@22 540 end
chris@22 541 end
chris@22 542
chris@22 543 context "done line" do
chris@22 544 should "start from the starting point on the left" do
Chris@1115 545 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@1115 546 assert_select "div.version.task_done[style*=left:28px]", true, @output_buffer
chris@22 547 end
chris@22 548
Chris@441 549 should "be the total done width of the version" do
Chris@1115 550 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@1115 551 assert_select "div.version.task_done[style*=width:16px]", true, @output_buffer
chris@22 552 end
chris@22 553 end
chris@22 554
chris@22 555 context "starting marker" do
chris@22 556 should "not appear if the starting point is off the gantt chart" do
chris@22 557 # Shift the date range of the chart
Chris@1115 558 @gantt.instance_variable_set('@date_from', today)
Chris@1115 559 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@119 560 assert_select "div.version.starting", false
chris@22 561 end
chris@22 562
chris@22 563 should "appear at the starting point" do
Chris@1115 564 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@1115 565 assert_select "div.version.starting[style*=left:28px]", true, @output_buffer
chris@22 566 end
chris@22 567 end
chris@22 568
chris@22 569 context "ending marker" do
chris@22 570 should "not appear if the starting point is off the gantt chart" do
chris@22 571 # Shift the date range of the chart
Chris@1115 572 @gantt.instance_variable_set('@date_to', (today - 14))
Chris@1115 573 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@119 574 assert_select "div.version.ending", false
chris@22 575 end
chris@22 576
chris@22 577 should "appear at the end of the date range" do
Chris@1115 578 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@1115 579 assert_select "div.version.ending[style*=left:88px]", true, @output_buffer
chris@22 580 end
chris@22 581 end
Chris@909 582
chris@22 583 context "status content" do
chris@22 584 should "appear at the far left, even if it's far in the past" do
Chris@1115 585 @gantt.instance_variable_set('@date_to', (today - 14))
Chris@1115 586 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@119 587 assert_select "div.version.label", /#{@version.name}/
chris@22 588 end
chris@22 589
chris@22 590 should "show the version name" do
Chris@1115 591 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@119 592 assert_select "div.version.label", /#{@version.name}/
chris@22 593 end
chris@22 594
chris@22 595 should "show the percent complete" do
Chris@1115 596 @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
Chris@119 597 assert_select "div.version.label", /30%/
chris@22 598 end
chris@22 599 end
chris@22 600 end
chris@22 601 should "test the PNG format"
chris@22 602 should "test the PDF format"
chris@22 603 end
chris@22 604
chris@22 605 context "#subject_for_issue" do
chris@22 606 setup do
chris@22 607 create_gantt
chris@22 608 @project.enabled_module_names = [:issue_tracking]
chris@22 609 @tracker = Tracker.generate!
chris@22 610 @project.trackers << @tracker
chris@22 611 @issue = Issue.generate!(:subject => "gantt#subject_for_issue",
chris@22 612 :tracker => @tracker,
chris@22 613 :project => @project,
Chris@1115 614 :start_date => (today - 3),
Chris@1115 615 :due_date => (today - 1))
chris@22 616 @project.issues << @issue
chris@22 617 end
chris@22 618
chris@22 619 context ":html format" do
chris@22 620 should "add an absolute positioned div" do
Chris@1115 621 @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html})
chris@22 622 assert_select "div[style*=absolute]"
chris@22 623 end
chris@22 624
chris@22 625 should "use the indent option to move the div to the right" do
Chris@1115 626 @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html, :indent => 40})
chris@22 627 assert_select "div[style*=left:40]"
chris@22 628 end
chris@22 629
chris@22 630 should "include the issue subject" do
Chris@1115 631 @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html})
chris@22 632 assert_select 'div', :text => /#{@issue.subject}/
chris@22 633 end
chris@22 634
chris@22 635 should "include a link to the issue" do
Chris@1115 636 @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html})
chris@22 637 assert_select 'a[href=?]', Regexp.escape("/issues/#{@issue.to_param}"), :text => /#{@tracker.name} ##{@issue.id}/
chris@22 638 end
chris@22 639
chris@22 640 should "style overdue issues" do
chris@22 641 assert @issue.overdue?, "Need an overdue issue for this test"
Chris@1115 642 @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html})
chris@22 643 assert_select 'div span.issue-overdue'
chris@22 644 end
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@1115 656 @version = Version.generate!(:effective_date => (today + 7))
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@1115 663 :start_date => (today - 7),
Chris@1115 664 :due_date => (today + 7))
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@1115 671 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 672 assert_select "div.task_todo[style*=left:28px]", true, @output_buffer
chris@22 673 end
chris@22 674
chris@22 675 should "be the total width of the issue" do
Chris@1115 676 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 677 assert_select "div.task_todo[style*=width:58px]", true, @output_buffer
chris@22 678 end
chris@22 679 end
chris@22 680
chris@22 681 context "late line" do
chris@22 682 should "start from the starting point on the left" do
Chris@1115 683 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 684 assert_select "div.task_late[style*=left:28px]", true, @output_buffer
chris@22 685 end
chris@22 686
chris@22 687 should "be the total delayed width of the issue" do
Chris@1115 688 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 689 assert_select "div.task_late[style*=width:30px]", true, @output_buffer
chris@22 690 end
chris@22 691 end
chris@22 692
chris@22 693 context "done line" do
chris@22 694 should "start from the starting point on the left" do
Chris@1115 695 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 696 assert_select "div.task_done[style*=left:28px]", true, @output_buffer
chris@22 697 end
chris@22 698
Chris@441 699 should "be the total done width of the issue" do
Chris@1115 700 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@441 701 # 15 days * 4 px * 30% - 2 px for borders = 16 px
Chris@1115 702 assert_select "div.task_done[style*=width:16px]", true, @output_buffer
Chris@119 703 end
Chris@119 704
Chris@119 705 should "not be the total done width if the chart starts after issue start date" do
Chris@1115 706 create_gantt(@project, :date_from => (today - 5))
Chris@1115 707 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 708 assert_select "div.task_done[style*=left:0px]", true, @output_buffer
Chris@1115 709 assert_select "div.task_done[style*=width:8px]", true, @output_buffer
Chris@441 710 end
Chris@909 711
Chris@441 712 context "for completed issue" do
Chris@441 713 setup do
Chris@441 714 @issue.done_ratio = 100
Chris@441 715 end
Chris@441 716
Chris@441 717 should "be the total width of the issue" do
Chris@1115 718 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 719 assert_select "div.task_done[style*=width:58px]", true, @output_buffer
Chris@441 720 end
Chris@909 721
Chris@441 722 should "be the total width of the issue with due_date=start_date" do
Chris@441 723 @issue.due_date = @issue.start_date
Chris@1115 724 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 725 assert_select "div.task_done[style*=width:2px]", true, @output_buffer
Chris@441 726 end
chris@22 727 end
chris@22 728 end
chris@22 729
chris@22 730 context "status content" do
chris@22 731 should "appear at the far left, even if it's far in the past" do
Chris@1115 732 @gantt.instance_variable_set('@date_to', (today - 14))
Chris@1115 733 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@1115 734 assert_select "div.task.label", true, @output_buffer
chris@22 735 end
chris@22 736
chris@22 737 should "show the issue status" do
Chris@1115 738 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@119 739 assert_select "div.task.label", /#{@issue.status.name}/
chris@22 740 end
chris@22 741
chris@22 742 should "show the percent complete" do
Chris@1115 743 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
Chris@119 744 assert_select "div.task.label", /30%/
chris@22 745 end
chris@22 746 end
chris@22 747 end
chris@22 748
chris@22 749 should "have an issue tooltip" do
Chris@1115 750 @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
chris@22 751 assert_select "div.tooltip", /#{@issue.subject}/
chris@22 752 end
chris@22 753 should "test the PNG format"
chris@22 754 should "test the PDF format"
chris@22 755 end
chris@22 756
chris@22 757 context "#to_image" do
chris@22 758 should "be tested"
chris@22 759 end
chris@22 760
chris@22 761 context "#to_pdf" do
chris@22 762 should "be tested"
chris@22 763 end
Chris@1464 764
Chris@1464 765 def test_sort_issues_no_date
Chris@1464 766 project = Project.generate!
Chris@1464 767 issue1 = Issue.generate!(:subject => "test", :project => project)
Chris@1464 768 issue2 = Issue.generate!(:subject => "test", :project => project)
Chris@1464 769 assert issue1.root_id < issue2.root_id
Chris@1464 770 child1 = Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
Chris@1464 771 :project => project)
Chris@1464 772 child2 = Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
Chris@1464 773 :project => project)
Chris@1464 774 child3 = Issue.generate!(:parent_issue_id => child1.id, :subject => 'child',
Chris@1464 775 :project => project)
Chris@1464 776 assert_equal child1.root_id, child2.root_id
Chris@1464 777 assert child1.lft < child2.lft
Chris@1464 778 assert child3.lft < child2.lft
Chris@1464 779 issues = [child3, child2, child1, issue2, issue1]
Chris@1464 780 Redmine::Helpers::Gantt.sort_issues!(issues)
Chris@1464 781 assert_equal [issue1.id, child1.id, child3.id, child2.id, issue2.id],
Chris@1464 782 issues.map{|v| v.id}
Chris@1464 783 end
Chris@1464 784
Chris@1464 785 def test_sort_issues_root_only
Chris@1464 786 project = Project.generate!
Chris@1464 787 issue1 = Issue.generate!(:subject => "test", :project => project)
Chris@1464 788 issue2 = Issue.generate!(:subject => "test", :project => project)
Chris@1464 789 issue3 = Issue.generate!(:subject => "test", :project => project,
Chris@1464 790 :start_date => (today - 1))
Chris@1464 791 issue4 = Issue.generate!(:subject => "test", :project => project,
Chris@1464 792 :start_date => (today - 2))
Chris@1464 793 issues = [issue4, issue3, issue2, issue1]
Chris@1464 794 Redmine::Helpers::Gantt.sort_issues!(issues)
Chris@1464 795 assert_equal [issue1.id, issue2.id, issue4.id, issue3.id],
Chris@1464 796 issues.map{|v| v.id}
Chris@1464 797 end
Chris@1464 798
Chris@1464 799 def test_sort_issues_tree
Chris@1464 800 project = Project.generate!
Chris@1464 801 issue1 = Issue.generate!(:subject => "test", :project => project)
Chris@1464 802 issue2 = Issue.generate!(:subject => "test", :project => project,
Chris@1464 803 :start_date => (today - 2))
Chris@1464 804 issue1_child1 =
Chris@1464 805 Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
Chris@1464 806 :project => project)
Chris@1464 807 issue1_child2 =
Chris@1464 808 Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
Chris@1464 809 :project => project, :start_date => (today - 10))
Chris@1464 810 issue1_child1_child1 =
Chris@1464 811 Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child',
Chris@1464 812 :project => project, :start_date => (today - 8))
Chris@1464 813 issue1_child1_child2 =
Chris@1464 814 Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child',
Chris@1464 815 :project => project, :start_date => (today - 9))
Chris@1464 816 issue1_child1_child1_logic = Redmine::Helpers::Gantt.sort_issue_logic(issue1_child1_child1)
Chris@1464 817 assert_equal [[today - 10, issue1.id], [today - 9, issue1_child1.id],
Chris@1464 818 [today - 8, issue1_child1_child1.id]],
Chris@1464 819 issue1_child1_child1_logic
Chris@1464 820 issue1_child1_child2_logic = Redmine::Helpers::Gantt.sort_issue_logic(issue1_child1_child2)
Chris@1464 821 assert_equal [[today - 10, issue1.id], [today - 9, issue1_child1.id],
Chris@1464 822 [today - 9, issue1_child1_child2.id]],
Chris@1464 823 issue1_child1_child2_logic
Chris@1464 824 issues = [issue1_child1_child2, issue1_child1_child1, issue1_child2,
Chris@1464 825 issue1_child1, issue2, issue1]
Chris@1464 826 Redmine::Helpers::Gantt.sort_issues!(issues)
Chris@1464 827 assert_equal [issue1.id, issue1_child1.id, issue1_child2.id,
Chris@1464 828 issue1_child1_child2.id, issue1_child1_child1.id, issue2.id],
Chris@1464 829 issues.map{|v| v.id}
Chris@1464 830 end
Chris@1464 831
Chris@1464 832 def test_sort_versions
Chris@1464 833 project = Project.generate!
Chris@1464 834 version1 = Version.create!(:project => project, :name => 'test1')
Chris@1464 835 version2 = Version.create!(:project => project, :name => 'test2', :effective_date => '2013-10-25')
Chris@1464 836 version3 = Version.create!(:project => project, :name => 'test3')
Chris@1464 837 version4 = Version.create!(:project => project, :name => 'test4', :effective_date => '2013-10-02')
Chris@1464 838
Chris@1464 839 assert_equal versions.sort, Redmine::Helpers::Gantt.sort_versions!(versions)
Chris@1464 840 end
chris@22 841 end