Class: GovukRSpecHelpers::ClickLink
- Inherits:
-
Object
- Object
- GovukRSpecHelpers::ClickLink
- Defined in:
- lib/click_govuk_link.rb
Constant Summary collapse
- VALID_LINK_CLASSES =
["govuk-link", "govuk-breadcrumbs__link", "govuk-back-link", "govuk-header__link", "govuk-footer__link", "govuk-notification-banner__link", "govuk-skip-link", "govuk-tabs__tab"]
- AMIBIGOUS_LINK_TEXTS =
["Change", "Add", "Remove"]
Instance Attribute Summary collapse
-
#link_text ⇒ Object
readonly
Returns the value of attribute link_text.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #click ⇒ Object
-
#initialize(page:, link_text:) ⇒ ClickLink
constructor
A new instance of ClickLink.
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
#link_text ⇒ Object (readonly)
Returns the value of attribute link_text.
4 5 6 |
# File 'lib/click_govuk_link.rb', line 4 def link_text @link_text end |
#page ⇒ Object (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
#click ⇒ Object
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_warns_if_opening_in_a_new_tab check_link_has_a_valid_class @link.click end |