1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Merge pull request #2482 from teamcapybara/allow_label_click_hash

Allow label click hash
This commit is contained in:
Thomas Walpole 2021-07-26 07:57:35 -07:00 committed by GitHub
commit f2113294de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 5 deletions

View file

@ -5,13 +5,18 @@ Release date: unreleased
* Ruby 2.6.0+ is now required
### Added
* `allow_label_click` accepts click options to be used when clicking an associated label
### Fixed
* Sibling and ancestor queries now work with Simple::Node - Issue #2452
* rack_test correctly ignores readonly attribute on specific input element types
* Node#all_text always returns a string - Issue #2477
* have_any_of_selectors negated match - Issue #2473
* Document#scroll_to - pass quirks: true if you need the older behavior [Eric Anderson]
* `Node#all_text` always returns a string - Issue #2477
* `have_any_of_selectors` negated match - Issue #2473
* `Document#scroll_to` fixed for standards behavior - pass quirks: true if you need the older behavior [Eric Anderson]
### Removed

View file

@ -92,8 +92,9 @@ module Capybara
end
# @!macro label_click
# @option options [Boolean] allow_label_click
# @option options [Boolean, Hash] allow_label_click
# Attempt to click the label to toggle state if element is non-visible. Defaults to {Capybara.configure automatic_label_click}.
# If set to a Hash it is passed as options to the `click` on the label
##
#
@ -371,7 +372,11 @@ module Capybara
begin
el ||= find(selector, locator, **options.merge(visible: :all))
el.session.find(:label, for: el, visible: true, match: :first).click unless el.checked? == checked
unless el.checked? == checked
el.session
.find(:label, for: el, visible: true, match: :first)
.click(**(Hash.try_convert(allow_label_click) || {}))
end
rescue StandardError # swallow extra errors - raise original
raise e
end

View file

@ -236,6 +236,15 @@ Capybara::SpecHelper.spec '#check' do
expect(@session).to have_field('multi_label_checkbox', checked: true, visible: :hidden)
end
end
context 'with allow_label_click options', requires: [:js] do
it 'should allow offsets to click location on label' do
expect(@session.find(:checkbox, 'form_cars_lotus', unchecked: true, visible: :hidden)).to be_truthy
@session.check('form_cars_lotus', allow_label_click: { x: 90, y: 10 })
@session.click_button('awesome')
expect(extract_results(@session)['cars']).to include('lotus')
end
end
end
end
end

View file

@ -223,6 +223,8 @@ New line after and before textarea tag
</label>
<input type="checkbox" value="maserati" name="form[cars][]" id="form_cars_maserati" disabled="disabled"/>
<label for="form_cars_maserati">Maserati</label>
<input type="checkbox" value="lotus" name="form[cars][]" id="form_cars_lotus" style="display: none"/>
<label for="form_cars_lotus"><a href="#" onclick="return false;">Link here</a>Lotus</label>
</p>
<p>