Files
nairobi/spec/components/shared/check_all_none_component_spec.rb
Javi Martín c367f21705 Add buttons to check all/none available languages
Although most Consul Democracy installations will only have a few
available languages using `config.i18n.available_locales`, there's a
chance some installation will keep every language as available and will
enable the desired ones using the admin interface. In these cases,
enabling (or disabling) every language would be tedious, particularly
when casually experimenting in a staging environment or while using the
official Consul Democracy demo.

So we're adding buttons to simplify the process. Since some
installations might have only a couple of available languages, and in
this case these buttons would be pretty much useless, we're only showing
them when there are many languages available.
2024-06-06 16:28:19 +02:00

42 lines
1.6 KiB
Ruby

require "rails_helper"
describe Shared::CheckAllNoneComponent do
it "generates a data-field-name attribute when a field name is given" do
render_inline Shared::CheckAllNoneComponent.new("ids[]")
expect(page).to have_button count: 2
page.find("li:first-child") do |check_all|
expect(check_all).to have_button "Select all"
expect(check_all).to have_css "button[type='button'][data-field-name='ids[]'][data-check-all]"
expect(check_all).not_to have_css "[data-check-none]"
end
page.find("li:last-child") do |check_none|
expect(check_none).to have_button "Select none"
expect(check_none).to have_css "button[type='button'][data-field-name='ids[]'][data-check-none]"
expect(check_none).not_to have_css "[data-check-all]"
end
end
it "does not generate a data-field-name attribute when no field name is given" do
render_inline Shared::CheckAllNoneComponent.new
expect(page).to have_button count: 2
page.find("li:first-child") do |check_all|
expect(check_all).to have_button "Select all"
expect(check_all).to have_css "button[type='button'][data-check-all]"
expect(check_all).not_to have_css "[data-check-none]"
expect(check_all).not_to have_css "[data-field-name]"
end
page.find("li:last-child") do |check_none|
expect(check_none).to have_button "Select none"
expect(check_none).to have_css "button[type='button'][data-check-none]"
expect(check_none).not_to have_css "[data-check-all]"
expect(check_none).not_to have_css "[data-field-name]"
end
end
end