<commit_before>require 'spec_helper'

feature "Add contributing authors", js: true do
  let(:submitter) { FactoryGirl.create :user }
  let!(:paper) { FactoryGirl.create :paper, user: submitter }
  let(:task) { FactoryGirl.create(:plos_authors_task, title: "Add Plos Authors", paper: paper) }


  before do
    task.participants << submitter
    paper.paper_roles.create(user: submitter, role: PaperRole::COLLABORATOR)

    sign_in_page = SignInPage.visit
    sign_in_page.sign_in submitter
  end

  scenario "Author specifies contributing authors" do
    edit_paper = EditPaperPage.visit paper

    edit_paper.view_card(task.title) do |overlay|
      overlay.add_author(first_name: 'Neils',
                         middle_initial: 'B.',
                         last_name: 'Bohr',
                         title: 'Soup of the day',
                         department: 'Underwhere?',
                         affiliation: 'University of Copenhagen',
                         email: '<EMAIL>')
      expect(overlay).to have_content "<NAME>"
    end
  end

  context "with an existing author" do
    let!(:author) { FactoryGirl.create :plos_author, paper: paper, plos_authors_task: task }

    scenario "editing" do
      edit_paper = EditPaperPage.visit paper
      edit_paper.view_card(task.title) do |overlay|
        overlay.edit_author author.first_name,
          last_name: 'rommel',
          email: '<EMAIL>'
        visit current_url
        within '.authors-overlay-list' do
          expect(page).to have_content "<EMAIL>"
          expect(page).to have_content "rommel"
        end
      end
    end

    scenario "deleting" do
      edit_paper = EditPaperPage.visit paper
      edit_paper.view_card(task.title) do |overlay|
        overlay.delete_author author.first_name
        within '.authors-overlay-list' do<commit_msg>add validation scenario for completing task<commit_after>require 'spec_helper'

feature "Add contributing authors", js: true do
  let(:submitter) { FactoryGirl.create :user }
  let!(:paper) { FactoryGirl.create :paper, user: submitter }
  let(:task) { FactoryGirl.create(:plos_authors_task, title: "Add Plos Authors", paper: paper) }


  before do
    task.participants << submitter
    paper.paper_roles.create(user: submitter, role: PaperRole::COLLABORATOR)

    sign_in_page = SignInPage.visit
    sign_in_page.sign_in submitter
  end

  scenario "Author specifies contributing authors" do
    edit_paper = EditPaperPage.visit paper

    edit_paper.view_card(task.title) do |overlay|
      overlay.add_author(first_name: 'Neils',
                         middle_initial: 'B.',
                         last_name: 'Bohr',
                         title: 'Soup of the day',
                         department: 'Underwhere?',
                         affiliation: 'University of Copenhagen',
                         email: '<EMAIL>')
      expect(overlay).to have_content "<NAME>"
    end
  end

  context "with an existing author" do
    let!(:author) { FactoryGirl.create :plos_author, paper: paper, plos_authors_task: task }

    scenario "editing" do
      edit_paper = EditPaperPage.visit paper
      edit_paper.view_card(task.title) do |overlay|
        overlay.edit_author author.first_name,
          last_name: 'rommel',
          email: '<EMAIL>'
        visit current_url
        within '.authors-overlay-list' do
          expect(page).to have_content "<EMAIL>"
          expect(page).to have_content "rommel"
        end
      end
    end

    scenario "validation on task completion" do
      edit_paper = EditPaperPage.visit paper
      edit_paper.view_card(task.title) do |overlay|
        overlay.edit_author author.first_name,
          email: 'invalid_email_string'
        overlay.mark_as_complete
        expect(page).to have_css(".add-author-form")
        within ".add-author-form" do
          expect(page).to have_content "needs to be a valid email address"
        end
      end
    end

    scenario "deleting" do
      edit_paper = EditPaperPage.visit paper
      edit_paper.view_card(task.title) do |overlay|
        overlay.delete_author author.first_name
        within '.authors-overlay-list' do
{'fraction_non_alphanumeric': 0.09383249340052796, 'fraction_numerical': 0.0, 'mean_word_length': 2.5025210084033613, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '1688344', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1183, 'n_words': 298}