Module: DesignSystem::Govuk::TestHelpers::FormBuilderAssertionsHelper
- Included in:
- FormBuilderTestable
- Defined in:
- lib/design_system/govuk/test_helpers/form_builder_assertions_helper.rb
Overview
This module provides assertion methods for form elements using the GOV.UK Design System
Instance Method Summary collapse
-
#assert_file_upload(field = nil, type: nil, value: nil, classes: [], attributes: {}, model: 'assistant') ⇒ Object
Asserts the presence and attributes of a file upload input.
-
#assert_form_group(classes = []) ⇒ Object
Assert the presence of a form group.
-
#assert_hint(field = nil, value = nil, text = nil, classes: [], model: 'assistant') ⇒ Object
Asserts the presence and attributes of a hint.
-
#assert_input(field = nil, type: nil, value: nil, classes: [], attributes: {}, model: 'assistant') ⇒ Object
Asserts the presence and attributes of an input field.
-
#assert_label(field = nil, value = nil, text = nil, model: 'assistant', classes: []) ⇒ Object
Asserts the presence and attributes of a label TODO: support special labels like checkbox_label?.
-
#assert_text_area(field = nil, value: nil, classes: [], attributes: {}, model: 'assistant') ⇒ Object
Asserts the presence and attributes of a text area.
Instance Method Details
#assert_file_upload(field = nil, type: nil, value: nil, classes: [], attributes: {}, model: 'assistant') ⇒ Object
Asserts the presence and attributes of a file upload input
7 8 9 |
# File 'lib/design_system/govuk/test_helpers/form_builder_assertions_helper.rb', line 7 def assert_file_upload(field = nil, type: nil, value: nil, classes: [], attributes: {}, model: 'assistant') assert_form_element('input', 'file-upload', field, type:, value:, classes:, attributes:, model:) end |
#assert_form_group(classes = []) ⇒ Object
Assert the presence of a form group
12 13 14 15 16 17 18 |
# File 'lib/design_system/govuk/test_helpers/form_builder_assertions_helper.rb', line 12 def assert_form_group(classes = []) assert_select('form') do form_group = assert_select("div.#{@brand}-form-group#{classes.map { |c| ".#{c}" }.join}").first assert form_group, "Form group not found with classes: #{classes.join(', ')}" yield(form_group) if block_given? end end |
#assert_hint(field = nil, value = nil, text = nil, classes: [], model: 'assistant') ⇒ Object
Asserts the presence and attributes of a hint
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/design_system/govuk/test_helpers/form_builder_assertions_helper.rb', line 21 def assert_hint(field = nil, value = nil, text = nil, classes: [], model: 'assistant') base_class = "div.#{@brand}-hint" class_selector = base_class + classes.map { |c| ".#{c}" }.join selector = if value "#{class_selector}[id='#{model}_#{field}_#{value}_hint']" else "#{class_selector}[id='#{model}_#{field}_hint']" end assert_select(selector, text) end |
#assert_input(field = nil, type: nil, value: nil, classes: [], attributes: {}, model: 'assistant') ⇒ Object
Asserts the presence and attributes of an input field
35 36 37 |
# File 'lib/design_system/govuk/test_helpers/form_builder_assertions_helper.rb', line 35 def assert_input(field = nil, type: nil, value: nil, classes: [], attributes: {}, model: 'assistant') assert_form_element('input', 'input', field, type:, value:, classes:, attributes:, model:) end |
#assert_label(field = nil, value = nil, text = nil, model: 'assistant', classes: []) ⇒ Object
Asserts the presence and attributes of a label TODO: support special labels like checkbox_label?
41 42 43 44 45 46 47 48 49 |
# File 'lib/design_system/govuk/test_helpers/form_builder_assertions_helper.rb', line 41 def assert_label(field = nil, value = nil, text = nil, model: 'assistant', classes: []) selector = if value "label.#{@brand}-label[for='#{model}_#{field}_#{value}']" else "label.#{@brand}-label[for='#{model}_#{field}']" end selector << classes.map { |c| ".#{c}" }.join assert_select(selector, text) end |
#assert_text_area(field = nil, value: nil, classes: [], attributes: {}, model: 'assistant') ⇒ Object
Asserts the presence and attributes of a text area
52 53 54 |
# File 'lib/design_system/govuk/test_helpers/form_builder_assertions_helper.rb', line 52 def assert_text_area(field = nil, value: nil, classes: [], attributes: {}, model: 'assistant') assert_form_element('textarea', 'textarea', field, value:, classes:, attributes:, model:) end |