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) ⇒ 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
23
24
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/confirmation_helpers.rb', line 10

def accept_confirm(_text = nil)
  yield if block_given?

  # The test can already be "within", so find the body using xpath
  body = find(:xpath, "/html/body")
  confirm_selector = "[data-confirm-modal-content]"
  message = nil

  within body do
    message = find(confirm_selector).text
    find("[data-confirm-ok]").click
  end

  message
end

#accept_page_unload(text = nil, **options) ⇒ Object

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



50
51
52
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/confirmation_helpers.rb', line 50

def accept_page_unload(text = nil, **options, &)
  page.send(:accept_modal, :confirm, text, options, &)
end

#dismiss_confirm(_text = nil) ⇒ 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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/confirmation_helpers.rb', line 31

def dismiss_confirm(_text = nil)
  yield if block_given?

  # The test can already be "within", so find the body using xpath
  body = find(:xpath, "/html/body")
  confirm_selector = "[data-confirm-modal-content]"
  message = nil

  within body do
    message = find(confirm_selector).text
    find("[data-confirm-cancel]").click
  end

  message
end

#dismiss_page_unload(text = nil, **options) ⇒ Object

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



57
58
59
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/confirmation_helpers.rb', line 57

def dismiss_page_unload(text = nil, **options, &)
  page.send(:dismiss_modal, :confirm, text, options, &)
end