Skip to content

Commit

Permalink
Update isDeisplayed atom to support popover elements (#2759)
Browse files Browse the repository at this point in the history
* Update isDeisplayed atom to support popover elements

* Add another test case
  • Loading branch information
twalpole committed Apr 13, 2024
1 parent edc0397 commit 0f15ddd
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/capybara/selenium/atoms/isDisplayed.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/capybara/selenium/atoms/src/isDisplayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,16 @@
return false;
}

if (e.matches('*[popover]')) {
try {
if (e.matches('*:popover-open')) {
return true;
} else {
return false;
}
} catch (_e) {}
}

var parent = getParentNodeInComposedDom(e);

if ((typeof ShadowRoot === "function") && (parent instanceof ShadowRoot)) {
Expand Down
9 changes: 9 additions & 0 deletions lib/capybara/spec/session/click_button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,13 @@
end.to raise_error(Capybara::ElementNotFound)
end
end

it 'should work with popovers' do
@session.click_button('Show popover')
clickable = @session.find(:button, 'Should be clickable', visible: false)
expect(clickable).to be_visible
expect do
@session.click_button('Should be clickable')
end.not_to raise_error
end
end
3 changes: 2 additions & 1 deletion lib/capybara/spec/session/has_element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
it 'should be true if the given element is on the page' do
expect(@session).to have_element('a', id: 'foo')
expect(@session).to have_element('a', text: 'A link', href: '/with_simple_html')
expect(@session).to have_element('a', text: :'A link', href: :'/with_simple_html')
# Should `text` actually accept a symbol?
# expect(@session).to have_element('a', text: :'A link', href: :'/with_simple_html')
expect(@session).to have_element('a', text: 'A link', href: %r{/with_simple_html})
expect(@session).to have_element('a', text: 'labore', target: '_self')
end
Expand Down
16 changes: 16 additions & 0 deletions lib/capybara/spec/session/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@
descendants_css = '#closed_details > *:not(summary), #closed_details > *:not(summary) *'
expect(@session).to have_no_css(descendants_css, visible: :visible)
.and(have_css(descendants_css, visible: :hidden, count: 3))
sleep 20
end

it 'works with popover attribute' do
expect(@session.find(:button, 'Should not be clickable')).not_to be_visible
expect(@session.find(:button, 'Should be clickable')).not_to be_visible
@session.click_button('Show popover')
expect(@session.find(:button, 'Should be clickable')).to be_visible
expect(@session.find(:button, 'Should not be clickable')).not_to be_visible
end

it 'works with popover parents' do
expect(@session.find(:id, 'popover_parent')).not_to be_visible
expect(@session.find(:id, 'popover_child')).not_to be_visible
@session.click_button('Show parent popover')
expect(@session.find(:id, 'popover_child', text: 'Popover Contents')).to be_visible
end
end

Expand Down
6 changes: 6 additions & 0 deletions lib/capybara/spec/views/form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@ New line after and before textarea tag
<input id="special" {custom}="abcdef" value="custom attribute"/>
</p>

<p>
<div style="position: relative; overflow: hidden;">
<button popovertarget="show">Show popover</button>
<button popover id="show">Should be clickable</button>
</div>
</p>

<label for="multi_label_checkbox">
Label to click
Expand Down
20 changes: 20 additions & 0 deletions lib/capybara/spec/views/with_html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ banana</textarea>
</div>
</details>

<div>
<div style="position: relative; overflow: hidden;">
<button popovertarget="show">Show popover</button>
<button popover id="not_shown">Should not be clickable</button>
<button popover id="show">Should be clickable</button>
</div>
</div>

<div>
<div style="position: relative; overflow: hidden;">
<button popovertarget="popover_parent">Show parent popover</button>
<div popover id="popover_parent">
<div id="popover_child">
Popover Contents
</div>
</div>
</div>
</div>


<div style='height: 1000px'>spacer</div>

<template id="template">
Expand Down
2 changes: 2 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TestClass
pending "Rack < 2 doesn't support 308" if Gem.loaded_specs['rack'].version < Gem::Version.new('2.0.0')
when /#attach_file with multipart form should send prior hidden field if no file submitted/
skip 'Rack-test < 2 needs an empty file to detect multipart form' if Gem.loaded_specs['rack-test'].version < Gem::Version.new('2.0.0')
when /popover/
skip "Rack-test driver doesn't support popover functionality"
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/rack_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module TestSessions
skip "Rack < 2 doesn't support 308" if Gem.loaded_specs['rack'].version < Gem::Version.new('2.0.0')
when /#attach_file with multipart form should send prior hidden field if no file submitted/
skip 'Rack-test < 2 needs an empty file to detect multipart form' if Gem.loaded_specs['rack-test'].version < Gem::Version.new('2.0.0')
when /popover/
skip "Rack-test driver doesn't support popover functionality"
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/selenium_spec_firefox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ module TestSessions
skip 'Not supported with this geckodriver version' if geckodriver_lt?('0.31.0', @session)
when /Capybara::Session selenium node #set should submit single text input forms if ended with \\n/
pending 'Firefox/geckodriver doesn\'t submit with values ending in \n'
when /popover/
pending "Firefox doesn't currently support popover functionality"
end
end

Expand Down

0 comments on commit 0f15ddd

Please sign in to comment.