Skip to content

Commit

Permalink
Sort issues for Issues page
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaherrera07 committed Jan 30, 2024
1 parent 7ec0fe1 commit 91320b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/presenters/epic_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/issues/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<%= render 'shared/epic_details_table', epic_presenter: @epic_presenter %>

<p class="h5">Issues</p>
<%= render 'issues/issues_table', issues: @epic_presenter.issues %>
<%= render 'issues/issues_table', issues: @epic_presenter.issues_sorted %>
</div>
16 changes: 16 additions & 0 deletions spec/presenters/epic_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 91320b8

Please sign in to comment.