From ffda67c1d81fdce265a6d582d9f94ab8336c22e9 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 19 Feb 2019 17:36:02 +0100 Subject: [PATCH] spec: add specs for attachments --- spec/features/new_user/brouillon_spec.rb | 50 ++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/spec/features/new_user/brouillon_spec.rb b/spec/features/new_user/brouillon_spec.rb index 5d2841af4..c0a495ade 100644 --- a/spec/features/new_user/brouillon_spec.rb +++ b/spec/features/new_user/brouillon_spec.rb @@ -10,7 +10,6 @@ feature 'The user' do # TODO: check # the order # there are no extraneous input - # attached file works scenario 'fill a dossier', js: true do allow(Champs::RegionChamp).to receive(:regions).and_return(['region1', 'region2']).at_least(:once) allow(Champs::DepartementChamp).to receive(:departements).and_return(['dep1', 'dep2']).at_least(:once) @@ -38,8 +37,7 @@ feature 'The user' do select('dep2', from: 'departements') check('engagement') fill_in('dossier_link', with: '123') - # do not know how to make it work... - # find('form input[type="file"]').set(Rails.root.join('spec/fixtures/files/white.png')) + find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf') click_on 'Enregistrer le brouillon' expect(page).to have_content('Votre brouillon a bien été sauvegardé') @@ -63,8 +61,10 @@ feature 'The user' do expect(champ_value_for('departements')).to eq('dep2') expect(champ_value_for('engagement')).to eq('on') expect(champ_value_for('dossier_link')).to eq('123') + expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet ## check data on the gui + expect(page).to have_field('text', with: 'super texte') expect(page).to have_field('textarea', with: 'super textarea') expect(page).to have_field('date', with: '2012-12-12') @@ -82,6 +82,8 @@ feature 'The user' do expect(page).to have_select('departement', selected: 'dep2') expect(page).to have_checked_field('engagement') expect(page).to have_field('dossier_link', with: '123') + expect(page).to have_text('file.pdf') + expect(page).to have_text('analyse antivirus en cours') end let(:procedure_with_repetition) do @@ -148,6 +150,48 @@ feature 'The user' do expect(page).to have_current_path(merci_dossier_path(user_dossier)) end + let(:procedure_with_pj) do + tdcs = [create(:type_de_champ_piece_justificative, mandatory: true, libelle: 'Pièce justificative')] + create(:procedure, :published, :for_individual, types_de_champ: tdcs) + end + + scenario 'adding, replacing and removing attachments', js: true do + log_in(user.email, password, procedure_with_pj) + fill_individual + + # Add an attachment + find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf') + click_on 'Enregistrer le brouillon' + expect(page).to have_content('Votre brouillon a bien été sauvegardé') + expect(page).to have_text('file.pdf') + expect(page).to have_text('analyse antivirus en cours') + + # Mark file as scanned and clean + virus_scan = VirusScan.last + virus_scan.update(scanned_at: Time.zone.now, status: VirusScan.statuses.fetch(:safe)) + within '.piece-justificative' do + click_on 'rafraichir' + end + expect(page).to have_link('file.pdf') + expect(page).to have_no_content('analyse antivirus en cours') + + # Replace the attachment + within '.piece-justificative' do + click_on 'Remplacer' + end + find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf') + click_on 'Enregistrer le brouillon' + expect(page).to have_no_text('file.pdf') + expect(page).to have_text('RIB.pdf') + + # Remove the attachment + within '.piece-justificative' do + click_on 'Supprimer' + end + expect(page).to have_content('La pièce jointe a bien été supprimée') + expect(page).to have_no_text('RIB.pdf') + end + private def log_in(email, password, procedure)