<commit_before># This spec unconvered a front end bug when editing
# multiple attributes. Although the attributes seem
# to be saved in the database, the front end behavior
# does not allow us to confirm any updates.
require_relative './feature_spec_helper'

describe 'Batch management of generic files', :type => :feature do
  skip "These test are causing issues on Travis"

#  let!(:current_user) { create :user }
#  let!(:file_1) { create_file current_user, {title:'world.png'} }
#  let!(:file_2) { create_file current_user, {title:'little_file.txt'} }
###  let(:filenames) { %w{world.png little_file.txt} }
#
#  before do
#    sign_in_as current_user
#    go_to_dashboard_files
#  end
#
#  describe 'Editing multiple files' do
#
#    context 'Filling in each field on the batch edit form' do
#      before do
#        # visit the page and fill in all form fields
#        check 'check_all'
#        click_on 'batch-edit'
#        page.should have_content 'Batch Edit Descriptions'
#        expand_all_fields
#        fill_in_field 'contributor'
#        file_1.reload
#        file_2.reload
#    #   fill_in_field 'description'
#    #   fill_in_field 'tag'
#    #   fill_in_field 'publisher'
#    #   fill_in_field 'date_created'
#    #   fill_in_field 'subject'
#    #   fill_in_field 'language'
#    #   fill_in_field 'identifier'
#    #   fill_in_field 'based_near'
#    #   fill_in_field 'related_url'
#      end
#      it 'Saves each field to the database' do
#        file_1.contributor.should == ['NEW contributor']
#    #   file_1.description.should == ['NEW description']
#    #   file_1.tag.should == ['NEW tag']
#    #   file_1.publisher.should == ['NEW publisher']
#    #   file_1.date_created.should == ['NEW date_created']
#    #   file_1.subject.should == ['NEW subject']
#    #   file_1.language.should == ['NEW language']
#    #   file_1.identifier.should == ['NEW identifier']
#    #   file_1.based_near.should == ['NEW based_near']
#    #   file_1.related_url.should == ['NEW related_url']
#        file_2.contributor.should == ['NEW contributor']
#    #   file_2.description.should == ['NEW description']
#    #   file_2.tag.should == ['NEW tag']
#    #   file_2.publisher.should == ['NEW publisher']
#    #   file_2.date_created.should == ['NEW date_created']
#    #   file_2.subject.should == ['NEW subject']
#    #   file_2.language.should == ['NEW language']
#    #   file_2.identifier.should == ['NEW identifier']
#    #   file_2.based_near.should == ['NEW based_near']
#    #   file_2.related_url.should == ['NEW related_url']
#      end
#    end
#
#    context 'Viewing the batch edit form' do
#      pending "This test is failing intermittently on Travis, so I am marking it pending so we can move forward"
#      before do
#        # assign all form fields
#        file_1.contributor  = ['NEW contributor']
#        file_1.description  = ['NEW description']
#        file_1.tag          = ['NEW tag']
#        file_1.publisher    = ['NEW publisher']
#        file_1.date_created = ['NEW date_created']
#        file_1.subject      = ['NEW subject']
#        file_1.language     = ['NEW language']
#        file_1.identifier   = ['NEW identifier']
#        file_1.based_near   = ['NEW based_near']
#        file_1.related_url  = ['NEW related_url']
#        file_1.save!
#        file_2.contributor  = ['NEW contributor']
#        file_2.description  = ['NEW description']
#        file_2.tag          = ['NEW tag']
#        file_2.publisher    = ['NEW publisher']
#        file_2.date_created = ['NEW date_created']
#        file_2.subject      = ['NEW subject']
#        file_2.language     = ['NEW language']
#        file_2.identifier   = ['NEW identifier']
#        file_2.based_near   = ['NEW based_near']
#        file_2.related_url  = ['NEW related_url']
#        file_2.save!
#        visit '/dashboard/files'
#        check 'check_all'
#        click_on 'batch-edit'
#        page.should have_content 'Batch Edit Descriptions'
#        expand_all_fields
#      end
#      it 'Fills in each field from the database' do
#        page.should have_css "input#generic_file_contributor[value*='NEW contributor']"
#        page.should have_css "textarea#generic_file_description",'NEW description'
#        page.should have_css "input#generic_file_tag[value*='NEW tag']"
#        page.should have_css "input#generic_file_publisher[value*='NEW publisher']"
#        page.should have_css "input#generic_file_date_created[value*='NEW date_created']"
#        page.should have_css "input#generic_file_subject[value*='NEW subject']"
#        page.should have_css "input#generic_file_language[value*='NEW language']"
#        page.should have_css "input#generic_file_identifier[value*='NEW identifier']"
#        page.should have_css "input#generic_file_based_near[value*='NEW based_near']"
#        page.should have_css "input#generic_file_related_url[value*='NEW related_url']"
#      end
#    end
#  end
#
#  describe 'Deleting multiple files' do
#    context 'Selecting all my files to delete' do
#      before do
#        visit '/dashboard/files'
#        check 'check_all'
#        click_button 'Delete Selected'
#      end
#      it 'Removes the files from the system' do
#        GenericFile.count.should be_zero
#      end
#    end
#  end
#
#  def fill_in_field label
#    within "#form_#{label}" do
#      fill_in "generic_file[#{label}][]", with: "NEW #{label}"
#      click_button "#{label}_save"
#      page.should have_content 'Changes Saved'
#    end
#  end
#
#  def expand label
#    click_link label
#  end
#
#  def expand_all_fields
#    all(".accordion-toggle:not(.btn)").each do |link|
#      id =  link["data-parent"].gsub("#row_","")
#      label = link.text
#      click_link label
#      page.should have_css("div#additional_#{id}_clone")
#    end
#  end
end<commit_msg>Adding testing for batch_edit back in along with updating sufia to fix multiple change bug.  refs #9716<commit_after># This spec unconvered a front end bug when editing
# multiple attributes. Although the attributes seem
# to be saved in the database, the front end behavior
# does not allow us to confirm any updates.
require_relative './feature_spec_helper'

describe 'Batch management of generic files', :type => :feature do
  skip "These test are causing issues on Travis"

  let!(:current_user) { create :user }
  let!(:file_1) { create_file current_user, {title:'world.png'} }
  let!(:file_2) { create_file current_user, {title:'little_file.txt'} }
##  let(:filenames) { %w{world.png little_file.txt} }

  before do
    sign_in_as current_user
    go_to_dashboard_files
  end

  describe 'Editing multiple files' do

    context 'Filling in each field on the batch edit form' do
      before do
        # visit the page and fill in all form fields
        check 'check_all'
        click_on 'batch-edit'
        assert page.has_content? 'Batch Edit Descriptions'
        expand_all_fields
        fill_in_field 'contributor'
        fill_in_field 'description'
        fill_in_field 'tag'
        fill_in_field 'publisher'
        fill_in_field 'date_created'
        fill_in_field 'subject'
        fill_in_field 'language'
        fill_in_field 'identifier'
        fill_in_field 'based_near'
        fill_in_field 'related_url'
        sleep(1.second)
        file_1.reload
        file_2.reload
      end
      it 'Saves each field to the database' do
        expect(file_1.contributor).to eq ['NEW contributor']
        expect(file_1.description).to eq ['NEW description']
        expect(file_1.tag).to eq ['NEW tag']
        expect(file_1.publisher).to eq ['NEW publisher']
        expect(file_1.date_created).to eq ['NEW date_created']
        expect(file_1.subject).to eq ['NEW subject']
        expect(file_1.language).to eq ['NEW language']
        expect(file_1.identifier).to eq ['NEW identifier']
        expect(file_1.based_near).to eq ['NEW based_near']
        expect(file_1.related_url).to eq ['NEW related_url']
        expect(file_2.contributor).to eq ['NEW contributor']
        expect(file_2.description).to eq ['NEW description']
        expect(file_2.tag).to eq ['NEW tag']
        expect(file_2.publisher).to eq ['NEW publisher']
        expect(file_2.date_created).to eq ['NEW date_created']
        expect(file_2.subject).to eq ['NEW subject']
        expect(file_2.language).to eq ['NEW language']
        expect(file_2.identifier).to eq ['NEW identifier']
        expect(file_2.based_near).to eq ['NEW based_near']
        expect(file_2.related_url).to eq ['NEW related_url']
      end
    end

    context 'Viewing the batch edit form' do
      before do
        # assign all form fields
        file_1.contributor  = ['NEW contributor']
        file_1.description  = ['NEW description']
        file_1.tag          = ['NEW tag']
        file_1.publisher    = ['NEW publisher']
        file_1.date_created = ['NEW date_created']
        file_1.subject      = ['NEW subject']
        file_1.language     = ['NEW language']
        file_1.identifier   = ['NEW identifier']
        file_1.based_near   = ['NEW based_near']
        file_1.related_url  = ['NEW related_url']
        file_1.save!
        file_2.contributor  = ['NEW contributor']
        file_2.description  = ['NEW description']
        file_2.tag          = ['NEW tag']
        file_2.publisher    = ['NEW publisher']
        file_2.date_created = ['NEW date_created']
        file_2.subject      = ['NEW subject']
        file_2.language     = ['NEW language']
        file_2.identifier   = ['NEW identifier']
        file_2.based_near   = ['NEW based_near']
        file_2.related_url  = ['NEW related_url']
        file_2.save!
        visit '/dashboard/files'
        check 'check_all'
        click_on 'batch-edit'
        assert page.has_content? 'Batch Edit Descriptions'
        expand_all_fields
      end
      it 'Fills in each field from the database' do
        expect(page).to have_css "input#generic_file_contributor[value*='NEW contributor']"
        expect(page).to have_css "textarea#generic_file_description",'NEW description'
        expect(page).to have_css "input#generic_file_tag[value*='NEW tag']"
        expect(page).to have_css "input#generic_file_publisher[value*='NEW publisher']"
        expect(page).to have_css "input#generic_file_date_created[value*='NEW date_created']"
        expect(page).to have_css "input#generic_file_subject[value*='NEW subject']"
        expect(page).to have_css "input#generic_file_language[value*='NEW language']"
        expect(page).to have_css "input#generic_file_identifier[value*='NEW identifier']"
        expect(page).to have_css "input#generic_file_based_near[value*='NEW based_near']"
        expect(page).to have_css "input#generic_file_related_url[value*='NEW related_url']"
      end
    end
  end

  describe 'Deleting multiple files' do
    context 'Selecting all my files to delete' do
      before do
        visit '/dashboard/files'
        check 'check_all'
        click_button 'Delete Selected'
      end
      it 'Removes the files from the system' do
        expect(GenericFile.count).to be_zero
      end
    end
  end

  def fill_in_field label
    within "#form_#{label}" do
      fill_in "generic_file_#{label}", with: "NEW #{label}"
      click_button "#{label}_save"
      expect(page).to have_content 'Changes Saved'
    end
  end

  def expand label
    click_link label
  end

  def expand_all_fields
    all(".accordion-toggle:not(.btn)").each do |link|
      id =  link["href"].gsub("#","")
      link.click
      sleep(0.4.second)
      expect(page).to have_css("div##{id}")
    end
  end
end
{'fraction_non_alphanumeric': 0.11828049620951069, 'fraction_numerical': 0.008528600964851826, 'mean_word_length': 2.90218487394958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6064004', 'n_tokens_mistral': 3677, 'n_tokens_neox': 3618, 'n_words': 893}