Skip to content

Commit

Permalink
Fix disabled? for rack_test anchor tags and optimize link_or_button d…
Browse files Browse the repository at this point in the history
…isabled filter
  • Loading branch information
twalpole committed Apr 2, 2019
1 parent e39c65e commit f94033a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/capybara/node/simple.rb
Expand Up @@ -127,7 +127,8 @@ def checked?
#
# @return [Boolean] Whether the element is disabled
def disabled?
native.has_attribute?('disabled')
native.has_attribute?('disabled') &&
%w[button input select textarea optgroup option menuitem fieldset].include?(tag_name)
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/selector.rb
Expand Up @@ -176,7 +176,7 @@
end.reduce(:union)
end

node_filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| node.tag_name == 'a' || !(value ^ node.disabled?) }
node_filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| !(value ^ node.disabled?) }

describe_node_filters do |disabled: nil, **|
' that is disabled' if disabled == true
Expand Down
1 change: 1 addition & 0 deletions lib/capybara/selenium/node.rb
Expand Up @@ -147,6 +147,7 @@ def selected?; boolean_attr(native.selected?); end

def disabled?
return true unless native.enabled?

# WebDriver only defines `disabled?` for form controls but fieldset makes sense too
find_xpath('self::fieldset/ancestor-or-self::fieldset[@disabled]').any?
end
Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/spec/session/node_spec.rb
Expand Up @@ -137,7 +137,7 @@
expect(element.base).to have_received(:set).with('gorilla', clear: :backspace)
end

context 'with a contenteditable element', requires: [:js], focus_: true do
context 'with a contenteditable element', requires: [:js] do
it 'should allow me to change the contents' do
@session.visit('/with_js')
@session.find(:css, '#existing_content_editable').set('WYSIWYG')
Expand Down Expand Up @@ -167,7 +167,7 @@
end
end

describe '#disabled?', :focus_ do
describe '#disabled?' do
it 'should extract disabled node' do
@session.visit('/form')
expect(@session.find('//input[@id="customer_name"]')).to be_disabled
Expand Down
4 changes: 4 additions & 0 deletions spec/selector_spec.rb
Expand Up @@ -478,6 +478,10 @@
Capybara::Selector[:link_or_button].expression_filters.delete(:random)
end

it 'should not find links when disabled == true' do
expect(string.all(:link_or_button, disabled: true).size).to eq 0
end

context 'when modified' do
it 'should still work' do
filter = Capybara::Selector[:link_or_button].expression_filters[:random]
Expand Down

0 comments on commit f94033a

Please sign in to comment.