From 673132c540bed67e5aaa72433e34e31a48733151 Mon Sep 17 00:00:00 2001 From: Anthony Davis Date: Tue, 6 May 2014 22:35:00 -0500 Subject: [PATCH] VRFS-1651 - periodic real test of www --- web/spec/features/production_spec.rb | 92 ++++++++++++++++++++++++++++ web/spec/spec_helper.rb | 3 + web/spec/support/utilities.rb | 21 ++++++- 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 web/spec/features/production_spec.rb diff --git a/web/spec/features/production_spec.rb b/web/spec/features/production_spec.rb new file mode 100644 index 000000000..152bb94bc --- /dev/null +++ b/web/spec/features/production_spec.rb @@ -0,0 +1,92 @@ +require 'spec_helper' + +# these tests MUST be idempotent and DO use actual production user accounts on www +www = 'http://www.jamkazam.com' + +describe "Production site at #{www}", :test_www => true, :js => true, :type => :feature, :capybara_feature => true do + + subject { page } + + before(:all) do + Capybara.javascript_driver = :poltergeist + Capybara.current_driver = Capybara.javascript_driver + Capybara.app_host = www + Capybara.run_server = false + Capybara.default_wait_time = 10 + end + + TestUser = Class.new do + attr_accessor :email, :password, :first_name, :last_name, :id + + def initialize(h) + h.each {|k,v| send("#{k}=",v)} + end + + alias :to_s :first_name + + def name + first_name + ' ' + last_name + end + end + + user1 = TestUser.new({ email: 'anthony+jim@jamkazam.com', password: 'j4m!t3st3r', first_name: 'Jim', last_name: 'Smith', id: '68e8eea2-140d-44c1-b711-10d07ce70f96' }) + user2 = TestUser.new({ email: 'anthony+john@jamkazam.com', password: 'j4m!t3st3r', first_name: 'John', last_name: 'Jones', id: '5bbcf689-2f73-452d-815a-c4f44e9e7f3e' }) + +# before(:each) do +# emulate_client +# end + + it "is possible for #{user1} to sign in and not get disconnected within 30 seconds" do + in_client(user1) do + sign_in_poltergeist user1 + repeat_for(30.seconds) do + expect(page).to_not have_selector('.no-websocket-connection') #looks for reconnect dialog every 1 second + end + end + end + + it "is possible for #{user1} and #{user2} to see each other online, and to send messages" do + # this example heavily based on text_message_spec.rb + + in_client(user1) do + sign_in_poltergeist(user1) + end + + test_message = "#{SecureRandom.uuid} - Hey #{user1}!" + test_response = "#{SecureRandom.uuid} - Hey yourself, #{user2}!" + test_goodbye = "#{SecureRandom.uuid} - OK bye!" + + in_client(user2) do + sign_in_poltergeist(user2) + expect(page).to have_xpath( + "//div[@class='friend-name' and @user-id='#{user1.id}']/span[@class='friend-status']", + :text => "Available" ) + + site_search(user1.name, expand: true) + find("#search-results a[user-id=\"#{user1.id}\"][hoveraction=\"musician\"]", text: user1.name).hover_intent + find('#musician-hover #btnMessage').trigger(:click) + find('h1', text: 'conversation with ' + user1.name) + send_text_message(test_message) + end + + in_client(user1) do + expect(page).to have_xpath( + "//div[@class='friend-name' and @user-id='#{user2.id}']/span[@class='friend-status']", + :text => "Available" ) + find('#notification #ok-button').trigger(:click) + find('h1', text: 'conversation with ' + user2.name) + find('.previous-message-text', text: test_message) + send_text_message(test_response, close_on_send: true) + end + + in_client(user2) do + find('.previous-message-text', text: test_response) + send_text_message(test_goodbye, close_on_send: true) + end + + in_client(user1) { sign_out_poltergeist } + in_client(user2) { sign_out_poltergeist } + end + +end + diff --git a/web/spec/spec_helper.rb b/web/spec/spec_helper.rb index d3f3dccbe..a27f22a65 100644 --- a/web/spec/spec_helper.rb +++ b/web/spec/spec_helper.rb @@ -160,6 +160,9 @@ bputs "before register capybara" config.filter_run_excluding slow: true unless ENV['RUN_SLOW_TESTS'] == "1" || ENV['SLOW'] == "1" || ENV['ALL_TESTS'] == "1" config.filter_run_excluding aws: true unless ENV['RUN_AWS_TESTS'] == "1" || ENV['AWS'] == "1" || ENV['ALL_TESTS'] == "1" + # by default, do not run production web tests -- even when "ALL_TESTS" is desired + config.filter_run_excluding test_www: true unless ENV['TEST_WWW'] == "1" + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" diff --git a/web/spec/support/utilities.rb b/web/spec/support/utilities.rb index bfd7e150d..57f24ae2d 100644 --- a/web/spec/support/utilities.rb +++ b/web/spec/support/utilities.rb @@ -169,6 +169,15 @@ def wait_to_see_my_track within('div.session-mytracks') {first('div.session-track.track')} end +def repeat_for(duration=Capybara.default_wait_time) + 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 + def determine_test_name(metadata, test_name_buffer = '') description = metadata[:description_args] if description.kind_of?(Array) @@ -430,6 +439,17 @@ def view_band_profile_of band wait_until_curtain_gone end +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 + def show_user_menu page.execute_script("$('ul.shortcuts').show()") #page.execute_script("JK.UserDropdown.menuHoverIn()") @@ -454,6 +474,5 @@ end def garbage length output = '' length.times { output << special_characters.sample } - output.gsub!(/<[\/|!|\?]/, '/<') # security risk -- avoids inputting tags until VRFS-1609 resolved output.slice(0, length) end \ No newline at end of file