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