require_relative 'requires'

# Note: This project is in poor condition and should be considered as a base template for getting started.
# Should work to move off direct xpaths.
# Also need to address how to send_keys on older API's (like 19)
# All pages within the 'pages' folder also should be fixed and possibly utilized.

describe 'Directory Screen Navigation' do

  it 'Remove Get Google Play Services prompt' do
    skip('Not always necessary')
    id('android:id/button1').click
  end

  it 'Can tap on a game' do
    #sixth_game = xpath('//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v4.widget.DrawerLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.GridView[1]/android.widget.FrameLayout[7]/android.widget.TextView[1]')
    sleep(3)
    find('tv.twitch.android.app:id/showcase_button').click #Click out of Chromecast Prompt

    game = find('tv.twitch.android.app:id/game_name')
    game.click

    sleep(1)
    find('android.widget.TextView').name == game.name

  end

  it 'Can tap on a channel' do
    channel = find('tv.twitch.android.app:id/channel_title')
    channel.click

    find_exact(channel.name)
  end

  it 'User can log in' do
    skip('Send Keys not fully implemented yet')
    nav_bar = xpath('//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v4.widget.DrawerLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.View[1]/android.widget.ImageButton[1]')

    nav_bar.click
    find('Login').click
    sleep(5)

    username_field = xpath('//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.View[1]/android.view.View[3]/android.widget.EditText[1]')
    username_field.send_keys 'bt_dylan'
    password_field = xpath('//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.View[1]/android.view.View[5]/android.widget.EditText[1]')
    password_field.send_keys '12345'

    button_exact('Log In').click

    sleep(3)


  end

  it 'User can search' do
    skip()
    nav_bar = xpath('//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v4.widget.DrawerLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.View[1]/android.widget.ImageButton[1]')

    nav_bar.click
    find('Search').click

    search_bar = xpath('//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v4.widget.DrawerLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.View[1]/android.support.v7.widget.LinearLayoutCompat[1]/android.support.v7.widget.LinearLayoutCompat[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.EditText[1]')

    search_bar.click
    sleep(3)
    search_bar.send_keys 'testing'
    sleep(3)
  end
end