Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support rack_test driver toggling details elements
  • Loading branch information
twalpole committed Aug 31, 2019
1 parent d0ca4bb commit 2cf317a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/capybara/rack_test/node.rb
Expand Up @@ -76,6 +76,8 @@ def click(keys = [], **options)
set(!checked?)
elsif tag_name == 'label'
click_label
elsif tag_name == 'details'
toggle_details
end
end

Expand Down Expand Up @@ -236,6 +238,14 @@ def click_label
labelled_control.set(!labelled_control.checked?) if checkbox_or_radio?(labelled_control)
end

def toggle_details
if native.has_attribute?('open')
native.remove_attribute('open')
else
native.set_attribute('open', 'open')
end
end

def link?
tag_name == 'a' && !self[:href].nil?
end
Expand Down
10 changes: 8 additions & 2 deletions lib/capybara/spec/session/node_spec.rb
Expand Up @@ -269,9 +269,15 @@
expect(descendants).to all(be_visible)
end

it 'sees opened details as visible', requires: [:js] do
it 'works when details is toggled open and closed' do
@session.find(:css, '#closed_details').click
expect(@session.all(:css, '#closed_details *')).to all(be_visible)
expect(@session).to have_css('#closed_details *', visible: true, count: 5)
.and(have_no_css('#closed_details *', visible: :hidden))

@session.find(:css, '#closed_details').click
descendants_css = '#closed_details > *:not(summary), #closed_details > *:not(summary) *'
expect(@session).to have_no_css(descendants_css, visible: true)
.and(have_css(descendants_css, visible: :hidden, count: 3))
end
end

Expand Down

0 comments on commit 2cf317a

Please sign in to comment.