require "rails_helper"
RSpec.describe GovukDesignSystem::SelectHelper, type: :helper do
describe "#govukSelect" do
it "returns the correct HTML for the default example" do
html = helper.govukSelect({
id: "sort",
name: "sort",
label: {
text: "Sort by"
},
items: [
{
value: "published",
text: "Recently published"
},
{
value: "updated",
text: "Recently updated",
selected: true
},
{
value: "views",
text: "Most views"
},
{
value: "comments",
text: "Most comments"
}
]
})
expect(html).to match_html(<<~HTML)
HTML
end
it "allows attributes to be passed" do
html = helper.govukSelect({
id: "sort",
name: "sort",
label: {
text: "Sort by"
},
items: [
{
value: "published",
text: "Recently published"
},
{
value: "updated",
text: "Recently updated",
selected: true
}
],
attributes: {
disabled: true,
data: { test: "testing" }
}
})
expect(html).to match_html(<<~HTML)
HTML
end
it "returns the correct HTML when the select element is an autocomplete element" do
html = helper.govukSelect({
id: "sort",
name: "sort",
label: {
text: "Sort by"
},
items: [
{
value: "published",
text: "Recently published"
},
{
value: "updated",
text: "Recently updated",
selected: true
},
{
value: "views",
text: "Most views"
},
{
value: "comments",
text: "Most comments"
}
],
is_autocomplete: true
})
expect(html).to match_html(<<~HTML)
HTML
end
end
end