The message "Are you sure?" is usually followed by blindly clicking "Yes" without really thinking about what one is doing. So we're including a bit more information about what's about to happen. That way it's more likely users will notice it when they accidentally click the wrong button. Ideally we would offer the option to undo every common action and then we wouldn't have to ask for confirmation. But since that isn't the case, for now we're adding a better confirmation message. Note we're removing the `resource_name` parameter from the translation to confirm the action of deleting a record. The reason is, in many languages it only makes sense to add the model name when it's got an associated article, and, unlike in English (where "the" is used for every word), that article is different depending on the noun it's related to. So we'd have to provide a translation like "name with article, when singular" for every model. The complexity of these translations could scalate quickly. And, given the context, IMHO it isn't essential to add the resouce name. When we're in the proposals index and there's a proposal named "Improve XYZ", and we click on "Delete" and see a message saying "This action will delete XYZ", it is implied that XYZ is a proposal. So instead we're changing the message so it works for every record with no need of noun-dependent articles.
109 lines
3.7 KiB
Ruby
109 lines
3.7 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Admin::ActionComponent do
|
|
it "includes an HTML class for the action" do
|
|
render_inline Admin::ActionComponent.new(:edit, double, path: "/")
|
|
|
|
expect(page).to have_css "a.edit-link"
|
|
end
|
|
|
|
describe "aria-label attribute" do
|
|
it "is not rendered by default" do
|
|
record = double(human_name: "Stay home")
|
|
|
|
render_inline Admin::ActionComponent.new(:edit, record, path: "/")
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).not_to have_css "[aria-label]"
|
|
end
|
|
|
|
it "is not rendered when aria-label is nil" do
|
|
render_inline Admin::ActionComponent.new(:edit, double, path: "/", "aria-label": nil)
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).not_to have_css "[aria-label]"
|
|
end
|
|
|
|
it "renders with the given value" do
|
|
render_inline Admin::ActionComponent.new(:edit, double, path: "/", "aria-label": "Modify")
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).to have_css "[aria-label='Modify']"
|
|
end
|
|
|
|
context "when aria-label is true" do
|
|
it "includes the action and the human_name of the record" do
|
|
record = double(human_name: "Stay home")
|
|
|
|
render_inline Admin::ActionComponent.new(:edit, record, path: "/", "aria-label": true)
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).to have_css "a[aria-label='Edit Stay home']", exact_text: "Edit"
|
|
end
|
|
|
|
it "uses the to_s method when there's no human_name" do
|
|
record = double(to_s: "do_not_go_out")
|
|
|
|
render_inline Admin::ActionComponent.new(:edit, record, path: "/", "aria-label": true)
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).to have_css "a[aria-label='Edit Do not go out']", exact_text: "Edit"
|
|
end
|
|
|
|
it "uses the human_name when there are both human_name and to_s" do
|
|
record = double(human_name: "Stay home", to_s: "do_not_go_out")
|
|
|
|
render_inline Admin::ActionComponent.new(:edit, record, path: "/", "aria-label": true)
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).to have_css "a[aria-label='Edit Stay home']", exact_text: "Edit"
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "data-confirm attribute" do
|
|
it "is not rendered by default" do
|
|
render_inline Admin::ActionComponent.new(:edit, double, path: "/")
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).not_to have_css "[data-confirm]"
|
|
end
|
|
|
|
it "is not rendered when confirm is nil" do
|
|
render_inline Admin::ActionComponent.new(:edit, double, path: "/", confirm: nil)
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).not_to have_css "[data-confirm]"
|
|
end
|
|
|
|
it "renders with the given value" do
|
|
render_inline Admin::ActionComponent.new(:edit, double, path: "/", confirm: "Really?")
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).to have_css "[data-confirm='Really?']"
|
|
end
|
|
|
|
context "when confirm is true" do
|
|
it "uses the human name as default" do
|
|
record = double(human_name: "Everywhere and nowhere")
|
|
text = 'Are you sure? Edit "Everywhere and nowhere"'
|
|
|
|
render_inline Admin::ActionComponent.new(:edit, record, path: "/", confirm: true)
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).to have_css "[data-confirm='#{text}']"
|
|
end
|
|
|
|
it "includes a more detailed message for the destroy action" do
|
|
record = double(human_name: "Participatory Budget 2015")
|
|
text = 'Are you sure? This action will delete "Participatory Budget 2015" and can\\\'t be undone.'
|
|
|
|
render_inline Admin::ActionComponent.new(:destroy, record, path: "/", confirm: true)
|
|
|
|
expect(page).to have_link count: 1
|
|
expect(page).to have_css "[data-confirm='#{text}']"
|
|
end
|
|
end
|
|
end
|
|
end
|