Merge pull request #8874 from tchak/fix-dossier-turbo-actions

fix(dossier): instructeur actions should be buttons and not links
This commit is contained in:
Paul Chavard 2023-04-07 10:35:20 +00:00 committed by GitHub
commit ce6f8369fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 34 deletions

View file

@ -7,7 +7,7 @@
dossier_is_followed: current_instructeur&.follow?(dossier), dossier_is_followed: current_instructeur&.follow?(dossier),
close_to_expiration: dossier.close_to_expiration?, close_to_expiration: dossier.close_to_expiration?,
hidden_by_administration: dossier.hidden_by_administration?, hidden_by_administration: dossier.hidden_by_administration?,
post_method: {data: { turbo_method: :post }}} turbo: true }
%li.instruction-button %li.instruction-button
= render partial: "instruction_button", locals: { dossier: dossier } = render partial: "instruction_button", locals: { dossier: dossier }

View file

@ -1,47 +1,49 @@
- if hidden_by_administration - if hidden_by_administration
%li %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') = t('views.instructeurs.dossiers.restore')
- elsif close_to_expiration || Dossier::TERMINE.include?(state) - elsif close_to_expiration || Dossier::TERMINE.include?(state)
%li{ 'data-turbo': 'true' } %li
- if close_to_expiration - 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 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') = t('instructeurs.dossiers.header.banner.button_delay_expiration')
- elsif archived - 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 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 - 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 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 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) - elsif Dossier::EN_CONSTRUCTION_OU_INSTRUCTION.include?(state)
- if Dossier.states[:en_construction] == state - if Dossier.states[:en_construction] == state
%li{ 'data-turbo': 'true' } %li{ 'data-turbo': turbo ? 'true' : 'false' }
= 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 = 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 Passer en instruction
- elsif Dossier.states[:en_instruction] == state - elsif Dossier.states[:en_instruction] == state
%li{ 'data-turbo': 'true' } %li{ 'data-turbo': turbo ? 'true' : 'false' }
= 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 = 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 Repasser en construction
- if dossier_is_followed - if dossier_is_followed
%li %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') = t('views.instructeurs.dossiers.stop_follow')
- else - else
%li %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') = t('views.instructeurs.dossiers.follow_file')

View file

@ -174,14 +174,14 @@
%td.action-col.follow-col %td.action-col.follow-col
%ul.inline.fr-btns-group.fr-btns-group--sm.fr-btns-group--inline.fr-btns-group--icon-right %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, dossier_id: p.dossier_id,
state: p.state, state: p.state,
archived: p.archived, archived: p.archived,
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: @statut == 'expirant', close_to_expiration: @statut == 'expirant',
hidden_by_administration: @statut == 'supprimes_recemment', hidden_by_administration: @statut == 'supprimes_recemment',
post_method: { method: :post } } turbo: false }
%tfoot %tfoot
%tr %tr
%td.force-table-100{ colspan: @procedure_presentation.displayed_fields_for_headers.size + 2 }= paginate @filtered_sorted_paginated_ids %td.force-table-100{ colspan: @procedure_presentation.displayed_fields_for_headers.size + 2 }= paginate @filtered_sorted_paginated_ids

View file

@ -98,7 +98,7 @@
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: nil, close_to_expiration: nil,
hidden_by_administration: nil, hidden_by_administration: nil,
post_method: { method: :post } } turbo: false }
- else - else
%td %td

View file

@ -61,7 +61,7 @@ describe 'Instructing a dossier:', js: true do
end end
expect(page).to have_text('Dossier traité avec succès.') 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 dossier.reload
expect(dossier.state).to eq(Dossier.states.fetch(:accepte)) 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 procedure.libelle
click_on 'traité' click_on 'traité'
expect(page).to have_link('Repasser en instruction') expect(page).to have_button('Repasser en instruction')
page.click_link('', title: 'Supprimer le dossier') click_on 'Supprimer le dossier'
click_on 'traité' click_on 'traité'
expect(page).not_to have_link('Repasser en instruction') expect(page).not_to have_button('Repasser en instruction')
end end
scenario 'An instructeur can destroy a dossier from view' do 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.passer_en_instruction(instructeur: instructeur)
dossier.accepter!(instructeur: instructeur) dossier.accepter!(instructeur: instructeur)
visit instructeur_dossier_path(procedure, dossier) visit instructeur_dossier_path(procedure, dossier)
page.click_link('', title: 'Supprimer le dossier') click_on 'Supprimer le dossier'
end end
scenario 'A instructeur can follow/unfollow a dossier' do scenario 'A instructeur can follow/unfollow a dossier' do

View file

@ -55,8 +55,12 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
context 'en_contruction' do context 'en_contruction' do
let(:dossier) { create(:dossier, :en_construction) } let(:dossier) { create(:dossier, :en_construction) }
it 'displays the correct actions' do it 'displays the correct actions' do
expect(subject).to have_link('Passer en instruction', href: passer_en_instruction_instructeur_dossier_path(dossier.procedure, dossier)) within("form[action=\"#{passer_en_instruction_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do
expect(subject).to have_link('Suivre le dossier', href: follow_instructeur_dossier_path(dossier.procedure, dossier)) 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) expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2)
end end
end end
@ -70,10 +74,14 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
end end
it 'displays the correct actions' do it 'displays the correct actions' do
expect(subject).to have_link('Repasser en construction', href: repasser_en_construction_instructeur_dossier_path(dossier.procedure, dossier)) within("form[action=\"#{repasser_en_construction_instructeur_dossier_path(dossier.procedure, dossier)}\"]") do
expect(subject).to have_link('Ne plus suivre', href: unfollow_instructeur_dossier_path(dossier.procedure, dossier)) 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_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) expect(subject).to have_selector('.header-actions ul:first-child > li.instruction-button', count: 1)
end end
end end
@ -82,8 +90,12 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
let(:dossier) { create(:dossier, :accepte) } let(:dossier) { create(:dossier, :accepte) }
it 'displays the correct actions' do it 'displays the correct actions' do
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_link('Archiver le dossier', href: archive_instructeur_dossier_path(dossier.procedure, dossier)) 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('[title^="Supprimer le dossier"]')
expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 3) expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 3)
end end
@ -98,7 +110,9 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
end end
it 'displays the correct actions' do 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) expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 1)
end end
end end
@ -109,7 +123,9 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
it 'displays the correct actions' do it 'displays the correct actions' do
expect(subject).to have_text('Conserver un mois de plus') 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) expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2)
end end
end end
@ -118,7 +134,9 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
let(:dossier) { create(:dossier, :accepte, :archived) } let(:dossier) { create(:dossier, :accepte, :archived) }
it 'displays the correct actions' do 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('[title^="Supprimer le dossier"]')
expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2) expect(subject).to have_selector('.header-actions ul:first-child .fr-btn', count: 2)
end end