From 207ce2132731c477c070e8d24f822f1dbb191de6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Apr 2023 10:43:21 +0200 Subject: [PATCH] fix(dossier): instructeur actions should be buttons and not links --- .../dossiers/_header_actions.html.haml | 2 +- .../procedures/_dossier_actions.html.haml | 32 ++++++++-------- .../instructeurs/procedures/show.html.haml | 4 +- app/views/recherche/index.html.haml | 2 +- spec/system/instructeurs/instruction_spec.rb | 10 ++--- .../dossiers/show.html.haml_spec.rb | 38 ++++++++++++++----- 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/app/views/instructeurs/dossiers/_header_actions.html.haml b/app/views/instructeurs/dossiers/_header_actions.html.haml index 8ee89c31e..38b8856e9 100644 --- a/app/views/instructeurs/dossiers/_header_actions.html.haml +++ b/app/views/instructeurs/dossiers/_header_actions.html.haml @@ -7,7 +7,7 @@ dossier_is_followed: current_instructeur&.follow?(dossier), close_to_expiration: dossier.close_to_expiration?, hidden_by_administration: dossier.hidden_by_administration?, - post_method: {data: { turbo_method: :post }}} + turbo: true } %li.instruction-button = render partial: "instruction_button", locals: { dossier: dossier } diff --git a/app/views/instructeurs/procedures/_dossier_actions.html.haml b/app/views/instructeurs/procedures/_dossier_actions.html.haml index f1a3f3027..91de51c96 100644 --- a/app/views/instructeurs/procedures/_dossier_actions.html.haml +++ b/app/views/instructeurs/procedures/_dossier_actions.html.haml @@ -1,47 +1,49 @@ - if hidden_by_administration %li - = link_to restore_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do + = button_to restore_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do = t('views.instructeurs.dossiers.restore') - elsif close_to_expiration || Dossier::TERMINE.include?(state) - %li{ 'data-turbo': 'true' } + %li - if close_to_expiration - = link_to repasser_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), { class: 'fr-btn fr-btn--secondary fr-icon-edit-line' }.deep_merge!(post_method) do + = button_to repasser_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-edit-line', form: { data: { turbo: turbo ? 'true' : 'false' } } do Repasser en instruction - = link_to(repousser_expiration_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: "fr-btn") do + = button_to repousser_expiration_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: "fr-btn" do = t('instructeurs.dossiers.header.banner.button_delay_expiration') - elsif archived - = link_to( unarchive_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-upload-2-line") do + = button_to unarchive_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-upload-2-line" do Désarchiver le dossier - = link_to('', instructeur_dossier_path(procedure_id, dossier_id), method: :delete, class: 'fr-btn fr-btn--secondary fr-icon-delete-line icon-only danger', title: t('views.instructeurs.dossiers.delete_dossier')) + = button_to instructeur_dossier_path(procedure_id, dossier_id), method: :delete, class: 'fr-btn fr-btn--secondary fr-icon-delete-line icon-only danger', title: t('views.instructeurs.dossiers.delete_dossier') do + = "" - else - = link_to repasser_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), { class: 'fr-btn fr-btn--secondary fr-icon-edit-line' }.deep_merge!(post_method) do + = button_to repasser_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-edit-line', form: { data: { turbo: turbo ? 'true' : 'false' } } do Repasser en instruction - = link_to( archive_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: 'fr-btn fr-icon-folder-2-line') do + = button_to archive_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: 'fr-btn fr-icon-folder-2-line' do Archiver le dossier - = link_to('', instructeur_dossier_path(procedure_id, dossier_id), method: :delete, class: 'fr-btn fr-btn--secondary fr-icon-delete-line icon-only danger', title: t('views.instructeurs.dossiers.delete_dossier')) + = button_to instructeur_dossier_path(procedure_id, dossier_id), method: :delete, class: 'fr-btn fr-btn--secondary fr-icon-delete-line icon-only danger', title: t('views.instructeurs.dossiers.delete_dossier') do + = "" - elsif Dossier::EN_CONSTRUCTION_OU_INSTRUCTION.include?(state) - if Dossier.states[:en_construction] == state - %li{ 'data-turbo': 'true' } - = link_to passer_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), { class: 'fr-btn fr-btn--secondary fr-icon-edit-line' }.deep_merge!(post_method) do + %li{ 'data-turbo': turbo ? 'true' : 'false' } + = button_to passer_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-edit-line' do Passer en instruction - elsif Dossier.states[:en_instruction] == state - %li{ 'data-turbo': 'true' } - = link_to repasser_en_construction_instructeur_dossier_path(procedure_id, dossier_id), { class: 'fr-btn fr-btn--secondary fr-icon-draft-line' }.deep_merge!(post_method) do + %li{ 'data-turbo': turbo ? 'true' : 'false' } + = button_to repasser_en_construction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-draft-line' do Repasser en construction - if dossier_is_followed %li - = link_to unfollow_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: 'fr-btn fr-btn--secondary fr-icon-star-fill' do + = button_to unfollow_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: 'fr-btn fr-btn--secondary fr-icon-star-fill' do = t('views.instructeurs.dossiers.stop_follow') - else %li - = link_to follow_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: 'fr-btn fr-icon-star-line' do + = button_to follow_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: 'fr-btn fr-icon-star-line' do = t('views.instructeurs.dossiers.follow_file') diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index f715e9e22..52a0d0dc4 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -174,14 +174,14 @@ %td.action-col.follow-col %ul.inline.fr-btns-group.fr-btns-group--sm.fr-btns-group--inline.fr-btns-group--icon-right - = render partial: 'dossier_actions', locals: { procedure_id: @procedure.id, + = render partial: 'instructeurs/procedures/dossier_actions', locals: { procedure_id: @procedure.id, dossier_id: p.dossier_id, state: p.state, archived: p.archived, dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), close_to_expiration: @statut == 'expirant', hidden_by_administration: @statut == 'supprimes_recemment', - post_method: { method: :post } } + turbo: false } %tfoot %tr %td.force-table-100{ colspan: @procedure_presentation.displayed_fields_for_headers.size + 2 }= paginate @filtered_sorted_paginated_ids diff --git a/app/views/recherche/index.html.haml b/app/views/recherche/index.html.haml index a5aaac223..ed16059ff 100644 --- a/app/views/recherche/index.html.haml +++ b/app/views/recherche/index.html.haml @@ -98,7 +98,7 @@ dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), close_to_expiration: nil, hidden_by_administration: nil, - post_method: { method: :post } } + turbo: false } - else %td diff --git a/spec/system/instructeurs/instruction_spec.rb b/spec/system/instructeurs/instruction_spec.rb index 48f8cb35b..a11895bed 100644 --- a/spec/system/instructeurs/instruction_spec.rb +++ b/spec/system/instructeurs/instruction_spec.rb @@ -61,7 +61,7 @@ describe 'Instructing a dossier:', js: true do end expect(page).to have_text('Dossier traité avec succès.') - expect(page).to have_link('Archiver le dossier') + expect(page).to have_button('Archiver le dossier') dossier.reload expect(dossier.state).to eq(Dossier.states.fetch(:accepte)) @@ -69,10 +69,10 @@ describe 'Instructing a dossier:', js: true do click_on procedure.libelle click_on 'traité' - expect(page).to have_link('Repasser en instruction') - page.click_link('', title: 'Supprimer le dossier') + expect(page).to have_button('Repasser en instruction') + click_on 'Supprimer le dossier' click_on 'traité' - expect(page).not_to have_link('Repasser en instruction') + expect(page).not_to have_button('Repasser en instruction') end scenario 'An instructeur can destroy a dossier from view' do @@ -81,7 +81,7 @@ describe 'Instructing a dossier:', js: true do dossier.passer_en_instruction(instructeur: instructeur) dossier.accepter!(instructeur: instructeur) visit instructeur_dossier_path(procedure, dossier) - page.click_link('', title: 'Supprimer le dossier') + click_on 'Supprimer le dossier' end scenario 'A instructeur can follow/unfollow a dossier' do diff --git a/spec/views/instructeur/dossiers/show.html.haml_spec.rb b/spec/views/instructeur/dossiers/show.html.haml_spec.rb index af0c65b74..b19e9cf9d 100644 --- a/spec/views/instructeur/dossiers/show.html.haml_spec.rb +++ b/spec/views/instructeur/dossiers/show.html.haml_spec.rb @@ -55,8 +55,12 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do 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)) + within("form[action=\"#{passer_en_instruction_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do + expect(subject).to have_button('Passer en instruction') + end + within("form[action=\"#{follow_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do + expect(subject).to have_button('Suivre le dossier') + end expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2) end end @@ -70,10 +74,14 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do 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)) + within("form[action=\"#{repasser_en_construction_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do + expect(subject).to have_button('Repasser en construction') + end + within("form[action=\"#{unfollow_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do + expect(subject).to have_button('Ne plus suivre') + end expect(subject).to have_button('Instruire le dossier') - expect(subject).to have_selector('.header-actions ul:first-child > li a.fr-btn', count: 2) + expect(subject).to have_selector('.header-actions ul:first-child > li .fr-btn', count: 15) expect(subject).to have_selector('.header-actions ul:first-child > li.instruction-button', count: 1) end end @@ -82,8 +90,12 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view 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)) + 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 expect(subject).to have_selector('[title^="Supprimer le dossier"]') expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 3) end @@ -98,7 +110,9 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do end it 'displays the correct actions' do - expect(subject).to have_link('Restaurer', href: restore_instructeur_dossier_path(dossier.procedure, dossier)) + within("form[action=\"#{restore_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do + expect(subject).to have_button('Restaurer') + end expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 1) end end @@ -109,7 +123,9 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do 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)) + within("form[action=\"#{repasser_en_instruction_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do + expect(subject).to have_button('Repasser en instruction') + end expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2) end end @@ -118,7 +134,9 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view 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)) + within("form[action=\"#{unarchive_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do + expect(subject).to have_button('Désarchiver le dossier') + end expect(subject).to have_selector('[title^="Supprimer le dossier"]') expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2) end