Skip to content

Commit

Permalink
Support rack_test driver toggling details elements
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Aug 31, 2019
1 parent d0ca4bb commit bbe7984
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/capybara/rack_test/node.rb
Original file line number Diff line number Diff line change
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
6 changes: 5 additions & 1 deletion lib/capybara/spec/session/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,13 @@
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)

@session.find(:css, '#closed_details').click
descendants = @session.all(:css, '#closed_details > *:not(summary), #closed_details > *:not(summary) *', minimum: 2)
expect(descendants).not_to include(be_visible)
end
end

Expand Down

0 comments on commit bbe7984

Please sign in to comment.