Skip to content

Commit

Permalink
Unselect a Seat from the <dialog>
Browse files Browse the repository at this point in the history
For comparison [see this commit][commit]

Nothing exciting here. The ergonomics is similar to the Stimulus version.

[commit]: seanpdoyle@2e69ac9
  • Loading branch information
jho406 committed Oct 8, 2023
1 parent 428af14 commit 4bcbac1
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/models/cart.rb
Expand Up @@ -3,4 +3,8 @@ class Cart < ApplicationRecord

has_many :seat_selections
has_many :seats, through: :seat_selections

def include?(seat)
seat_ids.include?(seat.id)
end
end
19 changes: 14 additions & 5 deletions app/views/seats/show.json.props
@@ -1,19 +1,28 @@
json.venue_name venue.name

json.sections(partial: ['sections', locals: local_assigns]) do
json.sections(partial: ["sections", locals: local_assigns]) do
end

json.cart(partial: ['cart', locals: local_assigns]) do
json.cart(partial: ["cart", locals: local_assigns]) do
end

json.seat do
json.show true
json.section_name seat.section.name
json.row_number seat.row_number
json.price number_to_currency(seat.section.price / 100.0)
json.seat_selection_form do
form_props(url: seat_selections_path(seat)) do |f|
f.submit

if Current.cart.include?(seat)
json.seat_selection_form do
form_props(url: seat_selections_path(seat), method: :delete) do |f|
f.submit(text: "Remove")
end
end
else
json.seat_selection_form do
form_props(url: seat_selections_path(seat)) do |f|
f.submit(text: "Select")
end
end
end
end
4 changes: 4 additions & 0 deletions test/application_system_test_case.rb
Expand Up @@ -2,4 +2,8 @@

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]

def click_on_seat(row_number)
find(%{[aria-label*="#{row_number}"]}).click
end
end
2 changes: 1 addition & 1 deletion test/controllers/selections_controller_test.rb
Expand Up @@ -26,7 +26,7 @@ class SelectionsControllerTest < ActionDispatch::IntegrationTest
seat = seat_selection.seat
cookies[:cart_token] = cart.token

delete seat_selection_path(seat, seat_selection)
delete seat_selection_path(seat)

assert_equal cart.seats.ids, []
end
Expand Down
22 changes: 22 additions & 0 deletions test/models/cart_test.rb
@@ -0,0 +1,22 @@
require "test_helper"

class CartTest < ActiveSupport::TestCase
test "#include? returns true when a seat is selected" do
seat_selection = create(:seat_selection)
seat = seat_selection.seat
cart = seat_selection.cart

included = cart.include?(seat)

assert included, "cart includes selected seat"
end

test "#include? returns false when a seat is not yet selected" do
seat = create(:seat)
cart = create(:cart)

included = cart.include?(seat)

refute included, "cart includes selected seat"
end
end
17 changes: 17 additions & 0 deletions test/system/visitor_unselects_seat_test.rb
Expand Up @@ -15,4 +15,21 @@ class VisitorUnselectsSeatTest < ApplicationSystemTestCase
assert_no_text "$10.00"
end
end

test "from the details dialog of an already selected seat" do
venue = create(:benedum_center)
floor = create(:orchestra, venue: venue)
section = create(:section, floor: floor, price: 10_00)
seat = create(:seat, row: "AA", number: "101", section: section)

visit "/venues/benedum_center/floors/orchestra/seats"
click_on_seat "AA-101"
click_on "Select"
click_on_seat "AA-101"
within("dialog") { click_on "Remove" }

within "#cart-summary" do
assert_no_text "$10.00"
end
end
end
4 changes: 0 additions & 4 deletions test/system/visitor_views_seats_test.rb
Expand Up @@ -12,8 +12,4 @@ class VisitorViewsSeatsTest < ApplicationSystemTestCase

assert_text("$10.00")
end

def click_on_seat(row_number)
find(%{[aria-label*="#{row_number}"]}).click
end
end

0 comments on commit 4bcbac1

Please sign in to comment.