Skip to content

Commit

Permalink
Merge pull request #211 from kufu/fixes/miss_params_on_schedule_item_…
Browse files Browse the repository at this point in the history
…remove

Fix broken turbo streams response on schedule page.
  • Loading branch information
kinoppyd authored Dec 24, 2024
2 parents aa6ebad + 1f7019a commit f96727c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def set_attributes_for_turbo_stream
@schedule_table.days.each do |day|
@table = @schedule_table[day]
@table.rows.each do |row|
throw :abort, [row, @table.track_list] if row.schedules.map(&:id).include?(params[:schedule_id])
throw :abort, [row, @table.track_list] if row.schedules.map(&:id).include?(@item.schedule.id)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/schedules/_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<div>
<% if @plan.plan_schedules.map(&:schedule).include?(schedule) # to avoid n+1 %>
<%= form_with(url: event_item_url(@plan.plan_schedules.find_by(schedule:), event_name: @plan.event.name), method: :delete ) do |form| %>
<%= form.hidden_field :mode, value: mode, id: SecureRandom.uuid %>
<%= form.submit I18n.t('card.remove'), class: "remove-plan-button p-2 text-sm font-bold min-h-5 normal-button", data: { turbo_frame: "event_#{@event.id}" } %>
<% end %>
<% elsif @plan.new_record? %>
Expand Down Expand Up @@ -133,6 +134,7 @@
<% else %>
<%= form_with(url: event_plan_items_url(plan_id: @plan.id, event_name: @plan.event.name), method: :post ) do |form| %>
<%= form.hidden_field :schedule_id, value: schedule.id %>
<%= form.hidden_field :mode, value: mode, id: SecureRandom.uuid %>
<%= form.submit inactive ? I18n.t('card.inactive') : I18n.t('card.add'), class: "add-plan-button p-2 text-sm font-bold min-h-5 normal-button", disabled: inactive, data: { turbo_frame: "event_#{@event.id}"} %>
<% end %>
<% end %>
Expand Down
18 changes: 18 additions & 0 deletions test/system/schedules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,22 @@ class SchedulesTest < ApplicationSystemTestCase
table_rows = all('tr')
assert table_rows[2].find_button(class: ['remove-plan-button'])
end

test 'when one schedule remove from plan, that schedule button to be add button' do
visit event_schedules_path(event_name: events(:kaigi).name)

all(class: ['add-plan-button'])[1].click
find(class: ['confirm-terms-of-service-button']).click

# wait for turbo frame
if has_selector?('dialog', visible: true, wait: 0.25.seconds)
has_no_selector?('dialog', visible: true, wait: 1.seconds)
end

all(class: ['remove-plan-button'])[0].click

sleep 1 # FIXME: this is workaround
table_rows = all('tr')
assert_equal 3, table_rows[2].all(class: ['add-plan-button']).count
end
end

0 comments on commit f96727c

Please sign in to comment.