Chris@441: # Redmine - project management software Chris@441: # Copyright (C) 2006-2011 Jean-Philippe Lang chris@22: # chris@22: # This program is free software; you can redistribute it and/or chris@22: # modify it under the terms of the GNU General Public License chris@22: # as published by the Free Software Foundation; either version 2 chris@22: # of the License, or (at your option) any later version. chris@22: # chris@22: # This program is distributed in the hope that it will be useful, chris@22: # but WITHOUT ANY WARRANTY; without even the implied warranty of chris@22: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@22: # GNU General Public License for more details. chris@22: # chris@22: # You should have received a copy of the GNU General Public License chris@22: # along with this program; if not, write to the Free Software chris@22: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. chris@22: Chris@119: require File.expand_path('../../../../../test_helper', __FILE__) chris@22: chris@22: class Redmine::Helpers::GanttTest < ActiveSupport::TestCase chris@22: # Utility methods and classes so assert_select can be used. chris@22: class GanttViewTest < ActionView::Base chris@22: include ActionView::Helpers::UrlHelper chris@22: include ActionView::Helpers::TextHelper chris@22: include ActionController::UrlWriter chris@22: include ApplicationHelper chris@22: include ProjectsHelper chris@22: include IssuesHelper chris@22: chris@22: def self.default_url_options chris@22: {:only_path => true } chris@22: end chris@22: chris@22: end chris@22: chris@22: include ActionController::Assertions::SelectorAssertions chris@22: chris@22: def setup chris@22: @response = ActionController::TestResponse.new chris@22: # Fixtures chris@22: ProjectCustomField.delete_all chris@22: Project.destroy_all chris@22: chris@22: User.current = User.find(1) chris@22: end chris@22: chris@22: def build_view chris@22: @view = GanttViewTest.new chris@22: end chris@22: chris@22: def html_document chris@22: HTML::Document.new(@response.body) chris@22: end chris@22: chris@22: # Creates a Gantt chart for a 4 week span Chris@119: def create_gantt(project=Project.generate!, options={}) chris@22: @project = project Chris@119: @gantt = Redmine::Helpers::Gantt.new(options) chris@22: @gantt.project = @project chris@22: @gantt.query = Query.generate_default!(:project => @project) chris@22: @gantt.view = build_view Chris@119: @gantt.instance_variable_set('@date_from', options[:date_from] || 2.weeks.ago.to_date) Chris@119: @gantt.instance_variable_set('@date_to', options[:date_to] || 2.weeks.from_now.to_date) chris@22: end chris@22: chris@22: context "#number_of_rows" do chris@22: chris@22: context "with one project" do chris@22: should "return the number of rows just for that project" chris@22: end chris@22: chris@22: context "with no project" do chris@22: should "return the total number of rows for all the projects, resursively" chris@22: end chris@22: Chris@119: should "not exceed max_rows option" do Chris@119: p = Project.generate! Chris@119: 5.times do Chris@119: Issue.generate_for_project!(p) Chris@119: end Chris@119: Chris@119: create_gantt(p) Chris@119: @gantt.render Chris@119: assert_equal 6, @gantt.number_of_rows Chris@119: assert !@gantt.truncated Chris@119: Chris@119: create_gantt(p, :max_rows => 3) Chris@119: @gantt.render Chris@119: assert_equal 3, @gantt.number_of_rows Chris@119: assert @gantt.truncated Chris@119: end chris@22: end chris@22: chris@22: context "#number_of_rows_on_project" do chris@22: setup do chris@22: create_gantt chris@22: end chris@22: Chris@441: should "count 0 for an empty the project" do Chris@441: assert_equal 0, @gantt.number_of_rows_on_project(@project) chris@22: end chris@22: chris@22: should "count the number of issues without a version" do chris@22: @project.issues << Issue.generate_for_project!(@project, :fixed_version => nil) chris@22: assert_equal 2, @gantt.number_of_rows_on_project(@project) chris@22: end chris@22: chris@22: should "count the number of issues on versions, including cross-project" do chris@22: version = Version.generate! chris@22: @project.versions << version chris@22: @project.issues << Issue.generate_for_project!(@project, :fixed_version => version) chris@22: chris@22: assert_equal 3, @gantt.number_of_rows_on_project(@project) chris@22: end chris@22: end chris@22: chris@22: # TODO: more of an integration test chris@22: context "#subjects" do chris@22: setup do chris@22: create_gantt chris@22: @project.enabled_module_names = [:issue_tracking] chris@22: @tracker = Tracker.generate! chris@22: @project.trackers << @tracker chris@22: @version = Version.generate!(:effective_date => 1.week.from_now.to_date, :sharing => 'none') chris@22: @project.versions << @version chris@22: chris@22: @issue = Issue.generate!(:fixed_version => @version, chris@22: :subject => "gantt#line_for_project", chris@22: :tracker => @tracker, chris@22: :project => @project, chris@22: :done_ratio => 30, chris@22: :start_date => Date.yesterday, chris@22: :due_date => 1.week.from_now.to_date) Chris@119: @project.issues << @issue chris@22: end Chris@119: chris@22: context "project" do chris@22: should "be rendered" do Chris@119: @response.body = @gantt.subjects chris@22: assert_select "div.project-name a", /#{@project.name}/ chris@22: end Chris@119: chris@22: should "have an indent of 4" do Chris@119: @response.body = @gantt.subjects chris@22: assert_select "div.project-name[style*=left:4px]" chris@22: end chris@22: end Chris@119: chris@22: context "version" do chris@22: should "be rendered" do Chris@119: @response.body = @gantt.subjects chris@22: assert_select "div.version-name a", /#{@version.name}/ chris@22: end Chris@119: chris@22: should "be indented 24 (one level)" do Chris@119: @response.body = @gantt.subjects chris@22: assert_select "div.version-name[style*=left:24px]" chris@22: end Chris@441: Chris@441: context "without assigned issues" do Chris@441: setup do Chris@441: @version = Version.generate!(:effective_date => 2.week.from_now.to_date, :sharing => 'none', :name => 'empty_version') Chris@441: @project.versions << @version Chris@441: end Chris@441: Chris@441: should "not be rendered" do Chris@441: @response.body = @gantt.subjects Chris@441: assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0 Chris@441: end Chris@441: end chris@22: end Chris@119: chris@22: context "issue" do chris@22: should "be rendered" do Chris@119: @response.body = @gantt.subjects chris@22: assert_select "div.issue-subject", /#{@issue.subject}/ chris@22: end Chris@119: chris@22: should "be indented 44 (two levels)" do Chris@119: @response.body = @gantt.subjects chris@22: assert_select "div.issue-subject[style*=left:44px]" chris@22: end Chris@119: Chris@441: context "assigned to a shared version of another project" do Chris@441: setup do Chris@441: p = Project.generate! Chris@441: p.trackers << @tracker Chris@441: p.enabled_module_names = [:issue_tracking] Chris@441: @shared_version = Version.generate!(:sharing => 'system') Chris@441: p.versions << @shared_version Chris@441: # Reassign the issue to a shared version of another project Chris@441: Chris@441: @issue = Issue.generate!(:fixed_version => @shared_version, Chris@441: :subject => "gantt#assigned_to_shared_version", Chris@441: :tracker => @tracker, Chris@441: :project => @project, Chris@441: :done_ratio => 30, Chris@441: :start_date => Date.yesterday, Chris@441: :due_date => 1.week.from_now.to_date) Chris@441: @project.issues << @issue Chris@441: end Chris@441: Chris@441: should "be rendered" do Chris@441: @response.body = @gantt.subjects Chris@441: assert_select "div.issue-subject", /#{@issue.subject}/ Chris@441: end Chris@441: end Chris@441: Chris@119: context "with subtasks" do Chris@119: setup do Chris@119: attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version} Chris@119: @child1 = Issue.generate!(attrs.merge(:subject => 'child1', :parent_issue_id => @issue.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date)) Chris@119: @child2 = Issue.generate!(attrs.merge(:subject => 'child2', :parent_issue_id => @issue.id, :start_date => Date.today, :due_date => 1.week.from_now.to_date)) Chris@119: @grandchild = Issue.generate!(attrs.merge(:subject => 'grandchild', :parent_issue_id => @child1.id, :start_date => Date.yesterday, :due_date => 2.day.from_now.to_date)) Chris@119: end Chris@119: Chris@119: should "indent subtasks" do Chris@119: @response.body = @gantt.subjects Chris@119: # parent task 44px Chris@119: assert_select "div.issue-subject[style*=left:44px]", /#{@issue.subject}/ Chris@119: # children 64px Chris@119: assert_select "div.issue-subject[style*=left:64px]", /child1/ Chris@119: assert_select "div.issue-subject[style*=left:64px]", /child2/ Chris@119: # grandchild 84px Chris@119: assert_select "div.issue-subject[style*=left:84px]", /grandchild/, @response.body Chris@119: end Chris@119: end chris@22: end chris@22: end chris@22: chris@22: context "#lines" do chris@22: setup do chris@22: create_gantt chris@22: @project.enabled_module_names = [:issue_tracking] chris@22: @tracker = Tracker.generate! chris@22: @project.trackers << @tracker chris@22: @version = Version.generate!(:effective_date => 1.week.from_now.to_date) chris@22: @project.versions << @version chris@22: @issue = Issue.generate!(:fixed_version => @version, chris@22: :subject => "gantt#line_for_project", chris@22: :tracker => @tracker, chris@22: :project => @project, chris@22: :done_ratio => 30, chris@22: :start_date => Date.yesterday, chris@22: :due_date => 1.week.from_now.to_date) chris@22: @project.issues << @issue chris@22: chris@22: @response.body = @gantt.lines chris@22: end chris@22: chris@22: context "project" do chris@22: should "be rendered" do Chris@119: assert_select "div.project.task_todo" Chris@119: assert_select "div.project.starting" Chris@119: assert_select "div.project.ending" Chris@119: assert_select "div.label.project", /#{@project.name}/ chris@22: end chris@22: end chris@22: chris@22: context "version" do chris@22: should "be rendered" do Chris@119: assert_select "div.version.task_todo" Chris@119: assert_select "div.version.starting" Chris@119: assert_select "div.version.ending" Chris@119: assert_select "div.label.version", /#{@version.name}/ chris@22: end chris@22: end chris@22: chris@22: context "issue" do chris@22: should "be rendered" do chris@22: assert_select "div.task_todo" Chris@119: assert_select "div.task.label", /#{@issue.done_ratio}/ chris@22: assert_select "div.tooltip", /#{@issue.subject}/ chris@22: end chris@22: end chris@22: end chris@22: chris@22: context "#render_project" do chris@22: should "be tested" chris@22: end chris@22: chris@22: context "#render_issues" do chris@22: should "be tested" chris@22: end chris@22: chris@22: context "#render_version" do chris@22: should "be tested" chris@22: end chris@22: chris@22: context "#subject_for_project" do chris@22: setup do chris@22: create_gantt chris@22: end chris@22: chris@22: context ":html format" do chris@22: should "add an absolute positioned div" do chris@22: @response.body = @gantt.subject_for_project(@project, {:format => :html}) chris@22: assert_select "div[style*=absolute]" chris@22: end chris@22: chris@22: should "use the indent option to move the div to the right" do chris@22: @response.body = @gantt.subject_for_project(@project, {:format => :html, :indent => 40}) chris@22: assert_select "div[style*=left:40]" chris@22: end chris@22: chris@22: should "include the project name" do chris@22: @response.body = @gantt.subject_for_project(@project, {:format => :html}) chris@22: assert_select 'div', :text => /#{@project.name}/ chris@22: end chris@22: chris@22: should "include a link to the project" do chris@22: @response.body = @gantt.subject_for_project(@project, {:format => :html}) chris@22: assert_select 'a[href=?]', "/projects/#{@project.identifier}", :text => /#{@project.name}/ chris@22: end chris@22: chris@22: should "style overdue projects" do chris@22: @project.enabled_module_names = [:issue_tracking] chris@22: @project.versions << Version.generate!(:effective_date => Date.yesterday) chris@22: chris@22: assert @project.overdue?, "Need an overdue project for this test" chris@22: @response.body = @gantt.subject_for_project(@project, {:format => :html}) chris@22: chris@22: assert_select 'div span.project-overdue' chris@22: end chris@22: chris@22: chris@22: end chris@22: chris@22: should "test the PNG format" chris@22: should "test the PDF format" chris@22: end chris@22: chris@22: context "#line_for_project" do chris@22: setup do chris@22: create_gantt chris@22: @project.enabled_module_names = [:issue_tracking] chris@22: @tracker = Tracker.generate! chris@22: @project.trackers << @tracker chris@22: @version = Version.generate!(:effective_date => Date.yesterday) chris@22: @project.versions << @version chris@22: chris@22: @project.issues << Issue.generate!(:fixed_version => @version, chris@22: :subject => "gantt#line_for_project", chris@22: :tracker => @tracker, chris@22: :project => @project, chris@22: :done_ratio => 30, Chris@119: :start_date => 1.week.ago.to_date, chris@22: :due_date => 1.week.from_now.to_date) chris@22: end chris@22: chris@22: context ":html format" do chris@22: context "todo line" do chris@22: should "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.task_todo[style*=left:28px]", true, @response.body chris@22: end chris@22: chris@22: should "be the total width of the project" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.task_todo[style*=width:58px]", true, @response.body chris@22: end chris@22: chris@22: end chris@22: chris@22: context "late line" do Chris@119: should_eventually "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.task_late[style*=left:28px]", true, @response.body chris@22: end chris@22: Chris@119: should_eventually "be the total delayed width of the project" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.task_late[style*=width:30px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "done line" do Chris@119: should_eventually "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.task_done[style*=left:28px]", true, @response.body chris@22: end chris@22: Chris@119: should_eventually "Be the total done width of the project" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.task_done[style*=width:18px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "starting marker" do chris@22: should "not appear if the starting point is off the gantt chart" do chris@22: # Shift the date range of the chart chris@22: @gantt.instance_variable_set('@date_from', Date.today) chris@22: chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.starting", false, @response.body chris@22: end chris@22: chris@22: should "appear at the starting point" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.starting[style*=left:28px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "ending marker" do chris@22: should "not appear if the starting point is off the gantt chart" do chris@22: # Shift the date range of the chart chris@22: @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) chris@22: chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.ending", false, @response.body chris@22: chris@22: end chris@22: chris@22: should "appear at the end of the date range" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.ending[style*=left:88px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "status content" do chris@22: should "appear at the far left, even if it's far in the past" do chris@22: @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) chris@22: chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.label", /#{@project.name}/ chris@22: end chris@22: chris@22: should "show the project name" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.label", /#{@project.name}/ chris@22: end chris@22: Chris@119: should_eventually "show the percent complete" do chris@22: @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.project.label", /0%/ chris@22: end chris@22: end chris@22: end chris@22: chris@22: should "test the PNG format" chris@22: should "test the PDF format" chris@22: end chris@22: chris@22: context "#subject_for_version" do chris@22: setup do chris@22: create_gantt chris@22: @project.enabled_module_names = [:issue_tracking] chris@22: @tracker = Tracker.generate! chris@22: @project.trackers << @tracker chris@22: @version = Version.generate!(:effective_date => Date.yesterday) chris@22: @project.versions << @version chris@22: chris@22: @project.issues << Issue.generate!(:fixed_version => @version, chris@22: :subject => "gantt#subject_for_version", chris@22: :tracker => @tracker, chris@22: :project => @project, chris@22: :start_date => Date.today) chris@22: chris@22: end chris@22: chris@22: context ":html format" do chris@22: should "add an absolute positioned div" do chris@22: @response.body = @gantt.subject_for_version(@version, {:format => :html}) chris@22: assert_select "div[style*=absolute]" chris@22: end chris@22: chris@22: should "use the indent option to move the div to the right" do chris@22: @response.body = @gantt.subject_for_version(@version, {:format => :html, :indent => 40}) chris@22: assert_select "div[style*=left:40]" chris@22: end chris@22: chris@22: should "include the version name" do chris@22: @response.body = @gantt.subject_for_version(@version, {:format => :html}) chris@22: assert_select 'div', :text => /#{@version.name}/ chris@22: end chris@22: chris@22: should "include a link to the version" do chris@22: @response.body = @gantt.subject_for_version(@version, {:format => :html}) chris@22: assert_select 'a[href=?]', Regexp.escape("/versions/show/#{@version.to_param}"), :text => /#{@version.name}/ chris@22: end chris@22: chris@22: should "style late versions" do chris@22: assert @version.overdue?, "Need an overdue version for this test" chris@22: @response.body = @gantt.subject_for_version(@version, {:format => :html}) chris@22: chris@22: assert_select 'div span.version-behind-schedule' chris@22: end chris@22: chris@22: should "style behind schedule versions" do chris@22: assert @version.behind_schedule?, "Need a behind schedule version for this test" chris@22: @response.body = @gantt.subject_for_version(@version, {:format => :html}) chris@22: chris@22: assert_select 'div span.version-behind-schedule' chris@22: end chris@22: end chris@22: should "test the PNG format" chris@22: should "test the PDF format" chris@22: end chris@22: chris@22: context "#line_for_version" do chris@22: setup do chris@22: create_gantt chris@22: @project.enabled_module_names = [:issue_tracking] chris@22: @tracker = Tracker.generate! chris@22: @project.trackers << @tracker chris@22: @version = Version.generate!(:effective_date => 1.week.from_now.to_date) chris@22: @project.versions << @version chris@22: chris@22: @project.issues << Issue.generate!(:fixed_version => @version, chris@22: :subject => "gantt#line_for_project", chris@22: :tracker => @tracker, chris@22: :project => @project, chris@22: :done_ratio => 30, Chris@119: :start_date => 1.week.ago.to_date, chris@22: :due_date => 1.week.from_now.to_date) chris@22: end chris@22: chris@22: context ":html format" do chris@22: context "todo line" do chris@22: should "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.task_todo[style*=left:28px]", true, @response.body chris@22: end chris@22: chris@22: should "be the total width of the version" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.task_todo[style*=width:58px]", true, @response.body chris@22: end chris@22: chris@22: end chris@22: chris@22: context "late line" do chris@22: should "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.task_late[style*=left:28px]", true, @response.body chris@22: end chris@22: chris@22: should "be the total delayed width of the version" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.task_late[style*=width:30px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "done line" do chris@22: should "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.task_done[style*=left:28px]", true, @response.body chris@22: end chris@22: Chris@441: should "be the total done width of the version" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@441: assert_select "div.version.task_done[style*=width:16px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "starting marker" do chris@22: should "not appear if the starting point is off the gantt chart" do chris@22: # Shift the date range of the chart chris@22: @gantt.instance_variable_set('@date_from', Date.today) chris@22: chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.starting", false chris@22: end chris@22: chris@22: should "appear at the starting point" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.starting[style*=left:28px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "ending marker" do chris@22: should "not appear if the starting point is off the gantt chart" do chris@22: # Shift the date range of the chart chris@22: @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) chris@22: chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.ending", false chris@22: chris@22: end chris@22: chris@22: should "appear at the end of the date range" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.ending[style*=left:88px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "status content" do chris@22: should "appear at the far left, even if it's far in the past" do chris@22: @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) chris@22: chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.label", /#{@version.name}/ chris@22: end chris@22: chris@22: should "show the version name" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.label", /#{@version.name}/ chris@22: end chris@22: chris@22: should "show the percent complete" do chris@22: @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.version.label", /30%/ chris@22: end chris@22: end chris@22: end chris@22: chris@22: should "test the PNG format" chris@22: should "test the PDF format" chris@22: end chris@22: chris@22: context "#subject_for_issue" do chris@22: setup do chris@22: create_gantt chris@22: @project.enabled_module_names = [:issue_tracking] chris@22: @tracker = Tracker.generate! chris@22: @project.trackers << @tracker chris@22: chris@22: @issue = Issue.generate!(:subject => "gantt#subject_for_issue", chris@22: :tracker => @tracker, chris@22: :project => @project, chris@22: :start_date => 3.days.ago.to_date, chris@22: :due_date => Date.yesterday) chris@22: @project.issues << @issue chris@22: chris@22: end chris@22: chris@22: context ":html format" do chris@22: should "add an absolute positioned div" do chris@22: @response.body = @gantt.subject_for_issue(@issue, {:format => :html}) chris@22: assert_select "div[style*=absolute]" chris@22: end chris@22: chris@22: should "use the indent option to move the div to the right" do chris@22: @response.body = @gantt.subject_for_issue(@issue, {:format => :html, :indent => 40}) chris@22: assert_select "div[style*=left:40]" chris@22: end chris@22: chris@22: should "include the issue subject" do chris@22: @response.body = @gantt.subject_for_issue(@issue, {:format => :html}) chris@22: assert_select 'div', :text => /#{@issue.subject}/ chris@22: end chris@22: chris@22: should "include a link to the issue" do chris@22: @response.body = @gantt.subject_for_issue(@issue, {:format => :html}) chris@22: assert_select 'a[href=?]', Regexp.escape("/issues/#{@issue.to_param}"), :text => /#{@tracker.name} ##{@issue.id}/ chris@22: end chris@22: chris@22: should "style overdue issues" do chris@22: assert @issue.overdue?, "Need an overdue issue for this test" chris@22: @response.body = @gantt.subject_for_issue(@issue, {:format => :html}) chris@22: chris@22: assert_select 'div span.issue-overdue' chris@22: end chris@22: chris@22: end chris@22: should "test the PNG format" chris@22: should "test the PDF format" chris@22: end chris@22: chris@22: context "#line_for_issue" do chris@22: setup do chris@22: create_gantt chris@22: @project.enabled_module_names = [:issue_tracking] chris@22: @tracker = Tracker.generate! chris@22: @project.trackers << @tracker chris@22: @version = Version.generate!(:effective_date => 1.week.from_now.to_date) chris@22: @project.versions << @version chris@22: @issue = Issue.generate!(:fixed_version => @version, chris@22: :subject => "gantt#line_for_project", chris@22: :tracker => @tracker, chris@22: :project => @project, chris@22: :done_ratio => 30, Chris@119: :start_date => 1.week.ago.to_date, chris@22: :due_date => 1.week.from_now.to_date) chris@22: @project.issues << @issue chris@22: end chris@22: chris@22: context ":html format" do chris@22: context "todo line" do chris@22: should "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task_todo[style*=left:28px]", true, @response.body chris@22: end chris@22: chris@22: should "be the total width of the issue" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task_todo[style*=width:58px]", true, @response.body chris@22: end chris@22: chris@22: end chris@22: chris@22: context "late line" do chris@22: should "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task_late[style*=left:28px]", true, @response.body chris@22: end chris@22: chris@22: should "be the total delayed width of the issue" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task_late[style*=width:30px]", true, @response.body chris@22: end chris@22: end chris@22: chris@22: context "done line" do chris@22: should "start from the starting point on the left" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task_done[style*=left:28px]", true, @response.body chris@22: end chris@22: Chris@441: should "be the total done width of the issue" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@441: # 15 days * 4 px * 30% - 2 px for borders = 16 px Chris@441: assert_select "div.task_done[style*=width:16px]", true, @response.body Chris@119: end Chris@119: Chris@119: should "not be the total done width if the chart starts after issue start date" do Chris@119: create_gantt(@project, :date_from => 5.days.ago.to_date) Chris@119: Chris@119: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task_done[style*=left:0px]", true, @response.body Chris@441: assert_select "div.task_done[style*=width:8px]", true, @response.body Chris@441: end Chris@441: Chris@441: context "for completed issue" do Chris@441: setup do Chris@441: @issue.done_ratio = 100 Chris@441: end Chris@441: Chris@441: should "be the total width of the issue" do Chris@441: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@441: assert_select "div.task_done[style*=width:58px]", true, @response.body Chris@441: end Chris@441: Chris@441: should "be the total width of the issue with due_date=start_date" do Chris@441: @issue.due_date = @issue.start_date Chris@441: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@441: assert_select "div.task_done[style*=width:2px]", true, @response.body Chris@441: end chris@22: end chris@22: end chris@22: chris@22: context "status content" do chris@22: should "appear at the far left, even if it's far in the past" do chris@22: @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) chris@22: chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task.label", true, @response.body chris@22: end chris@22: chris@22: should "show the issue status" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task.label", /#{@issue.status.name}/ chris@22: end chris@22: chris@22: should "show the percent complete" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) Chris@119: assert_select "div.task.label", /30%/ chris@22: end chris@22: end chris@22: end chris@22: chris@22: should "have an issue tooltip" do chris@22: @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4}) chris@22: assert_select "div.tooltip", /#{@issue.subject}/ chris@22: end chris@22: chris@22: should "test the PNG format" chris@22: should "test the PDF format" chris@22: end chris@22: chris@22: context "#to_image" do chris@22: should "be tested" chris@22: end chris@22: chris@22: context "#to_pdf" do chris@22: should "be tested" chris@22: end chris@22: chris@22: end