module ConfirmationHelpers

Helpers that get automatically included in component specs.

Public Instance Methods

accept_confirm(_text = nil, **_options) { || ... } click to toggle source

Overrides the Capybara default accept_confirm because we have replaced the system's own confirmation modal with foundation based modal.

See: github.com/teamcapybara/capybara/blob/44621209496fe4dd352709799a0061a80d97d562/lib/capybara/session.rb#L647

# File lib/decidim/dev/test/rspec_support/confirmation_helpers.rb, line 10
def accept_confirm(_text = nil, **_options)
  yield if block_given?

  # The test can already be "within", so find the body using xpath
  message = nil
  body = find(:xpath, "/html/body")
  within(body.find(".confirm-reveal")) do
    message = find(".confirm-modal-content").text
    find("a.button[data-confirm-ok]").click
  end

  message
end
accept_page_unload(text = nil, **options, &blk) click to toggle source

Used to accept the “onbeforeunload” event's normal browser confirm modal as this cannot be overridden. Original confirm dismiss implementation in Capybara.

# File lib/decidim/dev/test/rspec_support/confirmation_helpers.rb, line 46
def accept_page_unload(text = nil, **options, &blk)
  page.send(:accept_modal, :confirm, text, options, &blk)
end
dismiss_confirm(_text = nil, **_options) { || ... } click to toggle source

Overrides the Capybara default dismiss_confirm because we have replaced the system's own confirmation modal with foundation based modal.

See: github.com/teamcapybara/capybara/blob/44621209496fe4dd352709799a0061a80d97d562/lib/capybara/session.rb#L657

# File lib/decidim/dev/test/rspec_support/confirmation_helpers.rb, line 29
def dismiss_confirm(_text = nil, **_options)
  yield if block_given?

  # The test can already be "within", so find the body using xpath
  message = nil
  body = find(:xpath, "/html/body")
  within(body.find(".confirm-reveal")) do
    message = find(".confirm-modal-content").text
    find("a.button[data-confirm-cancel]").click
  end

  message
end
dismiss_page_unload(text = nil, **options, &blk) click to toggle source

Used to dismiss the “onbeforeunload” event's normal browser confirm modal as this cannot be overridden. Original confirm dismiss implementation in Capybara.

# File lib/decidim/dev/test/rspec_support/confirmation_helpers.rb, line 53
def dismiss_page_unload(text = nil, **options, &blk)
  page.send(:dismiss_modal, :confirm, text, options, &blk)
end