Fix failing tests

This commit is contained in:
Jesse C. Fisher 2021-11-05 21:02:33 -07:00
parent 38a1e54cca
commit 34502f4794
3 changed files with 21 additions and 18 deletions

View File

@ -1,14 +1,13 @@
- @game = seat.game
.seat
.seat{class: "position-#{@seats.index(seat) + 1}"}
.seat-controls
- if seat.occupied?
- if seat.occupied_by? current_user
= button_to "Stand",
stand_seat_path(seat),
:data => { :confirm => 'Are you sure you want to leave this seat?' }
= button_to stand_seat_path(seat), :data => { :confirm => 'Are you sure you want to leave this seat?' } do
- "Stand"
- else
= button_to "Sit",
sit_seat_path(seat)
= button_to sit_seat_path(seat) do
- "Sit"
- if seat.player
.player{id: "player-#{seat.player.id}", class: @game.controlling_player == seat.player ? "taking-turn" : "",

View File

@ -15,10 +15,13 @@ feature 'Seats', :devise, js: true do
end
it 'sit button is disabled for unavailable seats' do
@sit_buttons = page.find_all('button', text: 'Sit')
expect(@sit_buttons.length).to eq 4
@button = page.find_button('Sit', match: :first)
@button.click
expect(page).to have_content "Guest"
expect(@button.disabled?).to eq true
@sit_buttons = page.find_all('button', text: 'Sit')
expect(@sit_buttons.length).to eq 3
end
it 'has a stand button if current user is seated' do
@ -32,26 +35,25 @@ feature 'Seats', :devise, js: true do
scenario 'table seats match up with game seats' do
click_button 'Sit', match: :first
expect(page).to have_content "Guest"
expect(page.find(:css, ".game-seat.position-1")).to have_content "Guest"
expect(page.find(:css, ".seat.position-1 .player")).to have_content "Guest"
click_button 'Sit', match: :first
expect(page).to have_content "Guest"
expect(page.find(:css, ".game-seat.position-2")).to have_content "Guest"
expect(page.find(:css, ".seat.position-2 .player")).to have_content "Guest"
end
#TODO: User can only occupy one seat per table
scenario 'visitor changes seats' do
click_button 'Sit', match: :first
expect(page).to have_content "Guest"
expect(page.find(:css, ".game-seat.position-1")).to have_content "Guest"
expect(page.find(:css, ".seat.position-1")).to have_content "Guest"
click_button 'Sit', match: :first
expect(page).to have_content "Guest"
expect(page.find(:css, ".game-seat.position-2")).to have_content "Guest"
expect(page.find(:css, ".seat.position-2")).to have_content "Guest"
expect(page.text.scan('Guest').count).to eq 1
end
scenario 'visitor can join the current game' do
click_button 'Sit', match: :first
sleep 3
expect(page).to have_content "Guest"
expect(page.text.scan('Guest').count).to eq 1
end
@ -64,8 +66,10 @@ feature 'Seats', :devise, js: true do
click_button 'Sit', match: :first
expect(page).to have_content 'Guest'
expect(page.text.scan('Guest').count).to eq 1
click_button 'Stand', match: :first
expect(page.find('.game-seat.position-1')).to have_content 'Sit'
accept_confirm do
click_button 'Stand', match: :first
end
expect(page.find('.seat.position-1')).to have_content 'Sit'
expect(sit_buttons.length).to eq 4
expect(page.text.scan('Guest').count).to eq 0
end
@ -95,8 +99,9 @@ feature 'Seats', :devise, js: true do
click_button 'Sit', match: :first
expect(page).to have_content @user.email
expect(page.text.scan(@user.email).count).to eq 1
click_button 'Stand', match: :first
# sleep 1
accept_confirm do
click_button 'Stand', match: :first
end
expect(page.text.scan(@user.email).count).to eq 0
end

View File

@ -9,8 +9,7 @@ feature 'Sign in', :devise do
# Then I see an invalid credentials message
scenario 'user cannot sign in if not registered' do
signin('test@example.com', 'password')
expect(page).to have_content
I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
end
# Scenario: User can sign in with valid credentials