jam-cloud/web/spec/features/welcome_spec.rb

204 lines
6.4 KiB
Ruby

require 'spec_helper'
describe "Welcome", :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
before(:each) do
Feed.delete_all
MusicSessionHistory.delete_all
Recording.delete_all
page.driver.headers = { 'User-Agent' => ' JamKazam ' }
visit "/"
find('h1', text: 'Play music together over the Internet as if in the same room')
end
let(:user) { FactoryGirl.create(:user) }
let(:fb_auth) {
{ :provider => "facebook",
:uid => "1234",
:info => {:name => "John Doe",
:email => "johndoe@email.com"},
:credentials => {:token => "testtoken234tsdf", :expires_at => 2391456019},
:extra => { :raw_info => {:first_name => 'John', :last_name => 'Doe', :email => 'facebook@jamkazam.com', :gender => 'male'}} }
}
describe "signin" do
before(:each) do
find('#signin').trigger(:click)
end
it "show dialog" do
should have_selector('h1', text: 'sign in')
end
it "shows signup dialog if selected" do
find('.show-signup-dialog').trigger(:click)
find('h1', text: 'sign up for jamkazam')
end
it "forgot password" do
find('a.forgot-password').trigger(:click)
find('h1', text: 'reset your password')
end
it "closes if cancelled" do
find('a.signin-cancel').trigger(:click)
should_not have_selector('h1', text: 'sign in')
end
describe "signin natively" do
it "redirects to client on login" do
within('#signin-form') do
fill_in "email", with: user.email
fill_in "password", with: user.password
click_button "SIGN IN"
end
wait_until_curtain_gone
find('h2', text: 'musicians')
end
it "shows error if bad login" do
within('#signin-form') do
fill_in "email", with: "junk"
fill_in "password", with: user.password
click_button "SIGN IN"
end
should have_selector('h1', text: 'sign in')
find('div.login-error-msg', text: 'Invalid login')
end
end
describe "signin with facebook" do
before(:each) do
user.user_authorizations.build provider: 'facebook', uid: '1234', token: 'abc', token_expiration: 1.days.from_now
user.save!
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(fb_auth)
end
it "click will redirect to facebook for authorization" do
find('.signin-facebook').trigger(:click)
wait_until_curtain_gone
find('h2', text: 'musicians')
end
end
end
describe "signup" do
before(:each) do
find('#signup').trigger(:click)
end
it "show dialog" do
should have_selector('h1', text: 'sign up for jamkazam')
end
it "shows signin dialog if selected" do
find('.show-signin-dialog').trigger(:click)
find('h1', text: 'sign in')
end
it "closes if cancelled" do
find('a.signup-cancel').trigger(:click)
should_not have_selector('h1', text: 'sign in')
end
describe "signup with email" do
it "click will redirect to signup page" do
find('.signup-email').trigger(:click)
find('h2', text: 'Create a JamKazam account')
end
end
describe "signup with facebook" do
before(:each) do
fb_auth[:uid] = '12345'
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(fb_auth)
end
it "click will redirect to facebook for authorization" do
find('.signup-facebook').trigger(:click)
find('h2', text: 'Create a JamKazam account')
find_field('jam_ruby_user[first_name]').value.should eq 'John'
find_field('jam_ruby_user[last_name]').value.should eq 'Doe'
find_field('jam_ruby_user[email]').value.should eq 'facebook@jamkazam.com'
end
end
end
describe "feed" do
it "data" do
claimedRecording1 = FactoryGirl.create(:claimed_recording)
musicSessionHistory1 = claimedRecording1.recording.music_session.music_session_history
visit "/"
find('h1', text: 'Play music together over the Internet as if in the same room')
find('.feed-entry.music-session-history-entry .description', text: musicSessionHistory1.description)
find('.feed-entry.music-session-history-entry .session-status', text: 'SESSION IN PROGRESS')
find('.feed-entry.music-session-history-entry .session-controls.inprogress', text: 'SESSION IN PROGRESS')
find('.feed-entry.music-session-history-entry .artist', text: musicSessionHistory1.user.name)
should_not have_selector('.feed-entry.music-session-history-entry .musician-detail')
find('.feed-entry.recording-entry .name', text: claimedRecording1.name)
find('.feed-entry.recording-entry .description', text: claimedRecording1.description)
find('.feed-entry.recording-entry .title', text: 'RECORDING')
find('.feed-entry.recording-entry .artist', text: claimedRecording1.user.name)
should_not have_selector('.feed-entry.recording-entry .musician-detail')
# try to hide the recording
claimedRecording1.is_public = false
claimedRecording1.save!
visit "/"
find('h1', text: 'Play music together over the Internet as if in the same room')
find('.feed-entry.music-session-history-entry .description', text: musicSessionHistory1.description)
should_not have_selector('.feed-entry.recording-entry')
# try to mess with the music session history by removing all user histories (which makes it a bit invalid)
# but we really don't want the front page to ever crash if we can help it
musicSessionHistory1.music_session_user_histories.delete_all
musicSessionHistory1.reload
musicSessionHistory1.music_session_user_histories.length.should == 0
visit "/"
find('h1', text: 'Play music together over the Internet as if in the same room')
find('.feed-entry.music-session-history-entry .description', text: musicSessionHistory1.description)
# try to hide the music session
musicSessionHistory1.fan_access = false
musicSessionHistory1.save!
visit "/"
find('h1', text: 'Play music together over the Internet as if in the same room')
should_not have_selector('.feed-entry.music-session-history-entry')
end
end
end