2021-11-02 19:47:51 -07:00

72 lines
2.3 KiB
Ruby

# Feature: Play now
# As a visitor
# I want to quickly join a game
# So I can play
feature 'Play now', :devise, js: true do
# Scenario: Visitor can play now
# Given I am not signed in
# When I click Play Now
# Then I join a game
describe 'visitor can Play Now' do
context 'there are no joinable games' do
before do
expect(Game.all.count).to eq 0
visit root_path
click_link 'Play Now'
end
it 'creates and joins a new game' do
#TODO: Fix race condition
sleep 2
expect(page).to have_content "Hand to beat"
#Game title derived from visitor soft_token
expect(page).to have_content "#{Game.last.players.first.soft_token[0..4]}"
#Game count increased by 1
expect(Game.all.count).to eq 1
end
end
context 'visitor joins an existing game' do
before do
FactoryGirl.create :table
@table = Table.last
visit root_path
# expect(Game.all.count).to eq 1
click_link 'Play Now'
end
it 'shows and starts the game' do
#TODO: Deprecated it shows the game title
#expect(page).to have_content "Test Game"
# expect(page).to have_content "Hand to beat"
#it 'is located at the correct url' do
# expect(current_path).to eq table_path(@table)
#it 'shows the visitor as a player' do
@player = @game.players.last
@playerComponent = page.find_all(".seat").first
#TODO: have_content @player.display_name
expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..4]}")
#it 'shows other players' do
# Add another player
@user2 = FactoryGirl.create :user
@seats = @game.table.seats.map { |s| s.occupied? ? nil : s}
@seats.compact.first.sit(@user2)
#TODO: Remove race condition
visit current_path
expect(page).to have_content @user2.display_name
game_count = Game.all.count
#it 'the game is startable' do
click_button 'Start'
#TODO: Remove race condition
visit current_path
visit current_path
visit current_path
visit current_path
expect(page).to have_content 'Hand to beat'
expect(Game.all.count).to eq (game_count + 1)
end
end
end
end