diff --git a/app/presenters/epic_presenter.rb b/app/presenters/epic_presenter.rb index 53a078c..2351c01 100644 --- a/app/presenters/epic_presenter.rb +++ b/app/presenters/epic_presenter.rb @@ -13,6 +13,18 @@ def initialize(epic:, issues:, expected_average: nil, uncertainty_level: nil, la delegate :key, :labels, :project_key, :summary, to: :epic + def issues_sorted + issues.sort_by do |issue| + if issue.started? + 0 + elsif issue.to_do? + 1 + else + issue.finish_date.to_i + end + end + end + def issues_count_presenter @issues_count_presenter ||= EpicIssuesCountPresenter.new(issues: issues) end diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 6129b1e..d0d3b73 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -8,5 +8,5 @@ <%= render 'shared/epic_details_table', epic_presenter: @epic_presenter %>
Issues
- <%= render 'issues/issues_table', issues: @epic_presenter.issues %> + <%= render 'issues/issues_table', issues: @epic_presenter.issues_sorted %> diff --git a/spec/presenters/epic_presenter_spec.rb b/spec/presenters/epic_presenter_spec.rb index 6930101..96d47b2 100644 --- a/spec/presenters/epic_presenter_spec.rb +++ b/spec/presenters/epic_presenter_spec.rb @@ -15,6 +15,22 @@ it { is_expected.to delegate_method(:summary).to(:epic) } end + describe '#issues_sorted' do + subject { described_class.new(epic: epic, issues: issues).issues_sorted } + + let(:epic) { build(:epic) } + let(:issues) { [issue_done1, issue_done2, issue_to_do, issue_in_progress] } + + let(:issue_done1) { build(:issue, :done, status_change_date: 2.days.ago) } + let(:issue_done2) { build(:issue, :done, status_change_date: 5.days.ago) } + let(:issue_to_do) { build(:issue, :to_do) } + let(:issue_in_progress) { build(:issue, :in_progress) } + + it 'sorts issues by in progress, then pending, and then by completion date' do + expect(subject).to eq([issue_in_progress, issue_to_do, issue_done2, issue_done1]) + end + end + describe '#issues_count_presenter' do subject { described_class.new(epic: epic, issues: issues).issues_count_presenter }