2024-04-29 00:17:15 +02:00
# frozen_string_literal: true
2023-03-06 15:51:08 +01:00
describe 'instructeurs/dossiers/show' , type : :view do
2019-08-06 11:02:54 +02:00
let ( :current_instructeur ) { create ( :instructeur ) }
2018-09-25 15:56:18 +02:00
let ( :dossier ) { create ( :dossier , :en_construction ) }
2017-07-11 16:50:29 +02:00
before do
2019-08-07 11:15:16 +02:00
sign_in ( current_instructeur . user )
2019-08-08 17:36:08 +02:00
allow ( view ) . to receive ( :current_instructeur ) . and_return ( current_instructeur )
2017-07-11 16:50:29 +02:00
assign ( :dossier , dossier )
end
2023-02-22 12:03:37 +01:00
subject { render }
2017-07-11 16:50:29 +02:00
2018-09-25 15:56:18 +02:00
it 'renders the header' do
2023-02-22 12:03:37 +01:00
expect ( subject ) . to have_text ( " Dossier nº #{ dossier . id } " )
2017-07-11 16:50:29 +02:00
end
2018-09-25 15:56:18 +02:00
it 'renders the dossier infos' do
2023-02-22 12:03:37 +01:00
expect ( subject ) . to have_text ( 'Identité' )
expect ( subject ) . to have_text ( 'Demande' )
end
it 'renders the correct dossier state' do
2023-04-18 13:09:22 +02:00
expect ( subject ) . to have_text ( 'en construction' )
2023-02-22 12:03:37 +01:00
end
2023-04-18 18:06:24 +02:00
context 'en_construction' do
2023-02-22 12:03:37 +01:00
let ( :dossier ) { create ( :dossier , :en_construction ) }
it 'displays the correct actions' do
2023-04-07 10:43:21 +02:00
within ( " form[action= \" #{ passer_en_instruction_instructeur_dossier_path ( dossier . procedure , dossier ) } \" ] " ) do
2023-12-07 17:32:39 +01:00
expect ( subject ) . to have_button ( 'Passer en instruction' , disabled : false )
2023-04-07 10:43:21 +02:00
end
within ( " form[action= \" #{ follow_instructeur_dossier_path ( dossier . procedure , dossier ) } \" ] " ) do
expect ( subject ) . to have_button ( 'Suivre le dossier' )
end
2023-04-13 19:10:09 +02:00
expect ( subject ) . to have_button ( 'Demander une correction' )
2023-03-14 17:23:17 +01:00
expect ( subject ) . to have_selector ( '.header-actions ul:first-child > li.instruction-button' , count : 1 )
2023-02-22 12:03:37 +01:00
end
2023-12-07 17:32:39 +01:00
context 'with pending correction' do
before { create ( :dossier_correction , dossier : ) }
2023-12-18 12:32:27 +01:00
it { expect ( subject ) . to have_button ( 'Passer en instruction' , disabled : false ) }
2024-01-24 17:01:59 +01:00
it 'shows the correction badge' do
expect ( subject ) . to have_selector ( '.fr-badge--warning' , text : " en attente " )
end
2023-12-18 12:32:27 +01:00
context 'with procedure blocking pending correction' do
before { Flipper . enable ( :blocking_pending_correction , dossier . procedure ) }
it 'disable the instruction button' do
expect ( subject ) . to have_button ( 'Passer en instruction' , disabled : true )
expect ( subject ) . to have_content ( 'Le passage en instruction est impossible' )
end
2023-12-07 17:32:39 +01:00
end
end
2024-01-24 17:01:59 +01:00
context 'with resolved correction' do
before { create ( :dossier_correction , dossier : , resolved_at : 1 . minute . ago ) }
it 'shows the resolved badge' do
expect ( subject ) . to have_selector ( '.fr-badge--success' , text : " corrigé " )
end
end
2023-02-22 12:03:37 +01:00
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
2023-04-07 10:43:21 +02:00
within ( " form[action= \" #{ unfollow_instructeur_dossier_path ( dossier . procedure , dossier ) } \" ] " ) do
expect ( subject ) . to have_button ( 'Ne plus suivre' )
end
2023-04-18 18:06:24 +02:00
expect ( subject ) . to have_button ( 'Repasser en construction' )
expect ( subject ) . to have_selector ( '.en-construction-menu .fr-btn' , count : 5 )
2023-02-22 12:03:37 +01:00
expect ( subject ) . to have_button ( 'Instruire le dossier' )
2023-04-18 18:06:24 +02:00
expect ( subject ) . to have_selector ( '.instruction-button .fr-btn' , count : 13 )
2023-02-22 12:03:37 +01:00
end
end
context 'accepte' do
let ( :dossier ) { create ( :dossier , :accepte ) }
it 'displays the correct actions' do
2023-04-07 10:43:21 +02:00
within ( " form[action= \" #{ repasser_en_instruction_instructeur_dossier_path ( dossier . procedure , dossier ) } \" ] " ) do
expect ( subject ) . to have_button ( 'Repasser en instruction' )
end
within ( " form[action= \" #{ archive_instructeur_dossier_path ( dossier . procedure , dossier ) } \" ] " ) do
expect ( subject ) . to have_button ( 'Archiver le dossier' )
end
2023-02-22 12:03:37 +01:00
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
2023-04-07 10:43:21 +02:00
within ( " form[action= \" #{ restore_instructeur_dossier_path ( dossier . procedure , dossier ) } \" ] " ) do
expect ( subject ) . to have_button ( 'Restaurer' )
end
2023-02-22 12:03:37 +01:00
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' )
2023-04-07 10:43:21 +02:00
within ( " form[action= \" #{ repasser_en_instruction_instructeur_dossier_path ( dossier . procedure , dossier ) } \" ] " ) do
expect ( subject ) . to have_button ( 'Repasser en instruction' )
end
2023-02-27 17:57:46 +01:00
expect ( subject ) . to have_selector ( '.header-actions ul:first-child .fr-btn' , count : 2 )
2023-02-22 12:03:37 +01:00
end
end
context 'archived' do
let ( :dossier ) { create ( :dossier , :accepte , :archived ) }
it 'displays the correct actions' do
2023-04-07 10:43:21 +02:00
within ( " form[action= \" #{ unarchive_instructeur_dossier_path ( dossier . procedure , dossier ) } \" ] " ) do
expect ( subject ) . to have_button ( 'Désarchiver le dossier' )
end
2023-02-23 16:55:46 +01:00
expect ( subject ) . to have_selector ( '[title^="Supprimer le dossier"]' )
expect ( subject ) . to have_selector ( '.header-actions ul:first-child .fr-btn' , count : 2 )
2023-02-22 12:03:37 +01:00
end
2017-07-11 16:50:29 +02:00
end
2020-11-02 11:37:21 +01:00
context 'when the user is logged in with france connect' do
let ( :france_connect_information ) { build ( :france_connect_information ) }
2024-03-05 14:00:54 +01:00
let ( :user ) { build ( :user , france_connect_informations : [ france_connect_information ] ) }
2020-11-02 11:37:21 +01:00
let ( :procedure1 ) { create ( :procedure , :with_type_de_champ , for_individual : true ) }
let ( :dossier ) { create ( :dossier , procedure : procedure1 , user : user ) }
before do
render
end
it 'fills the individual with the informations from France Connect' do
2022-09-14 16:19:14 +02:00
expect ( view . content_for ( :notice_info ) ) . to have_text ( " Le dossier a été déposé par le compte de #{ france_connect_information . given_name } #{ france_connect_information . family_name } , authentifié par FranceConnect le #{ france_connect_information . updated_at . strftime ( '%d/%m/%Y' ) } " )
2020-11-02 11:37:21 +01:00
end
end
2022-09-21 15:17:44 +02:00
describe 'entreprise degraded mode' do
context 'etablissement complete' do
let ( :dossier ) { create ( :dossier , :en_construction , :with_entreprise , as_degraded_mode : false ) }
it 'contains no warning' do
2023-02-22 12:03:37 +01:00
expect ( subject ) . not_to have_text ( " Les services de l’ INSEE sont indisponibles " )
2022-09-21 15:17:44 +02:00
end
end
context 'etablissement in degraded mode' do
let ( :dossier ) { create ( :dossier , :en_construction , :with_entreprise , as_degraded_mode : true ) }
it 'warns the instructeur' do
2023-02-22 12:03:37 +01:00
expect ( subject ) . to have_text ( " Les services de l’ INSEE sont indisponibles " )
2022-09-21 15:17:44 +02:00
end
end
end
2024-04-15 10:37:47 +02:00
describe 'accuse de lecture ' do
context 'dossier not termine' do
let ( :dossier ) { create ( :dossier , :en_instruction , procedure : create ( :procedure , :accuse_lecture ) ) }
it 'does not display a text about accuse de lecture for instructeur' do
expect ( subject ) . not_to have_text ( 'Cette démarche est soumise à un accusé de lecture' )
end
end
context 'dossier termine with accuse de lecture not accepted by user' do
let ( :dossier ) { create ( :dossier , :accepte , procedure : create ( :procedure , :accuse_lecture ) ) }
it 'displays a text about accuse de lecture for instructeur' do
expect ( subject ) . to have_text ( 'Cette démarche est soumise à un accusé de lecture' )
expect ( subject ) . to have_text ( 'L’ usager n’ a pas encore pris connaissance de la décision concernant son dossier' )
end
end
context 'dossier termine with accuse de lecture accepted by user' do
let ( :dossier ) { create ( :dossier , :accepte , accuse_lecture_agreement_at : Time . zone . now , procedure : create ( :procedure , :accuse_lecture ) ) }
it 'displays a text about accuse de lecture for instructeur' do
expect ( subject ) . to have_text ( 'Cette démarche est soumise à un accusé de lecture' )
expect ( subject ) . to have_text ( 'L’ usager a pris connaissance de la décision concernant son dossier le' )
end
end
end
2024-06-21 05:49:42 +02:00
describe 'when header_sections are present' do
let ( :procedure ) { create ( :procedure , types_de_champ_public : ) }
let ( :types_de_champ_public ) do
[
{ type : :header_section , level : 1 , libelle : 'l1' }
]
end
let ( :dossier ) { create ( :dossier , :en_construction , procedure : ) }
it 'displays a link to header_section' do
expect ( subject ) . to have_selector ( 'a.fr-sidemenu__link' , text : 'l1' )
end
end
2024-10-01 15:17:09 +02:00
describe " Dossier labels " do
2024-10-15 11:12:21 +02:00
let ( :procedure ) { create ( :procedure , :with_labels ) }
let ( :dossier ) { create ( :dossier , :en_construction , procedure : ) }
2024-10-16 16:38:16 +02:00
context " Procedure without labels " do
let ( :procedure_without_labels ) { create ( :procedure ) }
let ( :dossier ) { create ( :dossier , :en_construction , procedure : procedure_without_labels ) }
it 'does not display button to add label or dropdown' do
expect ( subject ) . not_to have_text ( " Ajouter un label " )
2024-10-28 14:33:57 +01:00
expect ( subject ) . not_to have_text ( " À examiner " )
2024-10-16 16:38:16 +02:00
end
end
2024-10-01 15:17:09 +02:00
context " Dossier without labels " do
it 'displays button with text to add label' do
expect ( subject ) . to have_text ( " Ajouter un label " )
expect ( subject ) . to have_selector ( " button.dropdown-button " )
2024-10-28 14:33:57 +01:00
expect ( subject ) . to have_text ( " À examiner " , count : 1 )
2024-10-01 15:17:09 +02:00
within ( '.dropdown' ) do
2024-10-28 14:33:57 +01:00
expect ( subject ) . to have_text ( " À examiner " , count : 1 )
2024-10-01 15:17:09 +02:00
end
end
end
context " Dossier with labels " do
before do
2024-10-29 14:52:14 +01:00
DossierLabel . create ( dossier_id : dossier . id , label_id : dossier . procedure . labels . first . id )
2024-10-01 15:17:09 +02:00
end
it 'displays labels and button without text to add label' do
expect ( subject ) . not_to have_text ( " Ajouter un label " )
expect ( subject ) . to have_selector ( " button.dropdown-button " )
2024-10-28 14:33:57 +01:00
expect ( subject ) . to have_text ( " À examiner " , count : 2 )
2024-10-01 15:17:09 +02:00
within ( '.dropdown' ) do
2024-10-28 14:33:57 +01:00
expect ( subject ) . to have_text ( " À examiner " , count : 1 )
2024-10-01 15:17:09 +02:00
end
end
end
end
2017-07-11 16:50:29 +02:00
end