<commit_before># Copyright (c) 2008-2013 <NAME> and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
require File.expand_path("../acceptance_helper.rb", __FILE__)

feature 'Contacts', %q{
  In order to increase customer satisfaction
  As a user
  I want to manage contacts
} do

  before :each do
    do_login_if_not_already(:first_name => "Bill", :last_name => "Murray")
  end

  scenario 'should view a list of contacts' do
    4.times { |i| FactoryGirl.create(:contact, :first_name => "Test", :last_name => "Subject \##{i}") }
    visit contacts_page
    expect(page).to have_content('Test Subject #0')
    expect(page).to have_content('Test Subject #1')
    expect(page).to have_content('Test Subject #2')
    expect(page).to have_content('Test Subject #3')
    expect(page).to have_content('Create Contact')
  end

  scenario 'should create a contact', :js => true do
    with_versioning do
      visit contacts_page
      click_link 'Create Contact'
      expect(page).to have_selector('#contact_first_name', :visible => true)
      fill_in 'contact_first_name', :with => 'Testy'
      fill_in 'contact_last_name', :with => 'McTest'
      fill_in 'contact_email', :with => "<EMAIL>"
      fill_in 'contact_phone', :with => '+44 1234 567890'
      click_link 'Comment'
      fill_in 'comment_body', :with => 'This is a very important person.'
      click_button 'Create Contact'
      expect(find('div#contacts')).to have_content('Testy McTest')
      find('div#contacts').click_link 'Testy McTest'
      expect(page).to have_content('This is a very important person.')
      click_link "Dashboard"
      expect(page).to have_content('<NAME> created contact <NAME>')
      expect(page).to have_content('<NAME> created comment on <NAME>')
    end
  end

  scenario "remembers the comment field when the creation was unsuccessful", :js => true do
    visit contacts_page
    click_link 'Create Contact'

    click_link 'Comment'
    fill_in 'comment_body', :with => 'This is a very important person.'
    click_button 'Create Contact'

    expect(page).to have_field("comment_body", :with => 'This is a very important person.')
  end

  scenario 'should view and edit a contact', :js => true do
    FactoryGirl.create(:contact, :first_name => "Testy", :last_name => "McTest")
    with_versioning do
      visit contacts_page
      click_link 'Testy McTest'
      click_link 'Edit'
      fill_in 'contact_first_name', :with => 'Test'
      fill_in 'contact_last_name', :with => 'Subject'
      fill_in 'contact_email', :with => "<EMAIL>"
      click_button 'Save Contact'
      expect(page).to have_content('Test Subject')
      click_link 'Dashboard'
      expect(page).to have_content("<NAME> updated contact Test Subject")
    end
  end

  scenario 'should delete a contact', :js => true do
    FactoryGirl.create(:contact, :first_name => "Test", :last_name => "Subject")
    with_versioning do
      visit contacts_page
      click_link 'Test Subject'
      click_link 'Delete?'
      expect(page).to have_content('Are you sure you want to delete this contact?')
      click_link 'Yes'
      expect(page).to have_content('Test Subject has been deleted.')
      expect(page).not_to have_content('Test Subject')
    end
  end

  scenario 'should search for a contact', :js => true do
    2.times { |i| FactoryGirl.create(:contact, :first_name => "Test", :last_name => "Subject \##{i}") }
    visit contacts_page
    expect(find('#contacts')).to have_content('Test Subject #0')
    expect(find('#contacts')).to have_content('Test Subject #1')
    fill_in 'query', :with => 'Test Subject #1'
    expect(find('#contacts')).to have_content('Test Subject #1')
    expect(find('#contacts')).not_to have_content('Test Subject #0')
    fill_in 'query', :with => 'Test Subject'
    expect(find('#contacts')).to have_content('Test Subject #0')
    expect(find('#contacts')).to have_content('Test Subject #1')
    fill_in 'query', :with => "Fake contact"
    expect(find('#contacts')).not_to have_content('Test Subject #0')
    expect(find('#contacts')).not_to have_content('Test Subject #1')
  end
end
<commit_msg>uses selectors to reduce flakeyness of contacts feature<commit_after># Copyright (c) 2008-2013 <NAME> and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
require File.expand_path("../acceptance_helper.rb", __FILE__)

feature 'Contacts', %q{
  In order to increase customer satisfaction
  As a user
  I want to manage contacts
} do

  before :each do
    do_login_if_not_already(:first_name => "Bill", :last_name => "Murray")
  end

  scenario 'should view a list of contacts' do
    4.times { |i| FactoryGirl.create(:contact, :first_name => "Test", :last_name => "Subject \##{i}") }
    visit contacts_page
    expect(contacts_element).to have_content('Test Subject #0')
    expect(contacts_element).to have_content('Test Subject #1')
    expect(contacts_element).to have_content('Test Subject #2')
    expect(contacts_element).to have_content('Test Subject #3')
    expect(find('.title_tools')).to have_content('Create Contact')
  end

  scenario 'should create a contact', :js => true do
    with_versioning do
      visit contacts_page
      click_link 'Create Contact'
      expect(page).to have_selector('#contact_first_name', :visible => true)
      fill_in 'contact_first_name', :with => 'Testy'
      fill_in 'contact_last_name', :with => 'McTest'
      fill_in 'contact_email', :with => "<EMAIL>"
      fill_in 'contact_phone', :with => '+44 1234 567890'
      click_link 'Comment'
      fill_in 'comment_body', :with => 'This is a very important person.'
      click_button 'Create Contact'
      expect(contacts_element).to have_content('<NAME>')
      contacts_element.click_link '<NAME>'
      expect(page).to have_content('This is a very important person.')
      click_link "Dashboard"
      expect(activities_element).to have_content('<NAME> created contact <NAME>')
      expect(activities_element).to have_content('<NAME> created comment on <NAME>')
    end
  end

  scenario "remembers the comment field when the creation was unsuccessful", :js => true do
    visit contacts_page
    click_link 'Create Contact'

    click_link 'Comment'
    fill_in 'comment_body', :with => 'This is a very important person.'
    click_button 'Create Contact'

    expect(page).to have_field("comment_body", :with => 'This is a very important person.')
  end

  scenario 'should view and edit a contact', :js => true do
    FactoryGirl.create(:contact, :first_name => "Testy", :last_name => "McTest")
    with_versioning do
      visit contacts_page
      click_link '<NAME>'
      click_link 'Edit'
      fill_in 'contact_first_name', :with => 'Test'
      fill_in 'contact_last_name', :with => 'Subject'
      fill_in 'contact_email', :with => "<EMAIL>"
      click_button 'Save Contact'
      expect(find('#edit_contact_title')).to have_content('Test Subject')
      click_link 'Dashboard'
      expect(activities_element).to have_content("<NAME> updated contact Test Subject")
    end
  end

  scenario 'should delete a contact', :js => true do
    FactoryGirl.create(:contact, :first_name => "Test", :last_name => "Subject")
    visit contacts_page
    click_link 'Test Subject'
    click_link 'Delete?'
    expect(page).to have_content('Are you sure you want to delete this contact?')
    click_link 'Yes'
    expect(page).to have_content('Test Subject has been deleted.')
    expect(page).not_to have_content('Test Subject')
  end

  scenario 'should search for a contact', :js => true do
    2.times { |i| FactoryGirl.create(:contact, :first_name => "Test", :last_name => "Subject \##{i}") }
    visit contacts_page
    expect(contacts_element).to have_content('Test Subject #0')
    expect(contacts_element).to have_content('Test Subject #1')
    fill_in 'query', :with => 'Test Subject #1'
    expect(contacts_element).to have_content('Test Subject #1')
    expect(contacts_element).not_to have_content('Test Subject #0')
    fill_in 'query', :with => 'Test Subject'
    expect(contacts_element).to have_content('Test Subject #0')
    expect(contacts_element).to have_content('Test Subject #1')
    fill_in 'query', :with => "Fake contact"
    expect(contacts_element).not_to have_content('Test Subject #0')
    expect(contacts_element).not_to have_content('Test Subject #1')
  end

  def contacts_element
    find('#contacts')
  end

  def activities_element
    find('#activities')
  end
end

{'fraction_non_alphanumeric': 0.14263002498296615, 'fraction_numerical': 0.00794912559618442, 'mean_word_length': 3.7121455323702515, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1339004', 'n_tokens_mistral': 2664, 'n_tokens_neox': 2627, 'n_words': 765}