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