annotate .svn/pristine/30/30802f3b65425b8bb22f7cebacbf8ac4352f1e79.svn-base @ 1485:c8d3ad483bea redmine-2.4-integration

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