From 2fb8abe83fdaf0d442999e3ef1580b5d2437563d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 10 Oct 2024 23:16:09 +0200 Subject: [PATCH] Use a button to delete documents While testing for accessibility issues (in a development branch), we're removing Turbolinks and monkey-patching the behavior of the `click_link` method to check the page for accessibility issues after each request. However, we were getting false positives when clicking links that act like buttons. So, for the reasons mentioned in commit 5311daadf, we're replacing the link to delete a document with a button. --- app/assets/stylesheets/documents/document.scss | 6 +++++- .../documents/document_component.html.erb | 10 +++++----- spec/shared/system/documentable.rb | 14 +++++++------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/assets/stylesheets/documents/document.scss b/app/assets/stylesheets/documents/document.scss index 54ecd651c..2b217757d 100644 --- a/app/assets/stylesheets/documents/document.scss +++ b/app/assets/stylesheets/documents/document.scss @@ -3,7 +3,7 @@ margin-top: calc(#{$line-height} / 3); } - a:first-of-type { + a { word-wrap: break-word; .document-metadata { @@ -18,4 +18,8 @@ } } } + + button { + cursor: pointer; + } } diff --git a/app/components/documents/document_component.html.erb b/app/components/documents/document_component.html.erb index 1de910081..f31ba2a12 100644 --- a/app/components/documents/document_component.html.erb +++ b/app/components/documents/document_component.html.erb @@ -8,10 +8,10 @@ <% end %> <% if show_destroy_link? && can?(:destroy, document) %> - <%= link_to t("documents.buttons.destroy_document"), - document, - method: :delete, - data: { confirm: t("documents.actions.destroy.confirm") }, - class: "delete" %> + <%= button_to t("documents.buttons.destroy_document"), + document, + method: :delete, + data: { confirm: t("documents.actions.destroy.confirm") }, + class: "delete" %> <% end %> diff --git a/spec/shared/system/documentable.rb b/spec/shared/system/documentable.rb index ad6727671..3f7177573 100644 --- a/spec/shared/system/documentable.rb +++ b/spec/shared/system/documentable.rb @@ -25,27 +25,27 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, scenario "Should not be able when no user logged in" do visit send(documentable_path, arguments) - expect(page).not_to have_link("Delete document") + expect(page).not_to have_button "Delete document" end scenario "Should be able when documentable author is logged in" do login_as documentable.author visit send(documentable_path, arguments) - expect(page).to have_link("Delete document") + expect(page).to have_button "Delete document" end scenario "Administrators cannot destroy documentables they have not authored", :admin do visit send(documentable_path, arguments) - expect(page).not_to have_link("Delete document") + expect(page).not_to have_button "Delete document" end scenario "Users cannot destroy documentables they have not authored" do login_as(create(:user)) visit send(documentable_path, arguments) - expect(page).not_to have_link("Delete document") + expect(page).not_to have_button "Delete document" end end @@ -93,7 +93,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, visit send(documentable_path, arguments) within "#document_#{document.id}" do - accept_confirm { click_link "Delete document" } + accept_confirm { click_button "Delete document" } end expect(page).to have_content "Document was deleted successfully." @@ -105,7 +105,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, visit send(documentable_path, arguments) within "#document_#{document.id}" do - accept_confirm { click_link "Delete document" } + accept_confirm { click_button "Delete document" } end expect(page).not_to have_content "Documents (0)" @@ -117,7 +117,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, visit send(documentable_path, arguments) within "#document_#{document.id}" do - accept_confirm { click_link "Delete document" } + accept_confirm { click_button "Delete document" } end within "##{ActionView::RecordIdentifier.dom_id(documentable)}" do