2012-08-31 03:01:52 +00:00
include ApplicationHelper
2014-03-20 11:53:26 +00:00
# add a hover_intent method to element, so that you can do find(selector).hover_intent
module Capybara
module Node
class Element
2014-04-11 14:45:54 +00:00
def attempt_hover
begin
hover
rescue = > e
end
end
2014-03-20 11:53:26 +00:00
def hover_intent
hover
2014-04-11 14:45:54 +00:00
sleep 0 . 3
attempt_hover
sleep 0 . 3
attempt_hover
2014-03-20 11:53:26 +00:00
end
2014-08-19 19:23:41 +00:00
def help_bubble
2016-07-17 15:16:27 +00:00
hover_intent
2014-08-19 19:23:41 +00:00
end
2014-03-20 11:53:26 +00:00
end
end
end
2013-12-21 15:12:25 +00:00
# holds a single test's session name's, mapped to pooled session names
$capybara_session_mapper = { }
# called in before (or after) test, to make sure each test run has it's own map of session names
def reset_session_mapper
$capybara_session_mapper . clear
2014-03-21 03:23:33 +00:00
Capybara . session_name = :default
2013-01-31 05:43:26 +00:00
end
2013-12-21 15:12:25 +00:00
# manages the mapped session name
def mapped_session_name ( session_name )
return :default if session_name == :default # special treatment for the built-in session
2014-03-20 11:53:26 +00:00
$capybara_session_mapper [ session_name ] || = 'session_' + $capybara_session_mapper . length . to_s
2013-12-21 15:12:25 +00:00
end
# in place of ever using Capybara.session_name directly,
# this utility is used to handle the mapping of session names in a way across all tests runs
2021-03-24 13:17:16 +00:00
def in_client ( name , & blk )
2013-12-21 15:12:25 +00:00
session_name = name . class == JamRuby :: User ? name . id : name
2013-10-16 06:15:34 +00:00
2021-03-24 13:17:16 +00:00
#Capybara.session_name = mapped_session_name(session_name)
2013-10-16 06:15:34 +00:00
2021-03-24 13:17:16 +00:00
Capybara . using_session ( session_name , & blk )
2013-10-16 06:15:34 +00:00
end
2013-12-21 15:12:25 +00:00
def cookie_jar
Capybara . current_session . driver . browser . current_session . instance_variable_get ( :@rack_mock_session ) . cookie_jar
end
2014-01-07 19:40:26 +00:00
2014-01-07 22:32:16 +00:00
#see also ruby/spec/support/utilities.rb
JAMKAZAM_TESTING_BUCKET = 'jamkazam-testing' #at least, this is the name given in jam-ruby
2014-01-07 19:40:26 +00:00
def wipe_s3_test_bucket
2014-01-07 22:32:16 +00:00
s3 = AWS :: S3 . new ( :access_key_id = > Rails . application . config . aws_access_key_id ,
:secret_access_key = > Rails . application . config . aws_secret_access_key )
2014-01-07 19:40:26 +00:00
test_bucket = s3 . buckets [ JAMKAZAM_TESTING_BUCKET ]
if test_bucket . name == JAMKAZAM_TESTING_BUCKET
2014-02-02 01:30:23 +00:00
test_bucket . objects . each do | obj |
obj . delete
end
2014-01-07 19:40:26 +00:00
end
end
2013-12-21 15:12:25 +00:00
2015-07-15 22:04:21 +00:00
def authorize_google_user ( youtube_client , user , google_password )
2014-11-04 00:28:28 +00:00
youtube_client . wait_for_callback ( 2112 ) do | access_token |
#puts("Authorizing with token #{access_token}")
user_auth_hash = {
:provider = > " google_login " ,
2015-07-15 22:04:21 +00:00
:uid = > user . email ,
:token = > access_token ,
2014-11-04 00:28:28 +00:00
:token_expiration = > nil ,
:secret = > " "
}
authorization = user . user_authorizations . build ( user_auth_hash )
authorization . save
end
url = youtube_client . get_login_url ( user . email )
2015-07-20 16:58:33 +00:00
#puts("Login URL: #{url}")
2014-11-04 00:28:28 +00:00
visit url
sleep ( 1 )
2015-07-15 22:04:21 +00:00
# (the username is filled in with a hint in URL):
2014-11-04 00:28:28 +00:00
# fill_in "Usernm", with: user.email
2015-07-15 22:04:21 +00:00
find ( '#next' ) . trigger ( :click )
sleep ( 5 )
2014-11-04 00:28:28 +00:00
2015-07-15 22:04:21 +00:00
# Fill in password
fill_in " Passwd " , with : google_password
2014-11-04 00:28:28 +00:00
find ( '#signIn' ) . trigger ( :click )
2015-07-15 22:04:21 +00:00
2014-11-04 00:28:28 +00:00
# Wait for submit to enable and then click it:
sleep ( 5 )
2015-07-20 16:58:33 +00:00
save_screenshot ( " about_to_submit.png " )
2014-11-04 00:28:28 +00:00
find ( '#submit_approve_access' ) . trigger ( :click )
sleep ( 5 )
youtube_client
end
2013-12-21 15:12:25 +00:00
2012-08-31 03:01:52 +00:00
def sign_in ( user )
visit signin_path
2014-07-09 19:10:42 +00:00
within ( '#landing-inner form.signin-form' ) do
fill_in " Email " , with : user . email
fill_in " Password " , with : user . password
click_button " SIGN IN "
end
2012-08-31 03:01:52 +00:00
# Sign in when not using Capybara as well.
2013-01-31 05:43:26 +00:00
cookie_jar [ :remember_token ] = user . remember_token
2013-05-15 01:26:27 +00:00
end
2014-03-21 03:23:33 +00:00
def set_cookie ( k , v )
case Capybara . current_session . driver
when Capybara :: Poltergeist :: Driver
page . driver . set_cookie ( k , v )
when Capybara :: RackTest :: Driver
headers = { }
Rack :: Utils . set_cookie_header! ( headers , k , v )
cookie_string = headers [ 'Set-Cookie' ]
Capybara . current_session . driver . browser . set_cookie ( cookie_string )
when Capybara :: Selenium :: Driver
page . driver . browser . manage . add_cookie ( :name = > k , :value = > v )
else
raise " no cookie-setter implemented for driver #{ Capybara . current_session . driver . class . name } "
end
end
2013-05-15 01:26:27 +00:00
2021-02-15 04:32:27 +00:00
# def sign_in_poltergeist(user, options = {})
# validate = options[:validate]
# validate = true if validate.nil?
# if user.password.nil? && !options[:password]
# raise "user has no password. Use a user newly created so that it's password is still present"
# end
# uri = URI.parse(current_url)
# # in tests, we often have an issue where an old signin screen is unloading
# # as this one is loading.
# # so one way to fix this is to go to a different page in this case, and then come back to /signin
# if uri.path == signin_path
# visit '/'
# should_be_at_root
# end
# visit signin_path
# page.should have_selector('#landing-inner form.signin-form')
# within('#landing-inner form.signin-form') do
# fill_in "Email Address:", with: user.email
# fill_in "Password:", with: options[:password] || user.password
# click_button "SIGN IN"
# end
# page.should have_no_selector('h1', text: 'sign in or register')
# wait_until_curtain_gone
# # presence of this means websocket gateway is not working
# page.should have_no_selector('.no-websocket-connection') if validate
#end
2014-04-09 17:25:52 +00:00
def sign_in_poltergeist ( user , options = { } )
validate = options [ :validate ]
validate = true if validate . nil?
2016-04-26 03:01:15 +00:00
if user . password . nil? && ! options [ :password ]
raise " user has no password. Use a user newly created so that it's password is still present "
end
2014-07-09 22:20:20 +00:00
uri = URI . parse ( current_url )
# in tests, we often have an issue where an old signin screen is unloading
# as this one is loading.
# so one way to fix this is to go to a different page in this case, and then come back to /signin
if uri . path == signin_path
visit '/'
should_be_at_root
end
2015-07-15 22:04:21 +00:00
visit signin_path
2014-11-04 00:28:28 +00:00
page . should have_selector ( '#landing-inner form.signin-form' )
2014-07-09 22:20:20 +00:00
within ( '#landing-inner form.signin-form' ) do
fill_in " Email Address: " , with : user . email
2016-04-26 03:01:15 +00:00
fill_in " Password: " , with : options [ :password ] || user . password
2014-07-09 22:20:20 +00:00
click_button " SIGN IN "
end
page . should have_no_selector ( 'h1' , text : 'sign in or register' )
2013-05-15 20:53:19 +00:00
2014-03-20 11:53:26 +00:00
wait_until_curtain_gone
2014-04-09 17:25:52 +00:00
# presence of this means websocket gateway is not working
page . should have_no_selector ( '.no-websocket-connection' ) if validate
2013-10-16 06:15:34 +00:00
end
2013-10-21 22:13:53 +00:00
2014-07-23 23:26:28 +00:00
# skip the typical login form, which redirects to /client (slow due to extra login step).
# So this just sets the cookie, and puts you where you want to be
2014-06-25 21:54:31 +00:00
def fast_signin ( user , url )
2021-02-15 04:32:27 +00:00
visit '/'
2014-07-09 22:20:20 +00:00
set_login_cookie ( user )
2014-06-25 21:54:31 +00:00
visit url
end
#skip the 'hunt' for Sign Out, and redirect after. Just empty cookie, and go to '/'
def fast_signout
2021-02-14 18:10:27 +00:00
create_cookie ( " remember_token " , " " )
2014-06-25 21:54:31 +00:00
visit '/'
end
2014-03-21 16:20:34 +00:00
2014-07-09 22:20:20 +00:00
def set_login_cookie ( user )
2021-02-14 18:10:27 +00:00
create_cookie ( " remember_token " , user . remember_token )
2014-07-09 22:20:20 +00:00
end
2015-07-15 22:04:21 +00:00
2016-04-26 03:01:15 +00:00
def sign_out
2021-02-14 18:10:27 +00:00
delete_cookie ( " remember_token " )
2013-10-22 17:38:21 +00:00
end
2016-05-20 19:31:05 +00:00
def switch_user ( user , url )
sign_out_poltergeist ( validate : true )
fast_signin ( user , url )
end
2014-03-21 16:20:34 +00:00
def sign_out_poltergeist ( options = { } )
2016-05-20 19:31:05 +00:00
sign_out
2014-06-04 19:47:05 +00:00
open_user_dropdown
2014-03-21 16:20:34 +00:00
click_link 'Sign Out'
2016-05-20 19:31:05 +00:00
if options [ :validate ]
visit " / "
find ( '#jamclass-link' )
end
2014-03-21 16:20:34 +00:00
end
2014-06-04 19:47:05 +00:00
def open_user_dropdown
2016-06-03 13:06:47 +00:00
find ( '.userinfo' ) . hover ( )
2014-06-04 19:47:05 +00:00
end
2014-07-01 19:30:38 +00:00
2014-07-10 20:22:00 +00:00
def go_to_root
visit '/'
should_be_at_root
end
2015-04-09 03:43:57 +00:00
def should_be_at_root ( options = { signed_in : nil } )
2021-02-14 18:10:27 +00:00
signed_in = ! get_me_the_cookie ( 'remember_token' ) . nil?
if signed_in
find ( 'h2' , text : 'jamtracks' )
else
find ( 'a.join-today' , text : 'JOIN TODAY, PLAY FREE!' )
end
2014-03-21 16:20:34 +00:00
end
2013-10-21 22:13:53 +00:00
2014-07-01 19:30:38 +00:00
def should_be_at_signin
find ( 'h1' , text : 'sign in or register' )
end
2015-03-11 21:44:22 +00:00
def should_be_at_logged_out_client
find ( '#profile a.signin' , text : 'Sign Up' )
find ( '.musicians.not-logged-in' )
end
2013-11-13 06:58:28 +00:00
def leave_music_session_sleep_delay
# add a buffer to ensure WSG has enough time to expire
2014-04-30 20:29:10 +00:00
sleep_dur = ( Rails . application . config . websocket_gateway_connect_time_stale_browser +
Rails . application . config . websocket_gateway_connect_time_expire_browser ) * 1 . 4
2013-11-13 06:58:28 +00:00
sleep sleep_dur
end
2016-07-17 15:16:27 +00:00
def wait_for_ajax ( wait = Capybara . default_max_wait_time )
2013-10-21 22:13:53 +00:00
wait = wait * 10 #(because we sleep .1)
counter = 0
while page . execute_script ( " $.active " ) . to_i > 0
counter += 1
sleep ( 0 . 1 )
raise " AJAX request took longer than #{ wait } seconds. " if counter > = wait
end
end
# waits until the user object has been requested, which comes after the 'curtain' is lifted
# and after a call to /api/user/:id for the current user is called initially
2016-07-17 15:16:27 +00:00
def wait_until_user ( wait = Capybara . default_max_wait_time )
2013-10-21 22:13:53 +00:00
wait = wait * 10 #(because we sleep .1)
counter = 0
2013-11-16 14:05:23 +00:00
# while page.execute_script("$('.curtain').is(:visible)") == "true"
# counter += 1
# sleep(0.1)
# raise "Waiting for user to populate took longer than #{wait} seconds." if counter >= wait
# end
2013-10-21 22:13:53 +00:00
end
def wait_until_curtain_gone
2014-03-20 11:53:26 +00:00
page . should have_no_selector ( '.curtain' )
2013-11-05 03:00:43 +00:00
end
2013-11-13 06:58:28 +00:00
def wait_to_see_my_track
within ( 'div.session-mytracks' ) { first ( 'div.session-track.track' ) }
end
2016-07-17 15:16:27 +00:00
def repeat_for ( duration = Capybara . default_max_wait_time )
2014-05-07 03:35:00 +00:00
finish_time = Time . now + duration . seconds
loop do
yield
sleep 1 # by default this will execute the block every 1 second
break if ( Time . now > finish_time )
end
end
2013-11-05 03:00:43 +00:00
def determine_test_name ( metadata , test_name_buffer = '' )
description = metadata [ :description_args ]
if description . kind_of? ( Array )
description = description [ 0 ]
end
if metadata . has_key? :example_group
return determine_test_name ( metadata [ :example_group ] , " #{ description } #{ test_name_buffer } " )
else
return " #{ description } #{ test_name_buffer } "
end
end
2014-01-05 02:42:05 +00:00
def get_description
description = example . metadata [ :description_args ]
if description . kind_of? ( Array )
description = description [ 0 ]
end
return description
end
2014-02-10 22:43:09 +00:00
# will select the value from a easydropdown'ed select element
def jk_select ( text , select )
# the approach here is to find the hidden select element, and work way back up to the elements that need to be interacted with
2015-04-24 18:45:47 +00:00
find ( select , :visible = > false ) . find ( :xpath , 'ancestor::div[contains(@class, "dropdown easydropdown") and not(contains(@class, "disabled"))]' ) . trigger ( :click )
find ( select , :visible = > false ) . find ( :xpath , 'ancestor::div[contains(@class, "dropdown-wrapper") and contains(@class, "easydropdown-wrapper") and contains(@class, "open") ]' ) . find ( 'li' , text : text ) . trigger ( :click )
2015-07-15 22:04:21 +00:00
2014-02-10 22:43:09 +00:00
# works, but is 'cheating' because of visible = false
#select(genre, :from => 'genres', :visible => false)
end
2014-01-05 02:42:05 +00:00
2013-11-05 03:00:43 +00:00
# takes, or creates, a unique session description which is returned for subsequent calls to join_session to use
# in finding this session)
2014-04-04 22:16:38 +00:00
def create_session ( options = { } )
creator = options [ :creator ] || FactoryGirl . create ( :user )
2014-06-09 22:13:54 +00:00
unique_session_name = options [ :name ] || " create_join_session #{ SecureRandom . urlsafe_base64 } "
2014-04-04 22:16:38 +00:00
unique_session_desc = options [ :description ] || " create_join_session #{ SecureRandom . urlsafe_base64 } "
2014-09-10 16:27:55 +00:00
genre = options [ :genre ] || 'Alternative Rock'
2014-04-04 22:16:38 +00:00
musician_access = options [ :musician_access ] . nil? ? true : options [ :musician_access ]
2014-06-09 22:13:54 +00:00
approval_required = options [ :approval_required ] . nil? ? true : options [ :approval_required ]
2014-04-04 22:16:38 +00:00
fan_access = options [ :fan_access ] . nil? ? true : options [ :fan_access ]
2014-06-30 22:45:37 +00:00
fan_chat = options [ :fan_chat ] . nil? ? false : options [ :fan_chat ]
2013-11-05 03:00:43 +00:00
# create session in one client
in_client ( creator ) do
2013-12-30 18:34:15 +00:00
page . driver . resize ( 1500 , 800 ) # makes sure all the elements are visible
2014-04-04 22:16:38 +00:00
emulate_client
2014-07-09 22:20:20 +00:00
fast_signin ( creator , " /client # /createSession " )
2014-06-09 22:13:54 +00:00
expect ( page ) . to have_selector ( 'h1' , text : 'create session' )
2013-11-05 03:00:43 +00:00
within ( '#create-session-form' ) do
2014-06-09 22:13:54 +00:00
# step 1
find ( 'li[create-type="immediately"] ins' ) . trigger ( :click )
find ( '.btn-next' ) . trigger ( :click )
# step 2
2014-02-10 22:43:09 +00:00
jk_select ( genre , '#create-session-form select[name="genres"]' )
2014-06-09 22:13:54 +00:00
fill_in ( 'session-name' , :with = > unique_session_name )
fill_in ( 'session-description' , :with = > unique_session_desc )
find ( '.btn-next' ) . trigger ( :click )
# step 3
find ( '.btn-next' ) . trigger ( :click )
# step 4
musician_access_value = " Musicians may join by approval "
if ! musician_access && ! approval_required
musician_access_value = " Only RSVP musicians may join "
elsif musician_access && approval_required
musician_access_value = " Musicians may join at will "
end
jk_select ( musician_access_value , '#session-musician-access' )
fan_access_value = " Fans may listen, chat with each other "
if ! fan_access && ! fan_chat
fan_access_value = 'Fans may not listen to session'
elsif fan_access && fan_chat
2014-06-30 23:54:16 +00:00
fan_access_value = 'Fans may listen, chat with the band' #XXX this option is currently disabled/not available
2014-06-09 22:13:54 +00:00
end
jk_select ( fan_access_value , '#session-fans-access' )
find ( '#divSessionPolicy ins' ) . trigger ( :click )
find ( '.btn-next' ) . trigger ( :click )
2014-04-04 22:16:38 +00:00
2014-06-09 22:13:54 +00:00
# step 5
find ( '.btn-next' ) . trigger ( :click )
2013-11-05 03:00:43 +00:00
end
# verify that the in-session page is showing
2015-07-15 15:04:45 +00:00
expect ( page ) . to have_selector ( 'h2' , text : 'my live tracks' )
find ( '#session-screen .session-my-tracks .session-track.my-track' )
2013-11-05 03:00:43 +00:00
end
2014-01-05 02:42:05 +00:00
return creator , unique_session_desc , genre
2013-11-05 03:00:43 +00:00
end
2014-06-20 16:52:36 +00:00
def schedule_session ( options = { } )
creator = options [ :creator ] || FactoryGirl . create ( :user )
unique_session_name = options [ :name ] || " schedule_session #{ SecureRandom . urlsafe_base64 } "
unique_session_desc = options [ :description ] || " schedule_session #{ SecureRandom . urlsafe_base64 } "
2014-09-10 16:27:55 +00:00
genre = options [ :genre ] || 'Alternative Rock'
2014-06-20 16:52:36 +00:00
musician_access = options [ :musician_access ] . nil? ? true : options [ :musician_access ]
approval_required = options [ :approval_required ] . nil? ? true : options [ :approval_required ]
fan_access = options [ :fan_access ] . nil? ? true : options [ :fan_access ]
2014-06-30 23:54:16 +00:00
fan_chat = options [ :fan_chat ] . nil? ? false : options [ :fan_chat ]
2014-06-20 16:52:36 +00:00
musician_access_value = 'Musicians may join by approval'
fan_permission_value = 'Fans may listen, chat with each other'
2014-07-29 02:14:09 +00:00
rsvp = options [ :rsvp ]
immediate = options [ :immediate ]
quickstart = options [ :quickstart ]
2014-06-20 16:52:36 +00:00
if musician_access && ! approval_required
musician_access_value = 'Musicians may join at will'
elsif ! musician_access && ! approval_required
musician_access_value = 'Only RSVP musicians may join'
end
if fan_access && fan_chat
fan_permission_value = 'Fans may listen, chat with the band'
elsif ! fan_access && ! fan_chat
fan_permission_value = 'Fans may not listen to session'
end
# schedule a session in one client
in_client ( creator ) do
page . driver . resize ( 1500 , 800 ) # makes sure all the elements are visible
emulate_client
2014-07-09 22:20:20 +00:00
fast_signin ( creator , " /client # /createSession " )
2016-08-03 01:46:15 +00:00
expect ( page ) . to have_selector ( 'h1' , text : 'sessions' )
2014-06-20 16:52:36 +00:00
2014-07-02 13:57:18 +00:00
within ( '#create-session-form' ) do
2014-07-29 02:14:09 +00:00
if rsvp
find ( 'li[create-type="rsvp"] ins' ) . trigger ( :click )
elsif immediate
find ( 'li[create-type="immediately"] ins' ) . trigger ( :click )
elsif quickstart
find ( 'li[create-type="quick-start"] ins' ) . trigger ( :click )
else
find ( 'li[create-type="schedule-future"] ins' ) . trigger ( :click )
end
2014-07-02 13:57:18 +00:00
find ( '.btn-next' ) . trigger ( :click )
2014-06-20 16:52:36 +00:00
2014-07-29 02:14:09 +00:00
unless quickstart
jk_select ( genre , '#create-session-form select[name="genres"]' )
fill_in ( 'session-name' , :with = > unique_session_name )
fill_in ( 'session-description' , :with = > unique_session_desc )
find ( '.btn-next' ) . trigger ( :click )
2014-06-20 16:52:36 +00:00
2014-07-29 02:14:09 +00:00
find ( '.btn-next' ) . trigger ( :click )
2014-06-20 16:52:36 +00:00
2014-07-29 02:14:09 +00:00
find ( 'div#divSessionPolicy ins' ) . trigger ( :click )
jk_select ( musician_access_value , '#session-musician-access' )
jk_select ( fan_permission_value , '#session-fans-access' )
find ( '.btn-next' ) . trigger ( :click )
end
2014-06-20 16:52:36 +00:00
2015-04-17 19:01:07 +00:00
if immediate
2014-07-29 02:14:09 +00:00
find ( '.btn-next' , text : 'START SESSION' ) . trigger ( :click )
2015-04-17 19:01:07 +00:00
elsif ! quickstart
find ( '.btn-next' , text : 'PUBLISH SESSION' ) . trigger ( :click )
2014-07-29 02:14:09 +00:00
end
2014-07-02 13:57:18 +00:00
end
2014-06-20 16:52:36 +00:00
2014-07-29 02:14:09 +00:00
# find('h2', text: 'create session') unless quickstart || immediate
2014-06-26 02:50:20 +00:00
2014-06-24 04:03:04 +00:00
sleep 1 # to get rid of this, we need to verify that the URL is /client#/home.. otherwise intermittent fails
2014-06-20 16:52:36 +00:00
end
2014-07-02 13:57:18 +00:00
return creator , unique_session_name , genre
2014-06-20 16:52:36 +00:00
end
2013-11-05 03:00:43 +00:00
# this code assumes that there are no music sessions in the database. it should fail on the
2013-12-14 23:53:18 +00:00
# find('.join-link') call if > 1 session exists because capybara will complain of multiple matches
2014-04-04 22:16:38 +00:00
def join_session ( joiner , options )
description = options [ :description ]
2013-11-05 03:00:43 +00:00
in_client ( joiner ) do
2014-04-04 22:16:38 +00:00
page . driver . resize ( 1500 , 800 ) # makes sure all the elements are visible
emulate_client
2014-07-09 22:20:20 +00:00
fast_signin ( joiner , " /client # /findSession " )
2013-11-05 03:00:43 +00:00
# verify the session description is seen by second client
2014-04-04 22:16:38 +00:00
expect ( page ) . to have_text ( description )
2013-11-05 03:00:43 +00:00
find ( '.join-link' ) . trigger ( :click )
2014-10-29 03:25:55 +00:00
unless options [ :no_verify ]
find ( '#btn-accept-terms' ) . trigger ( :click )
2015-07-15 15:04:45 +00:00
expect ( page ) . to have_selector ( 'h2' , text : 'my live tracks' )
find ( '#session-screen .session-my-tracks .session-track.my-track' )
2014-10-29 03:25:55 +00:00
end
2013-11-05 03:00:43 +00:00
end
end
2015-02-02 02:20:39 +00:00
def request_to_join_session ( joiner , options )
join_session ( joiner , options . merge ( no_verify : true ) )
2015-02-02 02:38:21 +00:00
find ( '#btn-alert-ok' ) . trigger ( :click )
# page.should have_no_selector('h1', text: 'Alert')
2015-02-02 02:20:39 +00:00
end
2014-04-04 22:16:38 +00:00
def emulate_client
2021-02-15 04:32:27 +00:00
#page.driver.headers = { 'User-Agent' => ' JamKazam ' }
2021-06-11 11:55:18 +00:00
#Rails.application.config.allow_force_native_client = true
#create_cookie(:act_as_native_client, "true")
allow_any_instance_of ( ClientHelper ) . to receive ( :is_native_client? ) . and_return ( true )
2014-04-04 22:16:38 +00:00
end
def create_join_session ( creator , joiners = [ ] , options = { } )
options [ :creator ] = creator
creator , unique_session_desc = create_session ( options )
2013-11-05 03:00:43 +00:00
# find session in second client
2015-02-02 03:40:23 +00:00
[ * joiners ] . each do | joiner |
2014-04-04 22:16:38 +00:00
join_session ( joiner , description : unique_session_desc )
2013-11-05 03:00:43 +00:00
end
2014-04-04 22:16:38 +00:00
return creator , unique_session_desc
2013-11-12 04:57:04 +00:00
end
2014-02-23 03:12:12 +00:00
def formal_leave_by user
in_client ( user ) do
2015-07-15 15:04:45 +00:00
find ( '.session-leave.leave' ) . trigger ( :click )
2014-02-25 03:25:34 +00:00
#find('#btn-accept-leave-session').trigger(:click)
2014-02-23 03:12:12 +00:00
expect ( page ) . to have_selector ( 'h2' , text : 'feed' )
end
end
2015-02-02 03:40:23 +00:00
def verify_feed_shows_users * users
users = [ * users ]
visit " /client # /feed "
find ( '.feed-details a.details' ) . trigger ( :click )
within 'div.music-session-history-entry' do
users . each do | user |
# confirm user avatar exists
find ( " a.avatar-tiny[user-id= \" #{ user . id } \" ][hoveraction= \" musician \" ] img " )
# confirm user name exists
find ( " a.musician-name[user-id= \" #{ user . id } \" ][hoveraction= \" musician \" ] " , text : user . name )
end
end
end
2014-01-05 02:42:05 +00:00
def start_recording_with ( creator , joiners = [ ] , genre = nil )
2015-07-16 21:09:42 +00:00
2014-04-04 22:16:38 +00:00
create_join_session ( creator , joiners , { genre : genre } )
2014-01-05 02:42:05 +00:00
in_client ( creator ) do
2015-07-15 15:04:45 +00:00
find ( '.session-record' ) . trigger ( :click )
2015-07-16 01:42:34 +00:00
# gotta wait for popup
sleep 1
2015-07-16 21:09:42 +00:00
page . within_window ( - > { page . title == 'JamKazam | Recording Controls' } ) do
2015-07-15 15:04:45 +00:00
find ( '#recording-status' , text : 'Start Recording' )
find ( 'a.control' ) . trigger ( :click )
find ( '#recording-status' , text : 'Stop Recording' )
end
2014-01-05 02:42:05 +00:00
end
2015-07-16 21:09:42 +00:00
2014-01-05 02:42:05 +00:00
joiners . each do | joiner |
2015-07-16 01:42:34 +00:00
# gotta wait for popup
sleep 1
2014-01-05 02:42:05 +00:00
in_client ( joiner ) do
find ( '#notification' ) . should have_content 'started a recording'
2015-07-15 15:04:45 +00:00
find ( '.session-record[data-is-recording="true"]' )
2014-01-05 02:42:05 +00:00
end
end
end
def stop_recording
2015-07-15 15:04:45 +00:00
find ( '.session-record[data-is-recording="true"]' )
2015-07-16 01:42:34 +00:00
# gotta wait for popup
sleep 1
2015-07-16 21:09:42 +00:00
page . within_window ( - > { page . title == 'JamKazam | Recording Controls' } ) do
find ( '#recording-status' , text : 'Stop Recording' )
2015-07-15 15:04:45 +00:00
find ( 'a.control' ) . trigger ( :click )
end
2015-07-16 21:09:42 +00:00
2014-01-05 02:42:05 +00:00
end
def assert_recording_finished
2015-07-16 21:09:42 +00:00
find ( '.session-record[data-is-recording="false"]' , visible : false )
2014-01-05 02:42:05 +00:00
should have_selector ( 'h1' , text : 'recording finished' )
end
def check_recording_finished_for ( users = [ ] )
users . each do | user |
in_client ( user ) do
assert_recording_finished
end
end
end
def claim_recording ( name , description )
find ( '#recording-finished-dialog h1' )
fill_in " claim-recording-name " , with : name
fill_in " claim-recording-description " , with : description
2015-07-15 15:04:45 +00:00
jk_select ( 'Alternative Rock' , '#recording-finished-dialog .genre-selector select' )
2014-01-05 02:42:05 +00:00
find ( '#keep-session-recording' ) . trigger ( :click )
2014-04-29 07:33:37 +00:00
page . should have_no_selector ( 'h1' , text : 'recording finished' )
2014-01-05 02:42:05 +00:00
end
2013-11-12 04:57:04 +00:00
2015-02-02 02:20:39 +00:00
def set_session_access access_type
case access_type
when :only_rsvp , :private
access_level = " Only RSVP musicians may join "
when :by_approval
access_level = " Musicians may join by approval "
when :at_will , :public , :open
access_level = " Musicians may join at will "
else
access_level = " Musicians may join at will "
2013-11-12 04:57:04 +00:00
end
2015-07-15 15:04:45 +00:00
find ( '.session-settings' ) . trigger ( :click )
2013-12-14 23:53:18 +00:00
within ( '#session-settings-dialog' ) do
2015-02-02 02:20:39 +00:00
jk_select ( access_level , '#session-settings-dialog #session-settings-musician-access' )
2013-12-14 23:53:18 +00:00
find ( '#session-settings-dialog-submit' ) . trigger ( :click )
2013-11-12 04:57:04 +00:00
end
2014-05-07 02:48:02 +00:00
# verify it's dismissed
page . should have_no_selector ( 'h1' , text : 'update session settings' )
2013-11-13 06:58:28 +00:00
end
2013-12-14 23:53:18 +00:00
def get_options ( selector )
2014-02-10 22:43:09 +00:00
find ( selector , :visible = > false ) . all ( 'option' , :visible = > false ) . collect ( & :text ) . uniq
2013-12-14 23:53:18 +00:00
end
2014-01-05 02:42:05 +00:00
def selected_genres ( selector = '#session-settings-genre' )
2014-02-10 22:43:09 +00:00
page . evaluate_script ( " JK.GenreSelectorHelper.getSelectedGenres(' #{ selector } ') " )
2014-01-05 02:42:05 +00:00
end
def random_genre
[ 'African' ,
'Ambient' ,
'Asian' ,
'Blues' ,
'Classical' ,
'Country' ,
'Electronic' ,
'Folk' ,
'Hip Hop' ,
'Jazz' ,
'Latin' ,
'Metal' ,
'Pop' ,
'R&B' ,
'Reggae' ,
'Religious' ,
2014-09-10 16:27:55 +00:00
'Alternative Rock' ,
2014-01-05 02:42:05 +00:00
'Ska' ,
'Other' ] . sample
2013-12-14 23:53:18 +00:00
end
def change_session_genre #randomly just change it
here = 'select.genre-list'
#wait_for_ajax
2015-07-15 15:04:45 +00:00
find ( '.session-settings' ) . trigger ( :click )
2014-04-16 03:09:16 +00:00
find ( '#session-settings-dialog' ) # ensure the dialog is visible
2013-12-14 23:53:18 +00:00
within ( '#session-settings-dialog' ) do
wait_for_ajax
2014-07-31 04:43:04 +00:00
@new_genre = get_options ( here ) . - ( [ " Select Genre " , " Unspecified " ] ) . - ( selected_genres ) . sample . to_s
2014-02-10 22:43:09 +00:00
jk_select ( @new_genre , '#session-settings-dialog select[name="genres"]' )
2013-12-14 23:53:18 +00:00
wait_for_ajax
find ( '#session-settings-dialog-submit' ) . trigger ( :click )
end
return @new_genre
end
def get_session_genre
here = 'select.genre-list'
2015-07-15 15:04:45 +00:00
find ( '.session-settings' ) . trigger ( :click )
2013-12-14 23:53:18 +00:00
wait_for_ajax
@current_genres = selected_genres
find ( '#session-settings-dialog-submit' ) . trigger ( :click )
return @current_genres . join ( " " )
end
def find_session_contains? ( text )
visit " /client # /findSession "
wait_for_ajax
within ( '#find-session-form' ) do
expect ( page ) . to have_text ( text )
end
end
2013-11-13 06:58:28 +00:00
def assert_all_tracks_seen ( users = [ ] )
users . each do | user |
in_client ( user ) do
users . reject { | u | u == user } . each do | other |
2015-07-15 15:04:45 +00:00
find ( " .session-track " , text : other . name )
2013-11-13 06:58:28 +00:00
#puts user.name + " is able to see " + other.name + "\'s track"
end
end
end
2014-01-05 02:42:05 +00:00
end
2014-04-14 20:52:26 +00:00
def view_profile_of user
id = user . kind_of? ( JamRuby :: User ) ? user . id : user
2014-04-16 03:09:16 +00:00
# assume some user signed in already
2014-04-14 20:52:26 +00:00
visit " /client # /profile/ #{ id } "
wait_until_curtain_gone
end
2014-04-16 03:09:16 +00:00
def view_band_profile_of band
id = band . kind_of? ( JamRuby :: Band ) ? band . id :
band . kind_of? ( JamRuby :: BandMusician ) ? band . bands . first . id : band
visit " /client # /bandProfile/ #{ id } "
wait_until_curtain_gone
end
2014-05-07 03:35:00 +00:00
def sidebar_search_for string , category
visit " /client # /home "
find ( '#search-input' )
fill_in " search " , with : string
sleep 1
page . execute_script ( " JK.Sidebar.searchForInput() " )
wait_for_ajax
jk_select ( category , " search_text_type " )
wait_for_ajax
end
2015-02-09 02:25:55 +00:00
def expand_sidebar header_name
#search, friends, chat, notifications
panel_id = " panel #{ header_name . to_s . capitalize } "
within ( " div[layout-id=' #{ panel_id } '] " ) { find ( 'div.panel-header' ) . trigger ( :click ) }
end
2014-01-05 02:42:05 +00:00
def show_user_menu
page . execute_script ( " $('ul.shortcuts').show() " )
#page.execute_script("JK.UserDropdown.menuHoverIn()")
2014-02-10 22:43:09 +00:00
end
# wait for the easydropdown version of the specified select element to become visible
def wait_for_easydropdown ( select )
find ( select , :visible = > false ) . find ( :xpath , 'ancestor::div[contains(@class, "dropdown easydropdown")]' )
2014-03-20 11:53:26 +00:00
end
# defaults to enter key (13)
2014-04-09 17:25:52 +00:00
def send_key ( selector , keycode = 13 )
keypress_script = " var e = $.Event('keyup', { keyCode: #{ keycode } }); jQuery(' #{ selector } ').trigger(e); "
2014-03-20 11:53:26 +00:00
page . driver . execute_script ( keypress_script )
2015-08-18 19:26:41 +00:00
end
def send_key_sequence ( selector , text )
text . each_char do | char |
keycode = char . ord - 32
keypress_script = " var e = $.Event('keydown', { keyCode: #{ keycode } }); jQuery(' #{ selector } ').trigger(e); "
page . driver . execute_script ( keypress_script )
end
2014-03-20 11:53:26 +00:00
2014-04-14 20:52:26 +00:00
end
2015-08-18 19:26:41 +00:00
def send_keydown ( selector , keycode = 13 )
keypress_script = " var e = $.Event('keydown', { keyCode: #{ keycode } }); jQuery(' #{ selector } ').trigger(e); "
page . driver . execute_script ( keypress_script )
end
2014-04-14 20:52:26 +00:00
def special_characters
[ " ? " , " [ " , " ] " , " / " , " \\ " , " = " , " < " , " > " , " : " , " ; " , " , " , " ' " , " \" " , " & " , " $ " , " # " , " * " , " ( " , " ) " , " | " , " ~ " , " ` " , " ! " , " { " , " } " ]
end
def garbage length
output = ''
length . times { output << special_characters . sample }
output . slice ( 0 , length )
2014-05-19 21:57:08 +00:00
end
2014-06-27 19:17:56 +00:00
def nav_profile_history ( user )
visit Nav . profile ( user )
2015-05-01 01:53:19 +00:00
find ( '#history-link' ) . trigger ( :click )
2021-06-01 14:45:13 +00:00
end
2021-06-08 14:39:55 +00:00
def mock_latency_response ( collection )
resp = [ ]
if collection && collection . any?
resp = collection . map do | latency_item |
2021-06-09 17:58:59 +00:00
user = latency_item [ :user ]
latency = latency_item [ :latency ]
audio_latency = latency_item [ :audio_latency ]
audio_latency_unknown = latency_item [ :audio_latency_unknown ]
ars_internet_latency = latency_item [ :ars_internet_latency ]
ars_total_latency = latency_item [ :ars_total_latency ]
p2p_internet_latency = latency_item [ :p2p_internet_latency ]
p2p_total_latency = latency_item [ :p2p_total_latency ]
wifi = latency_item [ :wifi ]
2021-06-08 14:39:55 +00:00
{
" user_id " : user . id ,
" first_name " : user . first_name ,
" last_name " : user . last_name ,
2021-06-09 17:58:59 +00:00
" audio_latency " : audio_latency ,
" audio_latency_unknown " : audio_latency_unknown ,
2021-06-08 14:39:55 +00:00
" ars " : {
2021-06-09 17:58:59 +00:00
" internet_latency " : ars_internet_latency ,
" total_latency " : ars_total_latency
2021-06-08 14:39:55 +00:00
} ,
" p2p " : {
2021-06-09 17:58:59 +00:00
" internet_latency " : p2p_internet_latency ,
" total_latency " : p2p_total_latency
2021-06-08 14:39:55 +00:00
} ,
2021-06-09 17:58:59 +00:00
" wifi " : wifi
2021-06-08 14:39:55 +00:00
}
end
end
output = if resp . any?
{
" users " : resp ,
2021-06-01 14:45:13 +00:00
" my_audio_latency " : 4 . 0 ,
" my_audio_latency_unknown " : false
}
else
2021-06-08 14:39:55 +00:00
{
2021-06-01 14:45:13 +00:00
" users " : [ ]
}
end
2021-06-08 14:39:55 +00:00
output . to_json
2014-06-27 19:17:56 +00:00
end