- TomSelect.js manipulates the html structure of a select field to a degree that capybara select/find doesn't natively work.
- You need to create a TomSelectHelper method that instructs capybara specifically how to find and click on an option.
Last active
December 24, 2024 20:58
-
-
Save wrburgess/573bef94926fc731dce573a8cd89ca88 to your computer and use it in GitHub Desktop.
Using TomSelect.js and Capybara with Ruby on Rails and RSpect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/rails_helper.rb | |
RSpec.configure do |config| | |
config.include TomSelectHelper, type: :feature | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/support/tom_select_helper.rb | |
module TomSelectHelper | |
def fill_in_tom_select_field(input_selector:, text_value:) | |
# Find the TomSelect wrapper | |
wrapper = find("#{input_selector} + .ts-wrapper") | |
wrapper.click | |
# Wait for dropdown and select option | |
within('.ts-dropdown-content') do | |
find('.option', text: text_value, wait: 5, exact_text: true).click | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/features/widget_spec.rb | |
describe 'Admin Widget', type: :feature, js: true do | |
fill_in_tom_select_field_outset( | |
input_selector: '#widget_operation', | |
text_value: 'option name' | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment