Merge branch 'main' into feature/add_rna_type_de_champs

This commit is contained in:
Damien Le Thiec 2022-10-05 12:38:24 +02:00 committed by GitHub
commit 0131a41266
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
253 changed files with 2393 additions and 1301 deletions

View file

@ -1,15 +1,58 @@
describe 'administrateurs/procedures/edit.html.haml' do
let(:logo) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') }
let(:populate_zones_task) { Rake::Task['after_party:populate_zones'] }
before do
assign(:procedure, procedure)
render
Flipper.enable(:zonage)
populate_zones_task.invoke
end
after do
populate_zones_task.reenable
end
context 'when procedure logo is present' do
it 'display on the page' do
assign(:procedure, procedure)
render
expect(rendered).to have_selector('.procedure-logos')
end
end
context 'when procedure has never been published' do
before { Timecop.freeze(now) }
after { Timecop.return }
let(:procedure) { create(:procedure, zone: Zone.find_by(acronym: 'MTEI')) }
let(:now) { Time.zone.parse('18/05/2022') }
it 'displays zones with label available at the creation date' do
assign(:procedure, procedure)
render
expect(rendered).to have_content("Ministère du Travail")
expect(rendered).not_to have_content("Ministère du Travail, du Plein emploi et de l'Insertion")
end
end
context 'when procedure has been published' do
before { Timecop.freeze(now) }
after { Timecop.return }
let(:procedure) { create(:procedure, zone: Zone.find_by(acronym: 'MTEI')) }
let(:now) { Time.zone.parse('18/05/2022') }
it 'displays zones with label available at the creation date' do
Timecop.freeze(Time.zone.parse('22/05/2022')) do
procedure.publish!
end
assign(:procedure, procedure)
render
expect(rendered).to have_content("Ministère du Travail, du Plein emploi et de l'Insertion")
end
end
end

View file

@ -30,7 +30,25 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
end
it 'fills the individual with the informations from France Connect' do
expect(rendered).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 France Connect le #{france_connect_information.updated_at.strftime('%d/%m/%Y')}")
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')}")
end
end
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
expect(rendered).not_to have_text("Les services de lINSEE sont indisponibles")
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
expect(rendered).to have_text("Les services de lINSEE sont indisponibles")
end
end
end
end

View file

@ -20,6 +20,7 @@ describe 'layouts/_header.html.haml', type: :view do
let(:profile) { nil }
it { is_expected.to have_css(".fr-header__logo") }
it { is_expected.to_not have_css(".account-btn") }
it 'displays the Help link' do
expect(subject).to have_link('Aide', href: FAQ_URL)
@ -44,6 +45,7 @@ describe 'layouts/_header.html.haml', type: :view do
it { is_expected.to have_css(".fr-header__logo") }
it { is_expected.to have_link("Dossiers", href: dossiers_path) }
it { is_expected.to have_selector(:button, user.email, class: "account-btn") }
it 'displays the Help button' do
expect(subject).to have_link("Aide", href: FAQ_URL)
@ -57,6 +59,7 @@ describe 'layouts/_header.html.haml', type: :view do
let(:current_instructeur) { instructeur }
it { is_expected.to have_css(".fr-header__logo") }
it { is_expected.to have_selector(:button, user.email, class: "account-btn") }
it 'displays the Help dropdown menu' do
expect(subject).to have_css(".help-dropdown")

View file

@ -2,10 +2,11 @@ describe 'shared/attachment/_update.html.haml', type: :view do
let(:champ) { build(:champ_piece_justificative, dossier: create(:dossier)) }
let(:attached_file) { champ.piece_justificative_file }
let(:user_can_destroy) { false }
let(:template) { nil }
subject do
form_for(champ.dossier) do |form|
view.render Attachment::EditComponent.new(form: form, attached_file: attached_file, user_can_destroy: true, direct_upload: true)
view.render Attachment::EditComponent.new(form: form, attached_file: attached_file, user_can_destroy: true, direct_upload: true, template:)
end
end
@ -64,4 +65,26 @@ describe 'shared/attachment/_update.html.haml', type: :view do
is_expected.not_to have_link('Supprimer')
end
end
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
end

View file

@ -0,0 +1,10 @@
describe 'views/shared/champs/multiple_drop_down_list/_show.html.haml', type: :view do
let(:champ) { build(:champ_multiple_drop_down_list, value: ['abc', '2, 3, 4']) }
subject { render partial: 'shared/champs/multiple_drop_down_list/show', locals: { champ: champ } }
it 'renders the view' do
subject
expect(rendered).to have_selector('li', count: champ.selected_options.size)
end
end

View file

@ -1,6 +1,7 @@
describe 'shared/dossiers/edit.html.haml', type: :view do
before do
allow(controller).to receive(:current_user).and_return(dossier.user)
allow(view).to receive(:administrateur_signed_in?).and_return(false)
end
subject { render 'shared/dossiers/edit.html.haml', dossier: dossier, apercu: false }
@ -118,7 +119,9 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
end
context 'when dossier is brouillon' do
before { dossier.champs << champ }
before do
dossier.champs << champ
end
it 'can delete a piece justificative' do
expect(subject).to have_text('Supprimer')

View file

@ -1,32 +0,0 @@
describe 'shared/dossiers/france_connect_informations.html.haml', type: :view do
subject do
render(
'shared/dossiers/france_connect_informations.html.haml',
user_information: user_information
)
end
context "with complete france_connect information" do
let(:user_information) { build(:france_connect_information, updated_at: Time.zone.now) }
it {
expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}, authentifié par France Connect le #{user_information.updated_at.strftime('%d/%m/%Y')}")
}
end
context "with missing updated_at" do
let(:user_information) { build(:france_connect_information, updated_at: nil) }
it {
expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}")
expect(subject).not_to have_text("authentifié par France Connect le ")
}
end
context "with missing given_name" do
let(:user_information) { build(:france_connect_information, given_name: nil) }
it {
expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.family_name}")
}
end
end

View file

@ -2,32 +2,50 @@ describe 'users/dossiers/brouillon.html.haml', type: :view do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_notice, :with_service) }
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:brouillon), procedure: procedure) }
let(:footer) { view.content_for(:footer) }
let(:profile) { :user }
before do
sign_in dossier.user
assign(:dossier, dossier)
# allow(view) doesn't work because method is called inside partial
ActionView::Base.any_instance.stub(:administrateur_signed_in?).and_return(profile == :administrateur)
end
subject! { render }
it 'affiche le libellé de la démarche' do
expect(rendered).to have_text(dossier.procedure.libelle)
context "as an user" do
it 'affiche le libellé de la démarche' do
expect(rendered).to have_text(dossier.procedure.libelle)
end
it 'affiche un lien vers la notice' do
expect(response).to have_css("a[href*='/rails/active_storage/blobs/']", text: "Guide de la démarche")
expect(rendered).not_to have_text("Ce lien est éphémère")
end
it 'affiche les boutons de validation' do
expect(rendered).to have_selector('.send-dossier-actions-bar')
end
it 'prépare le footer' do
expect(footer).to have_selector('footer')
end
context 'quand la démarche ne comporte pas de notice' do
let(:procedure) { create(:procedure) }
it { is_expected.not_to have_link("Guide de la démarche") }
end
end
it 'affiche un lien vers la notice' do
expect(response).to have_css("a[href*='/rails/active_storage/blobs/']", text: "Guide de la démarche")
end
context "as an administrateur" do
let(:profile) { :administrateur }
it 'affiche les boutons de validation' do
expect(rendered).to have_selector('.send-dossier-actions-bar')
end
before do
create(:administrateur, user: dossier.user)
end
it 'prépare le footer' do
expect(footer).to have_selector('footer')
end
context 'quand la démarche ne comporte pas de notice' do
let(:procedure) { create(:procedure) }
it { is_expected.not_to have_link("Guide de la démarche") }
it 'affiche un avertissement à propos de la notice' do
expect(rendered).to have_text("Ce lien est éphémère")
end
end
end

View file

@ -45,7 +45,7 @@ describe 'users/dossiers/demande.html.haml', type: :view do
end
it 'fills the individual with the informations from France Connect' do
expect(rendered).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 France Connect le #{france_connect_information.updated_at.strftime('%d/%m/%Y')}")
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')}")
end
end
end