<commit_before>require 'rails_helper'

RSpec.feature "ScannedResourcesController", type: :feature do
  let(:user) { FactoryGirl.create(:curation_concern_creator) }
  let(:scanned_resource) { FactoryGirl.create(:scanned_resource_with_multi_volume_work, user: user) }
  let(:parent_presenter) do
    ScannedResourceShowPresenter.new(
      SolrDocument.new(
        scanned_resource.to_solr
      ), nil
    )
  end

  context "an authorized user" do
    before(:each) do
      sign_in user
    end

    scenario "Logged in user can follow link to edit scanned resource" do
      visit polymorphic_path [scanned_resource]
      click_link 'Edit This Scanned Resource'
      expect(page).to have_text('Manage Your Work')
    end

    scenario "User can edit a scanned resource" do
      visit edit_polymorphic_path [scanned_resource]
      fill_in 'scanned_resource_source_metadata_identifier', with: '1234568'
      fill_in 'scanned_resource_portion_note', with: 'new portion note'
      fill_in 'scanned_resource_description', with: 'new description'
      choose 'Final Review'

      click_button 'Update Scanned resource'
      expect(page).to have_text("Test title")
      expect(page).to have_selector("span.label-primary", "Final Review")
    end

    scenario "User can add a new file" do
      allow(CharacterizeJob).to receive(:perform_later).once
      allow_any_instance_of(FileSet).to receive(:warn) # suppress virus warning messages

      visit polymorphic_path [scanned_resource]
      click_link 'Attach a File'

      within("form.new_file_set") do
        fill_in("Title", with: 'image.png')
        attach_file("Upload a file", File.join(Rails.root, 'spec/fixtures/files/image.png'))
        click_on("Attach to Scanned Resource")
      end

      visit polymorphic_path [parent_presenter.file_presenters.first]
      expect(page).to have_content "image.png"
    end
  end

  context "an anonymous user" do
    scenario "User can't edit a scanned resource" do
      visit edit_polymorphic_path [scanned_resource]
      expect(page).to have_selector("div.alert-info", "You are not authorized to access this page")
    end

    scenario "User can follow link to parent multi volume work" do
      parent_id = scanned_resource.ordered_by.first.id
      visit curation_concerns_member_scanned_resource_path(parent_id, scanned_resource.id)
      click_link 'Test title'
      expect(page).to have_text('Test title')
    end
  end
end<commit_msg>add test for bulk edit link<commit_after>require 'rails_helper'

RSpec.feature "ScannedResourcesController", type: :feature do
  let(:user) { FactoryGirl.create(:curation_concern_creator) }
  let(:scanned_resource) { FactoryGirl.create(:scanned_resource_with_multi_volume_work, user: user) }
  let(:parent_presenter) do
    ScannedResourceShowPresenter.new(
      SolrDocument.new(
        scanned_resource.to_solr
      ), nil
    )
  end

  context "an authorized user" do
    before(:each) do
      sign_in user
    end

    scenario "Logged in user can follow link to edit scanned resource" do
      visit polymorphic_path [scanned_resource]
      click_link 'Edit This Scanned Resource'
      expect(page).to have_text('Manage Your Work')
    end

    scenario "User can edit a scanned resource" do
      visit edit_polymorphic_path [scanned_resource]
      fill_in 'scanned_resource_source_metadata_identifier', with: '1234568'
      fill_in 'scanned_resource_portion_note', with: 'new portion note'
      fill_in 'scanned_resource_description', with: 'new description'
      choose 'Final Review'

      click_button 'Update Scanned resource'
      expect(page).to have_text("Test title")
      expect(page).to have_selector("span.label-primary", "Final Review")
    end

    scenario "User can add a new file" do
      allow(CharacterizeJob).to receive(:perform_later).once
      allow_any_instance_of(FileSet).to receive(:warn) # suppress virus warning messages

      visit polymorphic_path [scanned_resource]
      click_link 'Attach a File'

      within("form.new_file_set") do
        fill_in("Title", with: 'image.png')
        attach_file("Upload a file", File.join(Rails.root, 'spec/fixtures/files/image.png'))
        click_on("Attach to Scanned Resource")
      end

      visit polymorphic_path [parent_presenter.file_presenters.first]
      expect(page).to have_content "image.png"
    end

    scenario "User can follow link to bulk edit scanned resource" do
      visit polymorphic_path [scanned_resource]
      click_link 'Bulk Edit'
      expect(page).to have_text('Bulk Edit')
    end
  end

  context "an anonymous user" do
    scenario "User can't edit a scanned resource" do
      visit edit_polymorphic_path [scanned_resource]
      expect(page).to have_selector("div.alert-info", "You are not authorized to access this page")
    end

    scenario "User can follow link to parent multi volume work" do
      parent_id = scanned_resource.ordered_by.first.id
      visit curation_concerns_member_scanned_resource_path(parent_id, scanned_resource.id)
      click_link 'Test title'
      expect(page).to have_text('Test title')
    end
  end
end
{'fraction_non_alphanumeric': 0.08323586744639376, 'fraction_numerical': 0.0027290448343079924, 'mean_word_length': 3.703024747937672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5553214', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1507, 'n_words': 413}