Module: Capybara::ReactSelect

Defined in:
lib/decidim/dev/test/rspec_support/react_select.rb

Instance Method Summary collapse

Instance Method Details

#autocomplete_select(value, from:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/decidim/dev/test/rspec_support/react_select.rb', line 7

def autocomplete_select(value, from:)
  within("div[data-autocomplete-for='#{from}']") do
    find(".Select-control").click

    find(".Select .Select-input input").native.send_keys(value[0..4])
    expect(page).to have_css(".Select-menu-outer") # select should be open now

    # This is a little funky because when the entered text forces the select to
    # wrap, it causes React to re-render.  We need to get it to re-render
    # (if needed) by hovering.
    expect(page).to have_css(".Select-option", text: value)
    find(".Select-option", text: value).hover
    expect(page).to have_css(".Select-option", text: value)
    find(".Select-option", text: value).click
    expect(page).to have_css(".Select-value-label", text: value)
  end
end