Hi,
I’ve build a filter in my application. Admin can select a category from a drop down select box and then only items (stakeholders) of that category are shown.
my markup looks like this:
<div class="filter">
<%= form_tag admin_stakeholders_path, method: "get", id: "filter", class: "filter" do %>
<%= label_tag "Field" %>
<%= select "stakeholder", "field", options_for_select(options_for_fields, selected: @selected), {prompt: 'All'}, onchange: "$('#filter').submit();" %>
<% end %>
</div>
I’ve written a spec for this:
describe "viewing the list of stakeholders" do
let!(:field1) { Field.create!(name: "beleidsmakers") }
let!(:field2) { Field.create!(name: "onderwijs") }
let!(:stakeholder1) { Stakeholder.create!(name: "stakeholder1", field_id: field1.id) }
let!(:stakeholder2) { Stakeholder.create!(name: "stakeholder2", field_id: field2.id) }
let!(:stakeholder3) { Stakeholder.create!(name: "stakeholder3", field_id: field1.id) }
before do
user = User.create!(user_attributes)
sign_in(user)
visit admin_stakeholders_path
end
...
it "shows the filtered stakeholders" do
select "beleidsmakers", from: "stakeholder_field"
expect(page).not_to have_text(stakeholder2.name)
end
However, for some reason Capybara doesn’t select the option ‘beleidsmakers’, instead the default option ‘all’ is selected.
Is this because the selection is triggered by Javascript?
onchange: "$('#filter').submit();
How can I solve this?
thanks for your help,
Anthony