Merge pull request #8630 from demarches-simplifiees/harmonize-actions-for-instructeurs
[instructeurs] Uniformiser les actions pour les instructeurs sur la page tableau et dossier
This commit is contained in:
commit
54f17ad3c7
30 changed files with 399 additions and 381 deletions
|
@ -0,0 +1,43 @@
|
|||
describe 'instructeurs/dossiers/instruction_button.html.haml', type: :view do
|
||||
include DossierHelper
|
||||
|
||||
subject! do
|
||||
render('instructeurs/dossiers/instruction_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 'en_instruction' do
|
||||
let(:dossier) { create(:dossier, :en_instruction) }
|
||||
|
||||
it 'renders a dropdown' do
|
||||
expect(rendered).to have_dropdown_title('Instruire le dossier')
|
||||
expect(rendered).to have_dropdown_items(count: 3)
|
||||
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
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
describe 'instructeurs/dossiers/state_button_motivation.html.haml', type: :view do
|
||||
describe 'instructeurs/dossiers/instruction_button_motivation.html.haml', type: :view do
|
||||
let(:dossier) { create(:dossier, :en_instruction) }
|
||||
|
||||
subject do
|
||||
render(
|
||||
'instructeurs/dossiers/state_button_motivation.html.haml',
|
||||
'instructeurs/dossiers/instruction_button_motivation.html.haml',
|
||||
dossier: dossier,
|
||||
popup_title: 'Accepter le dossier',
|
||||
placeholder: 'Expliquez au demandeur pourquoi ce dossier est accepté (facultatif)',
|
|
@ -1,120 +0,0 @@
|
|||
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.
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
it 'renders a dropdown' do
|
||||
expect(rendered).to have_dropdown_title('Brouillon')
|
||||
expect(rendered).to have_dropdown_items(count: 0)
|
||||
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 }
|
||||
|
||||
it 'renders a dropdown' do
|
||||
expect(rendered).to have_dropdown_title(dossier_display_state(dossier))
|
||||
expect(rendered).to have_dropdown_items(count: 2)
|
||||
expect(rendered).to have_dropdown_item('Repasser en instruction', href: repasser_en_instruction_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
end
|
||||
|
||||
context 'with a motivation' do
|
||||
let(:dossier) { create :dossier, state, :with_motivation }
|
||||
|
||||
it 'displays the motivation text' do
|
||||
expect(rendered).to have_dropdown_item('Motivation')
|
||||
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
|
||||
expect(rendered).to have_dropdown_item('Voir l’attestation')
|
||||
expect(rendered).to have_link(href: attestation_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a justificatif' do
|
||||
let(:dossier) do
|
||||
dossier = create(:dossier, state, :with_justificatif)
|
||||
dossier.justificatif_motivation.blob.update(virus_scan_result: ActiveStorage::VirusScanner::SAFE)
|
||||
dossier
|
||||
end
|
||||
|
||||
it 'allows to download the justificatif' do
|
||||
expect(rendered).to have_dropdown_item('Justificatif')
|
||||
expect(response).to have_css("a[href*='/rails/active_storage/blobs/']", text: dossier.justificatif_motivation.attachment.filename.to_s)
|
||||
end
|
||||
end
|
||||
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
|
|
@ -8,15 +8,119 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
|
|||
assign(:dossier, dossier)
|
||||
end
|
||||
|
||||
subject! { render }
|
||||
subject { render }
|
||||
|
||||
it 'renders the header' do
|
||||
expect(rendered).to have_text("Dossier nº #{dossier.id}")
|
||||
expect(subject).to have_text("Dossier nº #{dossier.id}")
|
||||
end
|
||||
|
||||
it 'renders the dossier infos' do
|
||||
expect(rendered).to have_text('Identité')
|
||||
expect(rendered).to have_text('Demande')
|
||||
expect(subject).to have_text('Identité')
|
||||
expect(subject).to have_text('Demande')
|
||||
end
|
||||
|
||||
it 'renders the correct dossier state' do
|
||||
expect(subject).to have_text('en construction')
|
||||
end
|
||||
|
||||
context 'with a motivation' do
|
||||
let(:dossier) { create :dossier, :accepte, :with_motivation }
|
||||
|
||||
it 'displays the motivation text' do
|
||||
expect(subject).to have_content(dossier.motivation)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an attestation' do
|
||||
let(:dossier) { create :dossier, :accepte, :with_attestation }
|
||||
|
||||
it 'provides a link to the attestation' do
|
||||
expect(subject).to have_text('Attestation')
|
||||
expect(subject).to have_link(href: attestation_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a justificatif' do
|
||||
let(:dossier) do
|
||||
dossier = create(:dossier, :accepte, :with_justificatif)
|
||||
dossier.justificatif_motivation.blob.update(virus_scan_result: ActiveStorage::VirusScanner::SAFE)
|
||||
dossier
|
||||
end
|
||||
|
||||
it 'allows to download the justificatif' do
|
||||
expect(subject).to have_css("a[href*='/rails/active_storage/blobs/']", text: dossier.justificatif_motivation.attachment.filename.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
context 'en_contruction' do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
it 'displays the correct actions' do
|
||||
expect(subject).to have_link('Passer en instruction', href: passer_en_instruction_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_link('Suivre le dossier', href: follow_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'en_instruction' do
|
||||
let(:dossier) { create(:dossier, :en_instruction) }
|
||||
|
||||
before do
|
||||
current_instructeur.followed_dossiers << dossier
|
||||
render
|
||||
end
|
||||
|
||||
it 'displays the correct actions' do
|
||||
expect(subject).to have_link('Repasser en construction', href: repasser_en_construction_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_link('Ne plus suivre', href: unfollow_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_button('Instruire le dossier')
|
||||
expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 3)
|
||||
end
|
||||
end
|
||||
|
||||
context 'accepte' do
|
||||
let(:dossier) { create(:dossier, :accepte) }
|
||||
|
||||
it 'displays the correct actions' do
|
||||
expect(subject).to have_link('Repasser en instruction', href: repasser_en_instruction_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_link('Archiver le dossier', href: archive_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_selector('[title^="Supprimer le dossier"]')
|
||||
expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 3)
|
||||
end
|
||||
end
|
||||
|
||||
context 'supprime' do
|
||||
let(:dossier) { create(:dossier, :accepte) }
|
||||
|
||||
before do
|
||||
dossier.hide_and_keep_track!(current_instructeur, :instructeur_request)
|
||||
render
|
||||
end
|
||||
|
||||
it 'displays the correct actions' do
|
||||
expect(subject).to have_link('Restaurer', href: restore_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'expirant' do
|
||||
let(:procedure) { create(:procedure, :published, duree_conservation_dossiers_dans_ds: 6, procedure_expires_when_termine_enabled: true) }
|
||||
let!(:dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: 175.days.ago) }
|
||||
|
||||
it 'displays the correct actions' do
|
||||
expect(subject).to have_text('Conserver un mois de plus')
|
||||
expect(subject).to have_link('Repasser en instruction', href: repasser_en_instruction_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'archived' do
|
||||
let(:dossier) { create(:dossier, :accepte, :archived) }
|
||||
|
||||
it 'displays the correct actions' do
|
||||
expect(subject).to have_link('Désarchiver le dossier', href: unarchive_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(subject).to have_selector('[title^="Supprimer le dossier"]')
|
||||
expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user is logged in with france connect' do
|
||||
|
@ -39,7 +143,7 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
|
|||
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, as_degraded_mode: false) }
|
||||
|
||||
it 'contains no warning' do
|
||||
expect(rendered).not_to have_text("Les services de l’INSEE sont indisponibles")
|
||||
expect(subject).not_to have_text("Les services de l’INSEE sont indisponibles")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,7 +151,7 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
|
|||
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, as_degraded_mode: true) }
|
||||
|
||||
it 'warns the instructeur' do
|
||||
expect(rendered).to have_text("Les services de l’INSEE sont indisponibles")
|
||||
expect(subject).to have_text("Les services de l’INSEE sont indisponibles")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue