2019-10-14 12:57:19 +02:00
|
|
|
|
describe 'instructeurs/dossiers/state_button.html.haml', type: :view do
|
|
|
|
|
include DossierHelper
|
|
|
|
|
|
|
|
|
|
subject! do
|
|
|
|
|
render('instructeurs/dossiers/state_button.html.haml', dossier: dossier)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
matcher :have_dropdown_title do |expected_title|
|
|
|
|
|
match do |rendered|
|
|
|
|
|
expect(rendered).to have_selector('.dropdown .dropdown-button', text: expected_title)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
matcher :have_dropdown_items do |options|
|
|
|
|
|
match do |rendered|
|
|
|
|
|
expected_count = options[:count] || 1
|
|
|
|
|
expect(rendered).to have_selector('ul.dropdown-items li', count: expected_count)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
matcher :have_dropdown_item do |expected_title, options = {}|
|
|
|
|
|
match do |rendered|
|
|
|
|
|
expected_href = options[:href]
|
|
|
|
|
if (expected_href.present?)
|
|
|
|
|
expect(rendered).to have_selector("ul.dropdown-items li a[href='#{expected_href}']", text: expected_title)
|
|
|
|
|
else
|
|
|
|
|
expect(rendered).to have_selector('ul.dropdown-items li', text: expected_title)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'brouillon' do
|
|
|
|
|
# Currently the state button is not supposed to be displayed for brouillons.
|
|
|
|
|
# But better have a sane fallback than crashing.
|
2019-10-14 13:18:59 +02:00
|
|
|
|
let(:dossier) { create(:dossier) }
|
2019-10-14 12:57:19 +02:00
|
|
|
|
|
2019-10-14 13:18:59 +02:00
|
|
|
|
it 'renders a dropdown' do
|
|
|
|
|
expect(rendered).to have_dropdown_title('Brouillon')
|
|
|
|
|
expect(rendered).to have_dropdown_items(count: 0)
|
2019-10-14 12:57:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'en_contruction' do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
|
|
|
|
|
|
|
|
|
it 'renders a dropdown' do
|
|
|
|
|
expect(rendered).to have_dropdown_title('En construction')
|
|
|
|
|
expect(rendered).to have_dropdown_items(count: 2)
|
|
|
|
|
expect(rendered).to have_dropdown_item('En construction')
|
|
|
|
|
expect(rendered).to have_dropdown_item('Passer en instruction', href: passer_en_instruction_instructeur_dossier_path(dossier.procedure, dossier))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'en_instruction' do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction) }
|
|
|
|
|
|
|
|
|
|
it 'renders a dropdown' do
|
|
|
|
|
expect(rendered).to have_dropdown_title('En instruction')
|
|
|
|
|
expect(rendered).to have_dropdown_items(count: 5)
|
|
|
|
|
expect(rendered).to have_dropdown_item('Repasser en construction', href: repasser_en_construction_instructeur_dossier_path(dossier.procedure, dossier))
|
|
|
|
|
expect(rendered).to have_dropdown_item('En instruction')
|
|
|
|
|
expect(rendered).to have_dropdown_item('Accepter')
|
|
|
|
|
expect(rendered).to have_dropdown_item('Classer sans suite')
|
|
|
|
|
expect(rendered).to have_dropdown_item('Refuser')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
shared_examples 'a dropdown for a closed state' do |state|
|
|
|
|
|
let(:dossier) { create :dossier, state }
|
|
|
|
|
|
2019-10-14 13:18:59 +02:00
|
|
|
|
it 'renders a dropdown' do
|
|
|
|
|
expect(rendered).to have_dropdown_title(dossier_display_state(dossier))
|
2020-11-17 13:25:35 +01:00
|
|
|
|
expect(rendered).to have_dropdown_items(count: 2)
|
2019-10-14 13:18:59 +02:00
|
|
|
|
expect(rendered).to have_dropdown_item('Repasser en instruction', href: repasser_en_instruction_instructeur_dossier_path(dossier.procedure, dossier))
|
2019-10-14 12:57:19 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with a motivation' do
|
2019-10-15 12:42:51 +02:00
|
|
|
|
let(:dossier) { create :dossier, state, :with_motivation }
|
2019-10-14 12:57:19 +02:00
|
|
|
|
|
|
|
|
|
it 'displays the motivation text' do
|
2019-10-15 12:42:51 +02:00
|
|
|
|
expect(rendered).to have_dropdown_item('Motivation')
|
2019-10-14 12:57:19 +02:00
|
|
|
|
expect(rendered).to have_content(dossier.motivation)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with an attestation' do
|
|
|
|
|
let(:dossier) { create :dossier, state, :with_attestation }
|
|
|
|
|
|
|
|
|
|
it 'provides a link to the attestation' do
|
2019-10-15 12:42:51 +02:00
|
|
|
|
expect(rendered).to have_dropdown_item('Voir l’attestation')
|
2019-10-14 12:57:19 +02:00
|
|
|
|
expect(rendered).to have_link(href: attestation_instructeur_dossier_path(dossier.procedure, dossier))
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-10-15 12:42:51 +02:00
|
|
|
|
|
|
|
|
|
context 'with a justificatif' do
|
|
|
|
|
let(:dossier) do
|
|
|
|
|
dossier = create(:dossier, state, :with_justificatif)
|
|
|
|
|
dossier.justificatif_motivation.blob.update(metadata: dossier.justificatif_motivation.blob.metadata.merge(virus_scan_result: ActiveStorage::VirusScanner::SAFE))
|
|
|
|
|
dossier
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'allows to download the justificatif' do
|
|
|
|
|
expect(rendered).to have_dropdown_item('Justificatif')
|
2019-12-19 18:29:01 +01:00
|
|
|
|
expect(response).to have_css("a[href*='/rails/active_storage/blobs/']", text: dossier.justificatif_motivation.attachment.filename.to_s)
|
2019-10-15 12:42:51 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-10-14 12:57:19 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'accepte' do
|
|
|
|
|
it_behaves_like 'a dropdown for a closed state', :accepte
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'refuse' do
|
|
|
|
|
it_behaves_like 'a dropdown for a closed state', :refuse
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'sans_suite' do
|
|
|
|
|
it_behaves_like 'a dropdown for a closed state', :sans_suite
|
|
|
|
|
end
|
|
|
|
|
end
|