diff options
author | Michael <seraph890@gmail.com> | 2017-03-16 11:34:46 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-03-16 11:34:46 +0000 |
commit | 6924b4d336c7498e1100153514bf29e217ae9239 (patch) | |
tree | ec0d9b32780c504ecb8328f2079cfa2e2942cde5 | |
parent | 774e0e3bfe2d35e8b7eb704ab856549559965dfe (diff) | |
download | gitlab-ce-6924b4d336c7498e1100153514bf29e217ae9239.tar.gz |
Issue milestone remaining time tooltip
-rw-r--r-- | app/helpers/milestones_helper.rb | 9 | ||||
-rw-r--r-- | changelogs/unreleased/chore-23493-remaining-time-tooltip.yml | 5 | ||||
-rw-r--r-- | spec/helpers/milestones_helper_spec.rb | 50 | ||||
-rw-r--r-- | spec/models/concerns/milestoneish_spec.rb | 26 |
4 files changed, 83 insertions, 7 deletions
diff --git a/app/helpers/milestones_helper.rb b/app/helpers/milestones_helper.rb index 7011e670cee..5053b937c02 100644 --- a/app/helpers/milestones_helper.rb +++ b/app/helpers/milestones_helper.rb @@ -82,12 +82,13 @@ module MilestonesHelper def milestone_remaining_days(milestone) if milestone.expired? 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? 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? days = milestone.elapsed_days content = content_tag(:strong, days) diff --git a/changelogs/unreleased/chore-23493-remaining-time-tooltip.yml b/changelogs/unreleased/chore-23493-remaining-time-tooltip.yml new file mode 100644 index 00000000000..dc315ca2367 --- /dev/null +++ b/changelogs/unreleased/chore-23493-remaining-time-tooltip.yml @@ -0,0 +1,5 @@ +--- +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 diff --git a/spec/helpers/milestones_helper_spec.rb b/spec/helpers/milestones_helper_spec.rb index 68b20a1e4fc..77a4ba305bb 100644 --- a/spec/helpers/milestones_helper_spec.rb +++ b/spec/helpers/milestones_helper_spec.rb @@ -47,4 +47,54 @@ describe MilestonesHelper do 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 diff --git a/spec/models/concerns/milestoneish_spec.rb b/spec/models/concerns/milestoneish_spec.rb index ad703a6c8bb..68e4c0a522b 100644 --- a/spec/models/concerns/milestoneish_spec.rb +++ b/spec/models/concerns/milestoneish_spec.rb @@ -116,21 +116,41 @@ describe Milestone, 'Milestoneish' do 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 it 'shows 0 if no start_date set' do - milestone = build(:milestone) + milestone = build_stubbed(:milestone) expect(milestone.elapsed_days).to eq(0) end 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) end 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) end |