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