Commit 43c981c7 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'chore/23493-remaining-time-tooltip' into 'master'

Issue milestone remaining time tooltip

See merge request !9536
parents 774e0e3b 6924b4d3
...@@ -82,12 +82,13 @@ module MilestonesHelper ...@@ -82,12 +82,13 @@ module MilestonesHelper
def milestone_remaining_days(milestone) def milestone_remaining_days(milestone)
if milestone.expired? if milestone.expired?
content_tag(:strong, 'Past due') content_tag(:strong, 'Past due')
elsif milestone.due_date
days = milestone.remaining_days
content = content_tag(:strong, days)
content << " #{'day'.pluralize(days)} remaining"
elsif milestone.upcoming? elsif milestone.upcoming?
content_tag(:strong, 'Upcoming') content_tag(:strong, 'Upcoming')
elsif milestone.due_date
time_ago = time_ago_in_words(milestone.due_date)
content = time_ago.gsub(/\d+/) { |match| "<strong>#{match}</strong>" }
content.slice!("about ")
content << " remaining"
elsif milestone.start_date && milestone.start_date.past? elsif milestone.start_date && milestone.start_date.past?
days = milestone.elapsed_days days = milestone.elapsed_days
content = content_tag(:strong, days) content = content_tag(:strong, days)
......
---
title: Added remaining_time method to milestoneish, specs and updated the milestone_helper
milestone_remaining_days method to correctly return the correct remaining time.
merge_request:
author: Michael Robinson
...@@ -47,4 +47,54 @@ describe MilestonesHelper do ...@@ -47,4 +47,54 @@ describe MilestonesHelper do
end end
end end
end end
describe '#milestone_remaining_days' do
context 'when less than 31 days remaining' do
let(:milestone_remaining) { milestone_remaining_days(build_stubbed(:milestone, due_date: 12.days.from_now)) }
it 'returns days remaining' do
expect(milestone_remaining).to eq("<strong>11</strong> days remaining")
end
end
context 'when less than 1 year and more than 30 days remaining' do
let(:milestone_remaining) { milestone_remaining_days(build_stubbed(:milestone, due_date: 2.months.from_now)) }
it 'returns months remaining' do
expect(milestone_remaining).to eq("<strong>2</strong> months remaining")
end
end
context 'when more than 1 year remaining' do
let(:milestone_remaining) { milestone_remaining_days(build_stubbed(:milestone, due_date: 1.year.from_now + 2.days)) }
it 'returns years remaining' do
expect(milestone_remaining).to eq("<strong>1</strong> year remaining")
end
end
context 'when milestone is expired' do
let(:milestone_remaining) { milestone_remaining_days(build_stubbed(:milestone, due_date: 2.days.ago)) }
it 'returns "Past due"' do
expect(milestone_remaining).to eq("<strong>Past due</strong>")
end
end
context 'when milestone has start_date in the future' do
let(:milestone_remaining) { milestone_remaining_days(build_stubbed(:milestone, start_date: 2.days.from_now)) }
it 'returns "Upcoming"' do
expect(milestone_remaining).to eq("<strong>Upcoming</strong>")
end
end
context 'when milestone has start_date in the past' do
let(:milestone_remaining) { milestone_remaining_days(build_stubbed(:milestone, start_date: 2.days.ago)) }
it 'returns days elapsed' do
expect(milestone_remaining).to eq("<strong>2</strong> days elapsed")
end
end
end
end end
...@@ -116,21 +116,41 @@ describe Milestone, 'Milestoneish' do ...@@ -116,21 +116,41 @@ describe Milestone, 'Milestoneish' do
end end
end end
describe '#remaining_days' do
it 'shows 0 if no due date' do
milestone = build_stubbed(:milestone)
expect(milestone.remaining_days).to eq(0)
end
it 'shows 0 if expired' do
milestone = build_stubbed(:milestone, due_date: 2.days.ago)
expect(milestone.remaining_days).to eq(0)
end
it 'shows correct remaining days' do
milestone = build_stubbed(:milestone, due_date: 2.days.from_now)
expect(milestone.remaining_days).to eq(2)
end
end
describe '#elapsed_days' do describe '#elapsed_days' do
it 'shows 0 if no start_date set' do it 'shows 0 if no start_date set' do
milestone = build(:milestone) milestone = build_stubbed(:milestone)
expect(milestone.elapsed_days).to eq(0) expect(milestone.elapsed_days).to eq(0)
end end
it 'shows 0 if start_date is a future' do it 'shows 0 if start_date is a future' do
milestone = build(:milestone, start_date: Time.now + 2.days) milestone = build_stubbed(:milestone, start_date: Time.now + 2.days)
expect(milestone.elapsed_days).to eq(0) expect(milestone.elapsed_days).to eq(0)
end end
it 'shows correct amount of days' do it 'shows correct amount of days' do
milestone = build(:milestone, start_date: Time.now - 2.days) milestone = build_stubbed(:milestone, start_date: Time.now - 2.days)
expect(milestone.elapsed_days).to eq(2) expect(milestone.elapsed_days).to eq(2)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment