# 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', js: true do
    visit new_game_path
    fill_in 'game_title', with: 'Test Game'
    click_button 'Create Game'
    expect(page).to have_button("Sit")
    click_button 'Sit', match: :first
    #TODO: Fix this asynchronous race condition
    visit current_path
    @game = Game.find(current_path.split('/').last)
    @player = @game.players.last
    @playerComponent = page.find("#player-1")
    expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..5]}")
  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
