<commit_before>require 'rails_helper'
require 'faker'
require 'support/poltergeist_js_hack_for_login'
require 'capybara/email/rspec'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

feature 'Invite people to a phone call' do
  scenario 'with valid data' do
    login_with_admin_user

    visit '/v2/event_invitations/new'

    research_subject_emails = Array.new(3, FactoryGirl.create(:person).email_address)

    admin_email = '<EMAIL>'

    fill_in "People's email addresses", with: research_subject_emails.join(',')

    event_description = "We're looking for mothers between the age of 16-26 for a phone interview"

    fill_in 'Event description', with: event_description

    select '30 mins', from: 'Call length'

    fill_in 'Date', with: '02/02/2016'
    select '12:00', from: 'Start time'
    select '15:30', from: 'End time'

    # TODO: implement multiple time windows after invitation for single time window works
    #
    # click_link 'Add another time window'
    #
    # fill_in 'Date', with: '02/03/2016'
    # select '12:00', from: 'Start time'
    # select '14:30', from: 'End time'

    click_button 'Send invitation'

    expect(page).to have_text 'Person was successfully invited.'

    [research_subject_emails, admin_email].flatten.each do |email_address|
      open_email(email_address)

      expect(current_email).
        to have_content "Hello, you've been invited to a phone interview"

      expect(current_email).
        to have_content event_description
    end
  end

  scenario 'with invalid data' do
    login_with_admin_user

    visit '/v2/event_invitations/new'

    click_button 'Send invitation'

    expect(page).to have_text('There were problems with some of the fields.')
  end

  scenario 'with an unregistered email address' do
    login_with_admin_user

    visit '/v2/event_invitations/new'

    research_subject_emails = ['<EMAIL>']
    admin_email = '<EMAIL>'

    fill_in "People's email addresses", with: research_subject_emails.join(',')

    event_description = "We're looking for mothers between the age of 16-26 for a phone interview"

    fill_in 'Event description', with: event_description

    select '30 mins', from: 'Call length'

    fill_in 'Date', with: '02/02/2016'
    select '12:00', from: 'Start time'
    select '15:30', from: 'End time'

    click_button 'Send invitation'

    expect(page).to have_text('There were problems with some of the fields.')
  end

  scenario 'with a call length that doesnt fit the time window perfectly, show a confirmation window', js: :true do
    login_with_admin_user

    visit '/v2/event_invitations/new'

    select '30 mins', from: 'Call length'

    fill_in 'Date', with: '20/02/2016'
    select '12:00', from: 'Start time'
    select '13:15', from: 'End time'

    click_button 'Send invitation'
    message = dismiss_confirm do
      click_button 'Send invitation'
    end
    expect(message).to eq('Your time window is not a multiple of the call length. Do you still want to save the Event?')<commit_msg>Change spec to match expected error messages<commit_after>require 'rails_helper'
require 'faker'
require 'support/poltergeist_js_hack_for_login'
require 'capybara/email/rspec'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

feature 'Invite people to a phone call' do
  scenario 'with valid data' do
    login_with_admin_user

    visit '/v2/event_invitations/new'

    research_subject_emails = Array.new(3, FactoryGirl.create(:person).email_address)

    admin_email = '<EMAIL>'

    fill_in "People's email addresses", with: research_subject_emails.join(',')

    event_description = "We're looking for mothers between the age of 16-26 for a phone interview"

    fill_in 'Event description', with: event_description

    select '30 mins', from: 'Call length'

    fill_in 'Date', with: '02/02/2016'
    select '12:00', from: 'Start time'
    select '15:30', from: 'End time'

    # TODO: implement multiple time windows after invitation for single time window works
    #
    # click_link 'Add another time window'
    #
    # fill_in 'Date', with: '02/03/2016'
    # select '12:00', from: 'Start time'
    # select '14:30', from: 'End time'

    click_button 'Send invitation'

    expect(page).to have_text 'Person was successfully invited.'

    [research_subject_emails, admin_email].flatten.each do |email_address|
      open_email(email_address)

      expect(current_email).
        to have_content "Hello, you've been invited to a phone interview"

      expect(current_email).
        to have_content event_description
    end
  end

  scenario 'with invalid data' do
    login_with_admin_user

    visit '/v2/event_invitations/new'

    click_button 'Send invitation'

    expect(page).to have_text('There were problems with some of the fields: Email addresses can\'t be blank, Description can\'t be blank, Date can\'t be blank')
  end

  scenario 'with an unregistered email address' do
    login_with_admin_user

    visit '/v2/event_invitations/new'

    research_subject_emails = ['<EMAIL>']

    fill_in "People's email addresses", with: research_subject_emails.join(',')

    event_description = "We're looking for mothers between the age of 16-26 for a phone interview"

    fill_in 'Event description', with: event_description

    select '30 mins', from: 'Call length'

    fill_in 'Date', with: '02/02/2016'
    select '12:00', from: 'Start time'
    select '15:30', from: 'End time'

    click_button 'Send invitation'

    expect(page).to have_text('There were problems with some of the fields: Email addresses One or more of the email addresses are not registered')
  end

  scenario 'with a call length that doesnt fit the time window perfectly, show a confirmation window', js: :true do
    login_with_admin_user

    visit '/v2/event_invitations/new'

    select '30 mins', from: 'Call length'

    fill_in 'Date', with: '20/02/2016'
    select '12:00', from: 'Start time'
    select '13:15', from: 'End time'

    click_button 'Send invitation'
    message = dismiss_confirm do
      click_button 'Send invitation'
    end
    expect(message).to eq('Your time window is not a multiple of the call length. Do you still want to save the Event?')
{'fraction_non_alphanumeric': 0.09596283242550464, 'fraction_numerical': 0.026594040371675745, 'mean_word_length': 3.7295454545454545, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '248255', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1863, 'n_words': 638}