diff --git a/web/app/views/clients/_session.html.erb b/web/app/views/clients/_session.html.erb index f90c4eb42..aa74a537e 100644 --- a/web/app/views/clients/_session.html.erb +++ b/web/app/views/clients/_session.html.erb @@ -38,7 +38,7 @@ - X  LEAVE + X  LEAVE diff --git a/web/spec/features/find_sessions_spec.rb b/web/spec/features/find_sessions_spec.rb index 311dd6366..ff476c6cc 100644 --- a/web/spec/features/find_sessions_spec.rb +++ b/web/spec/features/find_sessions_spec.rb @@ -14,12 +14,58 @@ describe "Find Session", :js => true, :type => :feature, :capybara_feature => tr before(:each) do UserMailer.deliveries.clear - sign_in_poltergeist user - visit "/#/findSession" - find('#find-session-form') end # when the find session page loads, it should show that there are no sessions - it { should have_selector('#sessions-none-found') } + it "shows there are no sessions" do + sign_in_poltergeist user + visit "/#/findSession" + + find('#find-session-form') + + page.should have_selector('#sessions-none-found') + + end + + + it "finds another public session", :slow => true do + + @unique_session_desc = 'Description found easily' + + in_client(:one) do + sign_in_poltergeist user + visit "/#/createSession" + + sleep 5 # this was in the cucumber steps file and it breaks when i remove it here + + # pick a genre + page.select("Rock", :from => "genres") + + # fill in description + page.fill_in 'description', :with => @unique_session_desc + + # check box for legal terms + page.check('intellectual-property') + + # create the session + page.find('#btn-create-session').click + + # verify that the in-session page is showing + expect(page).to have_selector('h2', text: 'my tracks') + + # with our description showing + # click into session description + # page.find("#session-info").should have_content @unique_session_desc + end + + in_client(:two) do + sign_in_poltergeist user + visit "/#/findSession" + find('#find-session-form') + sleep 5 # not happy with this + + expect(page).to have_text(@unique_session_desc) + end + end end diff --git a/web/spec/features/music_sessions_spec.rb b/web/spec/features/music_sessions_spec.rb new file mode 100644 index 000000000..9923e70b8 --- /dev/null +++ b/web/spec/features/music_sessions_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +describe "Music Session", :js => true, :type => :feature, :capybara_feature => true do + + subject { page } + + before(:all) do + Capybara.javascript_driver = :poltergeist + Capybara.current_driver = Capybara.javascript_driver + Capybara.default_wait_time = 10 + end + + let(:user) { FactoryGirl.create(:user) } + + before(:each) do + UserMailer.deliveries.clear + @user = user + sign_in_poltergeist @user + visit "/#/createSession" + + within('#create-session-form') do + fill_in('description', :with => 'foobar') + select('Ambient', :from => 'genres') + check('intellectual-property') + click_link('btn-create-session') + end + end + + describe "last person cleanly leaves session", :slow => true do + it "should update music session and user session history" do + should have_link('session-leave') + click_link('session-leave') + # add a buffer of 10% to ensure we have enough time + sleep_dur = (Rails.application.config.websocket_gateway_connect_time_stale + + Rails.application.config.websocket_gateway_connect_time_expire) * 1.1 + sleep sleep_dur + + user.reload + user.music_session_histories.count.should be == 1 + user.music_session_user_histories.count.should be == 1 + user.music_session_histories[0].session_removed_at.should_not be_nil + user.music_session_user_histories[0].session_removed_at.should_not be_nil + end + end + + describe "last person abruptly leaves session", :slow => true do + it "should delete connection and update music session and user session history" do + should have_link('session-leave') + page.evaluate_script("JK.JamServer.close(true)") + + # add a buffer of 10% to ensure we have enough time + sleep_dur = (Rails.application.config.websocket_gateway_connect_time_stale + + Rails.application.config.websocket_gateway_connect_time_expire) * 1.1 + sleep sleep_dur + + user.reload + user.connections.count.should be == 0 + user.music_session_histories.count.should be == 1 + user.music_session_user_histories.count.should be == 1 + user.music_session_histories[0].session_removed_at.should_not be_nil + user.music_session_user_histories[0].session_removed_at.should_not be_nil + end + end + + describe "person cleanly leaves session" do + pending + end + + describe "person abruptly leaves session" do + pending + end + +end diff --git a/web/spec/support/utilities.rb b/web/spec/support/utilities.rb index abbec6d15..e91b1bb03 100644 --- a/web/spec/support/utilities.rb +++ b/web/spec/support/utilities.rb @@ -4,6 +4,14 @@ def cookie_jar Capybara.current_session.driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar end + +def in_client(name) # to assist multiple-client RSpec/Capybara testing + Capybara.session_name = name + + yield +end + + def sign_in(user) visit signin_path fill_in "Email", with: user.email @@ -25,4 +33,4 @@ def sign_in_poltergeist(user) else page.driver.browser.manage.add_cookie :name => :remember_token, :value => user.remember_token end -end \ No newline at end of file +end