Module: ConfirmationHelpers

Defined in:
decidim-dev/lib/decidim/dev/test/rspec_support/confirmation_helpers.rb

Overview

Helpers that get automatically included in component specs.

Instance Method Summary collapse

Instance Method Details

#accept_confirm(_text = nil, **_options) ⇒ Object

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


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'decidim-dev/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) ⇒ Object

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


46
47
48
# File 'decidim-dev/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) ⇒ Object

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


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'decidim-dev/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) ⇒ Object

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


53
54
55
# File 'decidim-dev/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