Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix an invitation spec problem

  • Loading branch information...
commit 71419bb662b03f86813ca9cb67808a8cdee4242e 1 parent f81bb1a
@kyungbae kyungbae authored
Showing with 46 additions and 70 deletions.
  1. +46 −70 spec/features/invitations_spec.rb
View
116 spec/features/invitations_spec.rb
@@ -1,102 +1,84 @@
require 'spec_helper'
-feature "Post creator(registered user)" do
- describe "as a test user" do
- before :each do
- @user = create(:user)
- visit new_post_path
- click_on 'Sign in'
- expect(page).to have_content('SIGN IN')
- fill_in 'user_email', with: @user.email
- fill_in 'user_password', with: @user.password
- click_button 'Sign In'
+feature 'Invitation', js: true do
+ context 'as a registered user' do
+ let(:user) { create(:user) }
+
+ before do
+ sign_in(user)
visit new_post_path
+ click_on 'People I Choose'
+ click_on 'Invite a new person to the research platform'
end
- it 'adds an invitee in the new post page', js: true do
- expect(page).to have_content('SIGN OUT')
- expect(page).to have_content('Additional Details')
- find(:xpath, '//input[@id="post_title"]').visible?
-
- fill_post('Queen', 'another one bites the dust')
- click_button 'People I Choose'
-
- page.execute_script('$("#add_invitation").modal("show")')
-
- # Check the modal form has been opened
+ it 'opens an invitation form' do
expect(page).to have_selector('.modal-backdrop')
- test_email = 'abc@abc.com'
- test_name = 'AB C'
- test_message = 'This is a test invitation.'
-
- # Fill the invitation form
- fill_invitation(test_email, test_name, test_message)
+ end
- page.execute_script("$('#create_invitation').click()")
- sleep 5
+ it 'lets a user adds an invitee' do
+ fill_invitation('abc@abc.com', 'AB C', 'I am inviting you.')
+ click_button 'Invite'
+ sleep 3
- # Check the all information has been transferred to the hidden nested
- # fields
within('#invitation', visible: false) do
+
#Check the nested fields are created
expect(page).to have_selector('.input.hidden.post_invitations_recipient_name', visible: false)
expect(page).to have_selector('.input.email.required.post_invitations_recipient_email')
expect(page).to have_selector('.input.hidden.post_invitations_message', visible: false)
+
# Check the information has been transferred correctly from the modal
# form
- find('.input.hidden.post_invitations_recipient_name input', visible: false).value.should == test_name
- find('.input.email.post_invitations_recipient_email input').value.should == test_email
- find('.input.hidden.post_invitations_message input', visible: false).value.should == test_message
+ expect(find('.input.hidden.post_invitations_recipient_name input', visible: false).value).to eq 'AB C'
+ expect(find('.input.email.post_invitations_recipient_email input').value).to eq 'abc@abc.com'
+ expect(find('.input.hidden.post_invitations_message input', visible: false).value).to eq 'I am inviting you.'
end
-
- click_button 'Submit'
- expect(page).to have_content('Thread was successfully posted.')
end
- it 'closes the invitation form by clicking either Cancel button or X button', js: true do
- # Open the invitation form
- page.execute_script('$("#add_invitation").modal("show")')
+ it 'lets a user submits a post with an invitee' do
+ fill_invitation('abc@abc.com', 'AB C', 'I am inviting you')
+ click_button 'Invite'
+ # page.execute_script("$('#create_invitation').click()")
sleep 5
+ fill_post('Queen', 'Another one bites the dust.')
+ click_on 'Submit'
- # Make sure the invitaion form is opened
- expect(page).to have_selector('.modal-backdrop')
- expect(page).to have_button('Cancel')
-
- # Close the form
+ expect(page).to have_content('Thread was successfully posted.')
+ expect(Invitation.count).to eq 1
+ end
+
+ it 'allows a user closes an invitation form' do
click_button 'Cancel'
- sleep 5
+ sleep 3
- # Check the form is closed
- expect(page).to_not have_selector('.modal-backdrop')
+ expect(page).not_to have_selector('.modal-backdrop')
end
- it 'adds a invitee without a recipient name and message', js: true do
- fill_post('Test Title', 'This is a test.')
- page.execute_script('$("#add_invitation").modal("show")')
- sleep 5
-
+ it 'allows a user skips a recipient name and message' do
fill_invitation('test@test.com', '', '')
click_button 'Invite'
- sleep 5
+ fill_post('Test Title', 'This is a test.')
+ click_on 'Submit'
+ sleep 3
- click_button 'Submit'
expect(page).to have_content('Thread was successfully posted.')
end
- it 'adds with a wrong email address', js: true do
- page.execute_script('$("#add_invitation").modal("show")')
- sleep 5
-
- fill_invitation('test@test', 'Wrong Email', 'This is a test for the emial validation.')
- page.execute_script("$('#create_invitation').click()")
- sleep 5
+ it 'validates a recipient email' do
+ fill_invitation('test@test', 'Wrong Email', 'Email validation test')
+ click_button 'Invite'
+ sleep 3
- # Check the error message is showed up
expect(page).to have_content('Please check the email address')
- click_button 'Cancel'
end
end
+ def fill_post(title, detail)
+ find('#post_title').visible?
+ fill_in 'post_title', with: title
+ page.execute_script("editor.setValue('#{detail}')")
+ end
+
def fill_invitation(email, name, message)
within('#add_invitation') do
fill_in 'modal_recipient_name', with: name
@@ -104,10 +86,4 @@ def fill_invitation(email, name, message)
fill_in 'modal_message', with: message
end
end
-
- def fill_post(title, detail)
- find('#post_title').visible?
- fill_in 'post_title', with: title
- page.execute_script("editor.setValue('#{detail}')")
- end
end
Please sign in to comment.
Something went wrong with that request. Please try again.