Fix failing tests

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

View File

@ -1,14 +1,13 @@
- @game = seat.game - @game = seat.game
.seat .seat{class: "position-#{@seats.index(seat) + 1}"}
.seat-controls .seat-controls
- if seat.occupied? - if seat.occupied?
- if seat.occupied_by? current_user - if seat.occupied_by? current_user
= button_to "Stand", = button_to stand_seat_path(seat), :data => { :confirm => 'Are you sure you want to leave this seat?' } do
stand_seat_path(seat), - "Stand"
:data => { :confirm => 'Are you sure you want to leave this seat?' }
- else - else
= button_to "Sit", = button_to sit_seat_path(seat) do
sit_seat_path(seat) - "Sit"
- if seat.player - if seat.player
.player{id: "player-#{seat.player.id}", class: @game.controlling_player == seat.player ? "taking-turn" : "", .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 end
it 'sit button is disabled for unavailable seats' do 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 = page.find_button('Sit', match: :first)
@button.click @button.click
expect(page).to have_content "Guest" 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 end
it 'has a stand button if current user is seated' do 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 scenario 'table seats match up with game seats' do
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content "Guest" 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 click_button 'Sit', match: :first
expect(page).to have_content "Guest" 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 end
#TODO: User can only occupy one seat per table #TODO: User can only occupy one seat per table
scenario 'visitor changes seats' do scenario 'visitor changes seats' do
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content "Guest" 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 click_button 'Sit', match: :first
expect(page).to have_content "Guest" 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 expect(page.text.scan('Guest').count).to eq 1
end end
scenario 'visitor can join the current game' do scenario 'visitor can join the current game' do
click_button 'Sit', match: :first click_button 'Sit', match: :first
sleep 3
expect(page).to have_content "Guest" expect(page).to have_content "Guest"
expect(page.text.scan('Guest').count).to eq 1 expect(page.text.scan('Guest').count).to eq 1
end end
@ -64,8 +66,10 @@ feature 'Seats', :devise, js: true do
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content 'Guest' expect(page).to have_content 'Guest'
expect(page.text.scan('Guest').count).to eq 1 expect(page.text.scan('Guest').count).to eq 1
click_button 'Stand', match: :first accept_confirm do
expect(page.find('.game-seat.position-1')).to have_content 'Sit' click_button 'Stand', match: :first
end
expect(page.find('.seat.position-1')).to have_content 'Sit'
expect(sit_buttons.length).to eq 4 expect(sit_buttons.length).to eq 4
expect(page.text.scan('Guest').count).to eq 0 expect(page.text.scan('Guest').count).to eq 0
end end
@ -95,8 +99,9 @@ feature 'Seats', :devise, js: true do
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content @user.email expect(page).to have_content @user.email
expect(page.text.scan(@user.email).count).to eq 1 expect(page.text.scan(@user.email).count).to eq 1
click_button 'Stand', match: :first accept_confirm do
# sleep 1 click_button 'Stand', match: :first
end
expect(page.text.scan(@user.email).count).to eq 0 expect(page.text.scan(@user.email).count).to eq 0
end end

View File

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