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.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
margin-top: calc(#{$line-height} / 3);
|
margin-top: calc(#{$line-height} / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
a:first-of-type {
|
a {
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
|
|
||||||
.document-metadata {
|
.document-metadata {
|
||||||
@@ -18,4 +18,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if show_destroy_link? && can?(:destroy, document) %>
|
<% if show_destroy_link? && can?(:destroy, document) %>
|
||||||
<%= link_to t("documents.buttons.destroy_document"),
|
<%= button_to t("documents.buttons.destroy_document"),
|
||||||
document,
|
document,
|
||||||
method: :delete,
|
method: :delete,
|
||||||
data: { confirm: t("documents.actions.destroy.confirm") },
|
data: { confirm: t("documents.actions.destroy.confirm") },
|
||||||
|
|||||||
@@ -25,27 +25,27 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
|
|||||||
scenario "Should not be able when no user logged in" do
|
scenario "Should not be able when no user logged in" do
|
||||||
visit send(documentable_path, arguments)
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
expect(page).not_to have_link("Delete document")
|
expect(page).not_to have_button "Delete document"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Should be able when documentable author is logged in" do
|
scenario "Should be able when documentable author is logged in" do
|
||||||
login_as documentable.author
|
login_as documentable.author
|
||||||
visit send(documentable_path, arguments)
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
expect(page).to have_link("Delete document")
|
expect(page).to have_button "Delete document"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Administrators cannot destroy documentables they have not authored", :admin do
|
scenario "Administrators cannot destroy documentables they have not authored", :admin do
|
||||||
visit send(documentable_path, arguments)
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
expect(page).not_to have_link("Delete document")
|
expect(page).not_to have_button "Delete document"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Users cannot destroy documentables they have not authored" do
|
scenario "Users cannot destroy documentables they have not authored" do
|
||||||
login_as(create(:user))
|
login_as(create(:user))
|
||||||
visit send(documentable_path, arguments)
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
expect(page).not_to have_link("Delete document")
|
expect(page).not_to have_button "Delete document"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
|
|||||||
visit send(documentable_path, arguments)
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
within "#document_#{document.id}" do
|
within "#document_#{document.id}" do
|
||||||
accept_confirm { click_link "Delete document" }
|
accept_confirm { click_button "Delete document" }
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_content "Document was deleted successfully."
|
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)
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
within "#document_#{document.id}" do
|
within "#document_#{document.id}" do
|
||||||
accept_confirm { click_link "Delete document" }
|
accept_confirm { click_button "Delete document" }
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).not_to have_content "Documents (0)"
|
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)
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
within "#document_#{document.id}" do
|
within "#document_#{document.id}" do
|
||||||
accept_confirm { click_link "Delete document" }
|
accept_confirm { click_button "Delete document" }
|
||||||
end
|
end
|
||||||
|
|
||||||
within "##{ActionView::RecordIdentifier.dom_id(documentable)}" do
|
within "##{ActionView::RecordIdentifier.dom_id(documentable)}" do
|
||||||
|
|||||||
Reference in New Issue
Block a user