require 'rails_helper'
include Warden::Test::Helpers
Warden.test_mode!

feature 'Play a hand', type: :feature, js: true do
  before(:each) do
    @game = setup_visitor_game
    visit game_path @game
    click_button "Sit", match: :first
    #TODO: Fix race condition
    sleep 2
    click_button "Start"
    @game.reload
  end

  after(:each) do
    Warden.test_reset!
  end

  scenario 'player can see their own 13 card faces' do
    #TODO: Fix race condition
    sleep 2
    expect(page.find_all("#inventory img").length).to eq(13)
  end

  scenario 'player can see other players 13 card backs' do
    #TODO: Remove race condition
    sleep 2
    inventories = page.find_all(".inventory")
    inventories.each do |inventory|
      #TODO: This test should verify that other players card fronts are NOT seen
      expect(inventory.find_all("img").length).to eq(13)
    end
  end

end
