module LoginHelper
  def login(user, context)

    context.visit root_path

    # When troubleshooting JS errors, sleeping when the UI first comes up is helpful.
    # It allows you to bring up a JS console on the test browser and see what the problem is.
    # sleep 60

    # verify that the sign in form is showing
    context.should have_content "sign in or register"

    context.fill_in 'Email', :with => user.email
    context.fill_in 'Password', :with => user.password
    context.click_button 'SIGN IN'

    # There are delays in the main app due to us waiting until we're connected to
    # the websocket gateway. Tough to test, but adding a sleep to see if this
    # gets us past it.
    sleep 4

    # verify that the client page is showing
    # Temporary comment - we're skipping FTUE for video...
    # context.find("h1:contains('Audio Gear Setup')").should be_visible
  end
end

World(LoginHelper)
