From: Jean-Philippe Lang Date: Sun, 30 Nov 2014 13:28:53 +0000 (+0000) Subject: Gantt unit tests cleanup. X-Git-Tag: 3.0.0~314 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dacae57a3873043c9ef45af1bf472923612ed5e2;p=redmine.git Gantt unit tests cleanup. git-svn-id: http://svn.redmine.org/redmine/trunk@13673 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/test/unit/lib/redmine/helpers/gantt_test.rb b/test/unit/lib/redmine/helpers/gantt_test.rb index 652bdb6a2..97ba11a96 100644 --- a/test/unit/lib/redmine/helpers/gantt_test.rb +++ b/test/unit/lib/redmine/helpers/gantt_test.rb @@ -18,16 +18,8 @@ require File.expand_path('../../../../../test_helper', __FILE__) class Redmine::Helpers::GanttHelperTest < ActionView::TestCase - fixtures :projects, :trackers, :issue_statuses, :issues, - :journals, :journal_details, - :enumerations, :users, :issue_categories, - :projects_trackers, - :roles, - :member_roles, - :members, - :enabled_modules, - :versions, - :groups_users + fixtures :trackers, :issue_statuses, + :enumerations, :users, :issue_categories include ProjectsHelper include IssuesHelper @@ -44,12 +36,16 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase end private :today + def gantt_start + @gantt.date_from + end + # Creates a Gantt chart for a 4 week span def create_gantt(project=Project.generate!, options={}) @project = project @gantt = Redmine::Helpers::Gantt.new(options) @gantt.project = @project - @gantt.query = IssueQuery.create!(:project => @project, :name => 'Gantt') + @gantt.query = IssueQuery.new(:project => @project, :name => 'Gantt') @gantt.view = self @gantt.instance_variable_set('@date_from', options[:date_from] || (today - 14)) @gantt.instance_variable_set('@date_to', options[:date_to] || (today + 14)) @@ -132,11 +128,6 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase setup_subjects @output_buffer = @gantt.subjects assert_select "div.project-name a", /#{@project.name}/ - end - - test "#subjects project should have an indent of 4" do - setup_subjects - @output_buffer = @gantt.subjects assert_select "div.project-name[style*=left:4px]" end @@ -144,11 +135,6 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase setup_subjects @output_buffer = @gantt.subjects assert_select "div.version-name a", /#{@version.name}/ - end - - test "#subjects version should be indented 24 (one level)" do - setup_subjects - @output_buffer = @gantt.subjects assert_select "div.version-name[style*=left:24px]" end @@ -166,11 +152,6 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase setup_subjects @output_buffer = @gantt.subjects assert_select "div.issue-subject", /#{@issue.subject}/ - end - - test "#subjects issue should be indented 44 (two levels)" do - setup_subjects - @output_buffer = @gantt.subjects assert_select "div.issue-subject[style*=left:44px]" end @@ -224,460 +205,217 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase assert_select "div.issue-subject[style*=left:84px]", /grandchild/, @output_buffer 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 => (today + 7)) - @project.versions << @version - @issue = Issue.generate!(:fixed_version => @version, - :subject => "gantt#line_for_project", - :tracker => @tracker, - :project => @project, - :done_ratio => 30, - :start_date => (today - 1), - :due_date => (today + 7)) - @project.issues << @issue - @output_buffer = @gantt.lines - end + test "#lines" do + create_gantt + @project.enabled_module_names = [:issue_tracking] + @tracker = Tracker.generate! + @project.trackers << @tracker + @version = Version.generate!(:effective_date => (today + 7)) + @project.versions << @version + @issue = Issue.generate!(:fixed_version => @version, + :subject => "gantt#line_for_project", + :tracker => @tracker, + :project => @project, + :done_ratio => 30, + :start_date => (today - 1), + :due_date => (today + 7)) + @project.issues << @issue + @output_buffer = @gantt.lines - context "project" do - should "be rendered" do - assert_select "div.project.task_todo" - assert_select "div.project.starting" - assert_select "div.project.ending" - assert_select "div.label.project", /#{@project.name}/ - end - end + assert_select "div.project.task_todo" + assert_select "div.project.starting" + assert_select "div.project.ending" + assert_select "div.label.project", /#{@project.name}/ - context "version" do - should "be rendered" do - assert_select "div.version.task_todo" - assert_select "div.version.starting" - assert_select "div.version.ending" - assert_select "div.label.version", /#{@version.name}/ - end - end + assert_select "div.version.task_todo" + assert_select "div.version.starting" + assert_select "div.version.ending" + assert_select "div.label.version", /#{@version.name}/ - context "issue" do - should "be rendered" do - assert_select "div.task_todo" - assert_select "div.task.label", /#{@issue.done_ratio}/ - assert_select "div.tooltip", /#{@issue.subject}/ - end - end + assert_select "div.task_todo" + assert_select "div.task.label", /#{@issue.done_ratio}/ + assert_select "div.tooltip", /#{@issue.subject}/ end - context "#subject_for_project" do - setup do - create_gantt - end + test "#subject_for_project" do + create_gantt + @output_buffer = @gantt.subject_for_project(@project, :format => :html) + assert_select 'a[href=?]', "/projects/#{@project.identifier}", :text => /#{@project.name}/ + end - context ":html format" do - should "add an absolute positioned div" do - @output_buffer = @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 - @output_buffer = @gantt.subject_for_project(@project, {:format => :html, :indent => 40}) - assert_select "div[style*=left:40]" - end - - should "include the project name" do - @output_buffer = @gantt.subject_for_project(@project, {:format => :html}) - assert_select 'div', :text => /#{@project.name}/ - end - - should "include a link to the project" do - @output_buffer = @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 => (today - 1)) - assert @project.reload.overdue?, "Need an overdue project for this test" - @output_buffer = @gantt.subject_for_project(@project, {:format => :html}) - assert_select 'div span.project-overdue' - end - end + test "#subject_for_project should style overdue projects" do + create_gantt + @project.stubs(:overdue?).returns(true) + @output_buffer = @gantt.subject_for_project(@project, :format => :html) + assert_select 'div span.project-overdue' 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 => (today - 1)) - @project.versions << @version - @project.issues << Issue.generate!(:fixed_version => @version, - :subject => "gantt#line_for_project", - :tracker => @tracker, - :project => @project, - :done_ratio => 30, - :start_date => (today - 7), - :due_date => (today + 7)) - end + test "#subject_for_version" do + create_gantt + version = Version.generate!(:name => 'Foo', :effective_date => today, :project => @project) + @output_buffer = @gantt.subject_for_version(version, :format => :html) + assert_select 'a[href=?]', "/versions/#{version.to_param}", :text => /Foo/ + end - context ":html format" do - context "todo line" do - should "start from the starting point on the left" do - @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project.task_todo[style*=left:28px]", true, @output_buffer - end - - should "be the total width of the project" do - @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project.task_todo[style*=width:58px]", true, @output_buffer - 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', today) - @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project.starting", false, @output_buffer - end - - should "appear at the starting point" do - @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project.starting[style*=left:28px]", true, @output_buffer - 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', (today - 14)) - @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project.ending", false, @output_buffer - end - - should "appear at the end of the date range" do - @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project.ending[style*=left:88px]", true, @output_buffer - 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', (today - 14)) - @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project.label", /#{@project.name}/ - end - - should "show the project name" do - @output_buffer = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) - assert_select "div.project.label", /#{@project.name}/ - end - end - end + test "#subject_for_version should style overdue versions" do + create_gantt + version = Version.generate!(:name => 'Foo', :effective_date => today, :project => @project) + version.stubs(:overdue?).returns(true) + @output_buffer = @gantt.subject_for_version(version, :format => :html) + assert_select 'div span.version-overdue' 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 => (today - 1)) - @project.versions << @version - @project.issues << Issue.generate!(:fixed_version => @version, - :subject => "gantt#subject_for_version", - :tracker => @tracker, - :project => @project, - :start_date => today) + test "#subject_for_version should style behind schedule versions" do + create_gantt + version = Version.generate!(:name => 'Foo', :effective_date => today, :project => @project) + version.stubs(:behind_schedule?).returns(true) + @output_buffer = @gantt.subject_for_version(version, :format => :html) + assert_select 'div span.version-behind-schedule' + end - end + test "#subject_for_issue" do + create_gantt + issue = Issue.generate!(:project => @project) + @output_buffer = @gantt.subject_for_issue(issue, :format => :html) + assert_select 'div', :text => /#{issue.subject}/ + assert_select 'a[href=?]', "/issues/#{issue.to_param}", :text => /#{issue.tracker.name} ##{issue.id}/ + end - context ":html format" do - should "add an absolute positioned div" do - @output_buffer = @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 - @output_buffer = @gantt.subject_for_version(@version, {:format => :html, :indent => 40}) - assert_select "div[style*=left:40]" - end - - should "include the version name" do - @output_buffer = @gantt.subject_for_version(@version, {:format => :html}) - assert_select 'div', :text => /#{@version.name}/ - end - - should "include a link to the version" do - @output_buffer = @gantt.subject_for_version(@version, {:format => :html}) - assert_select 'a[href=?]', Regexp.escape("/versions/#{@version.to_param}"), :text => /#{@version.name}/ - end - - should "style late versions" do - assert @version.overdue?, "Need an overdue version for this test" - @output_buffer = @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" - @output_buffer = @gantt.subject_for_version(@version, {:format => :html}) - assert_select 'div span.version-behind-schedule' - end - end + test "#subject_for_issue should style overdue issues" do + create_gantt + issue = Issue.generate!(:project => @project) + issue.stubs(:overdue?).returns(true) + @output_buffer = @gantt.subject_for_issue(issue, :format => :html) + assert_select 'div span.issue-overdue' 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 => (today + 7)) - @project.versions << @version - @project.issues << Issue.generate!(:fixed_version => @version, - :subject => "gantt#line_for_project", - :tracker => @tracker, - :project => @project, - :done_ratio => 30, - :start_date => (today - 7), - :due_date => (today + 7)) - end + test "#subject should add an absolute positioned div" do + create_gantt + @output_buffer = @gantt.subject('subject', :format => :html) + assert_select "div[style*=absolute]", :text => 'subject' + end - context ":html format" do - context "todo line" do - should "start from the starting point on the left" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.task_todo[style*=left:28px]", true, @output_buffer - end - - should "be the total width of the version" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.task_todo[style*=width:58px]", true, @output_buffer - end - end - - context "late line" do - should "start from the starting point on the left" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.task_late[style*=left:28px]", true, @output_buffer - end - - should "be the total delayed width of the version" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.task_late[style*=width:30px]", true, @output_buffer - end - end - - context "done line" do - should "start from the starting point on the left" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.task_done[style*=left:28px]", true, @output_buffer - end - - should "be the total done width of the version" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.task_done[style*=width:16px]", true, @output_buffer - 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', today) - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.starting", false - end - - should "appear at the starting point" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.starting[style*=left:28px]", true, @output_buffer - 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', (today - 14)) - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.ending", false - end - - should "appear at the end of the date range" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.ending[style*=left:88px]", true, @output_buffer - 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', (today - 14)) - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.label", /#{@version.name}/ - end - - should "show the version name" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.label", /#{@version.name}/ - end - - should "show the percent complete" do - @output_buffer = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) - assert_select "div.version.label", /30%/ - end - end - end + test "#subject should use the indent option to move the div to the right" do + create_gantt + @output_buffer = @gantt.subject('subject', :format => :html, :indent => 40) + assert_select "div[style*=left:40]" 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 => (today - 3), - :due_date => (today - 1)) - @project.issues << @issue - end + test "#line_for_project" do + create_gantt + @project.stubs(:start_date).returns(today - 7) + @project.stubs(:due_date).returns(today + 7) + @output_buffer = @gantt.line_for_project(@project, :format => :html) + assert_select "div.project.label", :text => @project.name + end - context ":html format" do - should "add an absolute positioned div" do - @output_buffer = @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 - @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html, :indent => 40}) - assert_select "div[style*=left:40]" - end - - should "include the issue subject" do - @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html}) - assert_select 'div', :text => /#{@issue.subject}/ - end - - should "include a link to the issue" do - @output_buffer = @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" - @output_buffer = @gantt.subject_for_issue(@issue, {:format => :html}) - assert_select 'div span.issue-overdue' - end - end + test "#line_for_version" do + create_gantt + version = Version.generate!(:name => 'Foo', :project => @project) + version.stubs(:start_date).returns(today - 7) + version.stubs(:due_date).returns(today + 7) + version.stubs(:completed_percent).returns(30) + @output_buffer = @gantt.line_for_version(version, :format => :html) + assert_select "div.version.label", :text => /Foo/ + assert_select "div.version.label", :text => /30%/ 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 => (today + 7)) - @project.versions << @version - @issue = Issue.generate!(:fixed_version => @version, - :subject => "gantt#line_for_project", - :tracker => @tracker, - :project => @project, - :done_ratio => 30, - :start_date => (today - 7), - :due_date => (today + 7)) - @project.issues << @issue - end + test "#line_for_issue" do + create_gantt + issue = Issue.generate!(:project => @project, :start_date => today - 7, :due_date => today + 7, :done_ratio => 30) + @output_buffer = @gantt.line_for_issue(issue, :format => :html) + assert_select "div.task.label", :text => /#{issue.status.name}/ + assert_select "div.task.label", :text => /30%/ + assert_select "div.tooltip", /#{issue.subject}/ + end - context ":html format" do - context "todo line" do - should "start from the starting point on the left" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_todo[style*=left:28px]", true, @output_buffer - end - - should "be the total width of the issue" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_todo[style*=width:58px]", true, @output_buffer - end - end - - context "late line" do - should "start from the starting point on the left" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_late[style*=left:28px]", true, @output_buffer - end - - should "be the total delayed width of the issue" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_late[style*=width:30px]", true, @output_buffer - end - end - - context "done line" do - should "start from the starting point on the left" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_done[style*=left:28px]", true, @output_buffer - end - - should "be the total done width of the issue" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - # 15 days * 4 px * 30% - 2 px for borders = 16 px - assert_select "div.task_done[style*=width:16px]", true, @output_buffer - end - - should "not be the total done width if the chart starts after issue start date" do - create_gantt(@project, :date_from => (today - 5)) - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_done[style*=left:0px]", true, @output_buffer - assert_select "div.task_done[style*=width:8px]", true, @output_buffer - end - - context "for completed issue" do - setup do - @issue.done_ratio = 100 - end - - should "be the total width of the issue" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_done[style*=width:58px]", true, @output_buffer - end - - should "be the total width of the issue with due_date=start_date" do - @issue.due_date = @issue.start_date - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task_done[style*=width:2px]", true, @output_buffer - end - 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', (today - 14)) - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task.label", true, @output_buffer - end - - should "show the issue status" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task.label", /#{@issue.status.name}/ - end - - should "show the percent complete" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.task.label", /30%/ - end - end - end + test "#line todo line should start from the starting point on the left" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 30, false, 'line', :format => :html, :zoom => 4) + assert_select "div.task_todo[style*=left:28px]", 1 + end - should "have an issue tooltip" do - @output_buffer = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) - assert_select "div.tooltip", /#{@issue.subject}/ - end + test "#line todo line should be the total width" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 30, false, 'line', :format => :html, :zoom => 4) + assert_select "div.task_todo[style*=width:58px]", 1 + end + + test "#line late line should start from the starting point on the left" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 30, false, 'line', :format => :html, :zoom => 4) + assert_select "div.task_late[style*=left:28px]", 1 + end + + test "#line late line should be the total delayed width" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 30, false, 'line', :format => :html, :zoom => 4) + assert_select "div.task_late[style*=width:30px]", 1 + end + + test "#line done line should start from the starting point on the left" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 30, false, 'line', :format => :html, :zoom => 4) + assert_select "div.task_done[style*=left:28px]", 1 + end + + test "#line done line should be the width for the done ratio" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 30, false, 'line', :format => :html, :zoom => 4) + # 15 days * 4 px * 30% - 2 px for borders = 16 px + assert_select "div.task_done[style*=width:16px]", 1 + end + + test "#line done line should be the total width for 100% done ratio" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 100, false, 'line', :format => :html, :zoom => 4) + # 15 days * 4 px - 2 px for borders = 58 px + assert_select "div.task_done[style*=width:58px]", 1 + end + + test "#line done line should be the total width for 100% done ratio with same start and end dates" do + create_gantt + @output_buffer = @gantt.line(today + 7, today + 7, 100, false, 'line', :format => :html, :zoom => 4) + assert_select "div.task_done[style*=width:2px]", 1 + end + + test "#line done line should not be the total done width if the gantt starts after start date" do + create_gantt + @output_buffer = @gantt.line(today - 16, today - 2, 30, false, 'line', :format => :html, :zoom => 4) + assert_select "div.task_done[style*=left:0px]", 1 + assert_select "div.task_done[style*=width:8px]", 1 + end + + test "#line starting marker should appear at the start date" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 30, true, 'line', :format => :html, :zoom => 4) + assert_select "div.starting", 1 + assert_select "div.starting[style*=left:28px]", 1 + end + + test "#line starting marker should not appear if the start date is before gantt start date" do + create_gantt + @output_buffer = @gantt.line(gantt_start - 2, today + 7, 30, true, 'line', :format => :html, :zoom => 4) + assert_select "div.starting", 0 + end + + test "#line ending marker should appear at the end date" do + create_gantt + @output_buffer = @gantt.line(today - 7, today + 7, 30, true, 'line', :format => :html, :zoom => 4) + assert_select "div.ending", 1 + assert_select "div.ending[style*=left:88px]", 1 + end + + test "#line ending marker should not appear if the end date is before gantt start date" do + create_gantt + @output_buffer = @gantt.line(gantt_start - 30, gantt_start - 21, 30, true, 'line', :format => :html) + assert_select "div.ending", 0 + end + + test "#line label should appear at the far left, even if it's before gantt start date" do + create_gantt + @output_buffer = @gantt.line(gantt_start - 30, gantt_start - 21, 30, true, 'line', :format => :html) + assert_select "div.label", :text => 'line' end def test_sort_issues_no_date @@ -749,11 +487,12 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase def test_sort_versions project = Project.generate! - version1 = Version.create!(:project => project, :name => 'test1') - version2 = Version.create!(:project => project, :name => 'test2', :effective_date => '2013-10-25') - version3 = Version.create!(:project => project, :name => 'test3') - version4 = Version.create!(:project => project, :name => 'test4', :effective_date => '2013-10-02') + versions = [] + versions << Version.create!(:project => project, :name => 'test1') + versions << Version.create!(:project => project, :name => 'test2', :effective_date => '2013-10-25') + versions << Version.create!(:project => project, :name => 'test3') + versions << Version.create!(:project => project, :name => 'test4', :effective_date => '2013-10-02') - assert_equal versions.sort, Redmine::Helpers::Gantt.sort_versions!(versions) + assert_equal versions.sort, Redmine::Helpers::Gantt.sort_versions!(versions.dup) end end