From e22d5ad78fb78420b6e798b2f214ccae3307ce86 Mon Sep 17 00:00:00 2001 From: Aaron Contreras Date: Fri, 26 Jul 2024 11:47:49 -0500 Subject: [PATCH] Ensure meetings are displayed in the right order based on filter --- .../work_package_meetings_tab_controller.rb | 13 ++++++++++++- .../work_package_meetings_tab_spec.rb | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/modules/meeting/app/controllers/work_package_meetings_tab_controller.rb b/modules/meeting/app/controllers/work_package_meetings_tab_controller.rb index d65153e964d7..6de4b3f44b9a 100644 --- a/modules/meeting/app/controllers/work_package_meetings_tab_controller.rb +++ b/modules/meeting/app/controllers/work_package_meetings_tab_controller.rb @@ -127,9 +127,20 @@ def get_agenda_items_of_work_package(direction) .includes(:meeting) .where(meeting_id: Meeting.visible(current_user)) .where(work_package_id: @work_package.id) - .order("meetings.start_time": :asc) + .order(sort_clause(direction)) comparison = direction == :past ? "<" : ">=" agenda_items.where("meetings.start_time + (interval '1 hour' * meetings.duration) #{comparison} ?", Time.zone.now) end + + def sort_clause(direction) + case direction + when :upcoming + "meetings.start_time ASC" + when :past + "meetings.start_time DESC" + else + raise ArgumentError, "Invalid direction: #{direction}. Must be one of :upcoming or :past." + end + end end diff --git a/modules/meeting/spec/features/structured_meetings/work_package_meetings_tab_spec.rb b/modules/meeting/spec/features/structured_meetings/work_package_meetings_tab_spec.rb index 861a3c83e07f..06bea82dfb0a 100644 --- a/modules/meeting/spec/features/structured_meetings/work_package_meetings_tab_spec.rb +++ b/modules/meeting/spec/features/structured_meetings/work_package_meetings_tab_spec.rb @@ -238,11 +238,15 @@ expect(page).to have_content(second_meeting.title) expect(page).to have_content(meeting_agenda_item_of_second_meeting.notes) end + + meeting_containers = page.all("[data-test-selector^='op-meeting-container-']") + expect(meeting_containers[0]["data-test-selector"]).to eq("op-meeting-container-#{first_meeting.id}") + expect(meeting_containers[1]["data-test-selector"]).to eq("op-meeting-container-#{second_meeting.id}") end end context "when the work_package was already referenced in past meetings" do - let!(:first_past_meeting) { create(:structured_meeting, project:, start_time: Date.yesterday - 10.hours) } + let!(:first_past_meeting) { create(:structured_meeting, project:, start_time: Date.yesterday - 11.hours) } let!(:second_past_meeting) { create(:structured_meeting, project:, start_time: Date.yesterday - 10.hours) } let!(:first_meeting_agenda_item_of_first_past_meeting) do @@ -266,16 +270,20 @@ meetings_tab.switch_to_past_meetings_section + page.within_test_selector("op-meeting-container-#{second_past_meeting.id}") do + expect(page).to have_content(second_past_meeting.title) + expect(page).to have_content(meeting_agenda_item_of_second_past_meeting.notes) + end + page.within_test_selector("op-meeting-container-#{first_past_meeting.id}") do expect(page).to have_content(first_past_meeting.title) expect(page).to have_content(first_meeting_agenda_item_of_first_past_meeting.notes) expect(page).to have_content(second_meeting_agenda_item_of_first_past_meeting.notes) end - page.within_test_selector("op-meeting-container-#{second_past_meeting.id}") do - expect(page).to have_content(second_past_meeting.title) - expect(page).to have_content(meeting_agenda_item_of_second_past_meeting.notes) - end + meeting_containers = page.all("[data-test-selector^='op-meeting-container-']") + expect(meeting_containers[0]["data-test-selector"]).to eq("op-meeting-container-#{second_past_meeting.id}") + expect(meeting_containers[1]["data-test-selector"]).to eq("op-meeting-container-#{first_past_meeting.id}") end end