require "rails_helper"
RSpec.describe GovukDesignSystem::CheckboxesHelper, type: :helper do
describe "#govukCheckboxes" do
it "returns the correct HTML for the default example" do
html = helper.govukCheckboxes({
idPrefix: "waste",
name: "waste",
fieldset: {
legend: {
text: "Which types of waste do you transport?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "Select all that apply."
},
items: [
{
value: "carcasses",
text: "Waste from animal carcasses",
disable_ghost: true
},
{
value: "mines",
text: "Waste from mines or quarries",
disable_ghost: true
},
{
value: "farm",
text: "Farm or agricultural waste",
disable_ghost: true
}
]
})
expect(html).to match_html(<<~HTML)
HTML
end
it "adds ghost inputs by default as required by Rails" do
# NOTE: https://github.com/govuk-ruby/govuk-design-system-rails/blob/master/README.md#component-implementations
html = helper.govukCheckboxes({
idPrefix: "waste",
name: "waste",
fieldset: {
legend: {
text: "Which types of waste do you transport?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "Select all that apply."
},
items: [
{
value: "carcasses",
text: "Waste from animal carcasses",
},
{
value: "mines",
text: "Waste from mines or quarries",
},
{
value: "farm",
text: "Farm or agricultural waste",
}
]
})
expect(html).to match_html(<<~HTML)
HTML
end
it "returns the correct HTML when there is a fieldset css class" do
html = helper.govukCheckboxes({
idPrefix: "waste",
name: "waste",
fieldset: {
legend: {
text: "Which types of waste do you transport?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
},
classes: "js-mutually-exclusive"
},
hint: {
text: "Select all that apply."
},
items: [
{
value: "carcasses",
text: "Waste from animal carcasses",
disable_ghost: true
},
{
value: "mines",
text: "Waste from mines or quarries",
disable_ghost: true
},
{
value: "farm",
text: "Farm or agricultural waste",
disable_ghost: true
}
]
})
expect(html).to match_html(<<~HTML)
HTML
end
end
end