Skip to content

Commit 9bb867b

Browse files
seabeeberrySeray Ciftci
andauthored
Resolves #5247: Items in the history report are now displayed in alphabetical order when inside the filter view (#5272)
* Added automated alphabetical ordering of the items to the history report funnel view * Added test for showing items in history reports in alphabetical order * Fixed linting issues in _event_row.html.erb --------- Co-authored-by: Seray Ciftci <[email protected]>
1 parent 4ff9bad commit 9bb867b

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

app/views/events/_event_row.html.erb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
<% end %>
2929
</td>
3030
<td>
31-
<% event.data.items.each do |entry| %>
32-
<% item = items.find { |i| i.id == entry.item_id} %>
31+
<% sorted_entries = event.data.items.sort_by do |entry|
32+
item = items.find { |i| i.id == entry.item_id }
33+
item&.name&.downcase || ''
34+
end %>
35+
<% sorted_entries.each do |entry| %>
36+
<% item = items.find { |i| i.id == entry.item_id } %>
3337
<% if item %>
34-
<%= link_to items.find { |i| i.id == entry.item_id}.name, item_path(entry.item_id) %>:
38+
<%= link_to item.name, item_path(item.id) %>:
3539
<% else %>
3640
Item <%= entry.item_id %> (deleted)
3741
<% end %>

spec/requests/events_requests_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@
4747
expect(response.body).not_to include("99<br>")
4848
end
4949

50+
it "should show items in alphabetical order" do
51+
item_1 = create(:item, organization: organization, name: "Zebra")
52+
item_2 = create(:item, organization: organization, name: "apple")
53+
item_3 = create(:item, organization: organization, name: "Monkey")
54+
55+
donation = create(:donation, :with_items, organization: organization,
56+
storage_location: storage_location, item: item_1, item_quantity: 1)
57+
create(:line_item, item: item_2, quantity: 1, itemizable: donation)
58+
create(:line_item, item: item_3, quantity: 1, itemizable: donation)
59+
60+
DonationEvent.publish(donation)
61+
62+
get events_path(filters: {by_type: "DonationEvent", date_range: date_range_picker_params(3.days.ago, Time.zone.tomorrow)})
63+
64+
td_with_items = Nokogiri::HTML(response.body).css("td").find do |td|
65+
td.inner_html.include?("/items/")
66+
end
67+
68+
expect(td_with_items).not_to be_nil
69+
70+
links = td_with_items.css("a").map(&:text)
71+
expect(links).to eq(links.sort_by(&:downcase))
72+
end
5073
it "should show deleted items on regular event without crashing" do
5174
deleted_item = create(:item, organization: organization)
5275
travel(-1.day) do

0 commit comments

Comments
 (0)