Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken turbo streams response on schedule page. #211

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading