# Feature: Join Game
#   As a visitor
#   I want to join a game
#   So I can play
feature 'Join game', :devise do
  # Scenario: Visitor can join a game
  #   Given I am not signed in
  #   When I visit a joinable game
  #   Then I see a join button
  scenario 'visitor can join a game' do
    visit new_table_path
    fill_in 'table_title', with: 'Test Game'
    click_button 'Create Table'
    puts current_path
    expect(page).to have_button("Sit")
    click_button 'Sit', match: :first
    #TODO: Fix this asynchronous race condition
    visit current_path
    @table = Table.find(current_path.split('/').last)
    @player = @table.current_game.players.last
    @playerComponent = page.find_all(".seat").first
    expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..4]}")
  end

  scenario 'visitor can join a game in progress' do
    pending "To Be Implemented"
    expect(page).to have_content "Waiting for next game."
  end
end
