Merge pull request #6717 from opf/feature/22284/better-date-quickinfo

[22284] Better dates quickinfo

[ci skip]
pull/6723/head
Oliver Günther 6 years ago committed by GitHub
commit c721b7c7e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      app/helpers/work_packages_helper.rb
  2. 49
      spec/lib/open_project/text_formatting/markdown/markdown_spec.rb

@ -169,11 +169,29 @@ module WorkPackagesHelper
end
end
link = link_to_work_package(work_package, status: true, only_path: only_path)
link += " #{work_package.start_date.nil? ? '[?]' : work_package.start_date.to_s}"
link += changed_dates['start_date']
link += "#{work_package.due_date.nil? ? '[?]' : work_package.due_date.to_s}"
link += changed_dates['due_date']
# Don't print dates if neither start nor due set
start = work_package.start_date&.to_s
due = work_package.due_date&.to_s
if start.nil? && due.nil?
return link
end
# Otherwise, print concise
# (2018-01-01 -)
# (- 2018-01-01)
# (2018-01-01 - 2018-01-01)
link <<
if start.nil?
" (- #{due})"
elsif due.nil?
" (#{start} -)"
else
" (#{start} - #{due})"
end
link
end

@ -231,6 +231,55 @@ describe OpenProject::TextFormatting,
it { is_expected.to be_html_eql("<p>#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.</p>") }
end
describe 'quickinfo' do
subject { format_text("###{issue.id}") }
let(:issue) do
FactoryBot.create :work_package,
project: project,
author: project_member,
type: project.types.first,
start_date: start_date,
due_date: due_date
end
context 'no dates' do
let(:start_date) { nil }
let(:due_date) { nil }
it 'prints no quickinfo with dates' do
puts subject
end
end
context 'start date' do
let(:start_date) { Date.today }
let(:due_date) { nil }
it 'prints no quickinfo with dates' do
expect(subject).to include "(#{start_date.to_s} -)"
end
end
context 'due date' do
let(:start_date) { nil }
let(:due_date) { Date.today }
it 'prints quickinfo with start date' do
expect(subject).to include "(- #{due_date.to_s})"
end
end
context 'both date' do
let(:start_date) { Date.today }
let(:due_date) { Date.today + 1.day }
it 'prints quickinfo with dates' do
expect(subject).to include "(#{start_date.to_s} - #{due_date.to_s})"
end
end
end
context 'Plain issue link with braces' do
subject { format_text("foo (bar ##{issue.id})") }

Loading…
Cancel
Save