2019-06-17 16:13:12 +02:00
|
|
|
describe 'shared/attachment/_update.html.haml', type: :view do
|
|
|
|
let(:champ) { build(:champ_piece_justificative, dossier: create(:dossier)) }
|
2019-10-22 10:58:04 +02:00
|
|
|
let(:attached_file) { champ.piece_justificative_file }
|
2019-06-17 16:13:12 +02:00
|
|
|
let(:user_can_destroy) { false }
|
2022-09-19 18:27:50 +02:00
|
|
|
let(:template) { nil }
|
2019-06-17 16:13:12 +02:00
|
|
|
|
|
|
|
subject do
|
|
|
|
form_for(champ.dossier) do |form|
|
2022-09-19 18:27:50 +02:00
|
|
|
view.render Attachment::EditComponent.new(form: form, attached_file: attached_file, user_can_destroy: true, direct_upload: true, template:)
|
2019-06-17 16:13:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-22 10:58:04 +02:00
|
|
|
context 'when there is no attached file' do
|
|
|
|
before do
|
2020-07-01 11:20:53 +02:00
|
|
|
champ.piece_justificative_file = nil
|
2019-10-22 10:58:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders a form field for uploading a file' do
|
|
|
|
expect(subject).to have_selector('input[type=file]:not(.hidden)')
|
|
|
|
end
|
2019-06-17 16:13:12 +02:00
|
|
|
end
|
|
|
|
|
2020-07-29 12:20:05 +02:00
|
|
|
context 'when there is an attached file' do
|
2019-06-17 16:13:12 +02:00
|
|
|
it 'renders a form field for uploading a file' do
|
|
|
|
expect(subject).to have_selector('input[type=file]:not(.hidden)')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not renders a link to the unsaved file' do
|
2019-10-22 10:58:04 +02:00
|
|
|
expect(subject).not_to have_content(attached_file.filename.to_s)
|
2019-06-17 16:13:12 +02:00
|
|
|
end
|
|
|
|
|
2020-07-29 12:20:05 +02:00
|
|
|
it 'does not render action buttons' do
|
2019-06-17 16:13:12 +02:00
|
|
|
expect(subject).not_to have_link('Remplacer')
|
|
|
|
expect(subject).not_to have_link('Supprimer')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and the attachment has been saved' do
|
|
|
|
before { champ.save! }
|
|
|
|
|
|
|
|
it 'renders a link to the file' do
|
2019-10-22 10:58:04 +02:00
|
|
|
expect(subject).to have_content(attached_file.filename.to_s)
|
2019-06-17 16:13:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides the form field by default' do
|
|
|
|
expect(subject).to have_selector('input[type=file].hidden')
|
|
|
|
end
|
|
|
|
|
2020-07-29 12:20:05 +02:00
|
|
|
it 'shows the Delete button by default' do
|
|
|
|
is_expected.to have_link('Supprimer')
|
2019-06-17 16:13:12 +02:00
|
|
|
end
|
2020-07-29 12:20:05 +02:00
|
|
|
end
|
|
|
|
end
|
2019-06-17 16:13:12 +02:00
|
|
|
|
2020-07-29 12:20:05 +02:00
|
|
|
context 'when the user cannot destroy the attachment' do
|
|
|
|
subject do
|
|
|
|
form_for(champ.dossier) do |form|
|
2022-05-11 08:57:25 +02:00
|
|
|
render Attachment::EditComponent.new(form: form,
|
2020-07-29 12:20:05 +02:00
|
|
|
attached_file: attached_file,
|
2022-06-16 15:51:45 +02:00
|
|
|
user_can_destroy: user_can_destroy,
|
|
|
|
direct_upload: true)
|
2019-06-17 16:13:12 +02:00
|
|
|
end
|
|
|
|
end
|
2020-07-29 12:20:05 +02:00
|
|
|
|
|
|
|
it 'hides the Delete button' do
|
|
|
|
is_expected.not_to have_link('Supprimer')
|
|
|
|
end
|
2019-06-17 16:13:12 +02:00
|
|
|
end
|
2022-09-19 18:27:50 +02:00
|
|
|
|
|
|
|
context 'when champ has a template' do
|
|
|
|
let(:profil) { :user }
|
|
|
|
let(:template) { champ.type_de_champ.piece_justificative_template }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(ActionView::Base).to receive(:administrateur_signed_in?).and_return(profil == :administrateur)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders a link to template' do
|
|
|
|
expect(subject).to have_link('le modèle suivant')
|
|
|
|
expect(subject).not_to have_text("éphémère")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as an administrator' do
|
|
|
|
let(:profil) { :administrateur }
|
|
|
|
it 'warn about ephemeral template url' do
|
|
|
|
expect(subject).to have_link('le modèle suivant')
|
|
|
|
expect(subject).to have_text("éphémère")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-06-17 16:13:12 +02:00
|
|
|
end
|