Class: GovukRSpecHelpers::ClickLink

Inherits:
Object
  • Object
show all
Defined in:
lib/click_govuk_link.rb

Constant Summary collapse

["govuk-link", "govuk-breadcrumbs__link", "govuk-back-link", "govuk-header__link", "govuk-footer__link", "govuk-notification-banner__link", "govuk-skip-link", "govuk-tabs__tab"]
["Change", "Add", "Remove"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page:, link_text:) ⇒ ClickLink

Returns a new instance of ClickLink.



10
11
12
13
# File 'lib/click_govuk_link.rb', line 10

def initialize(page:, link_text:)
  @page = page
  @link_text = link_text
end

Instance Attribute Details

Returns the value of attribute link_text.



4
5
6
# File 'lib/click_govuk_link.rb', line 4

def link_text
  @link_text
end

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/click_govuk_link.rb', line 4

def page
  @page
end

Instance Method Details

#clickObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/click_govuk_link.rb', line 15

def click
  @links = page.all('a', text: link_text, exact_text: true, normalize_ws: true)

  if @links.size == 0
    check_whether_there_is_an_inexact_match
    check_whether_there_is_an_href_match
    check_whether_there_is_an_id_match

    raise "Unable to find link \"#{link_text}\""
  end

  check_link_text_is_unique
  check_link_text_is_not_ambiguous

  @link = @links.first
  @link_classes = @link[:class].to_s.split(/\s/).collect(&:strip)

  check_link_is_not_styled_as_button
  check_link_warns_if_opening_in_a_new_tab
  check_link_does_not_contain_a_button
  check_link_has_a_valid_class

  @link.click
end