Skip to content

Commit

Permalink
Check input type is text
Browse files Browse the repository at this point in the history
  • Loading branch information
frankieroberto committed Sep 13, 2023
1 parent b2bec9d commit 7e01018
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/fill_in_govuk_text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def fill_in
@input = @inputs.first

check_associated_element_is_a_form_field
check_input_type_is_text

aria_described_by_ids = @input["aria-describedby"].to_s.strip.split(/\s+/)

Expand Down Expand Up @@ -103,6 +104,10 @@ def check_associated_element_is_a_form_field
end
end

def check_input_type_is_text
raise "Found the field, but it has type=\"#{@input[:type]}\", expected type=\"text\"" unless @input[:type] == "text"
end

def check_field_is_described_by_a_hint
if @described_by_elements.size == 0
check_if_the_hint_exists_but_is_not_associated_with_field
Expand Down
18 changes: 18 additions & 0 deletions spec/fill_in_govuk_text_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,23 @@
expect(page.find_field("What is the name of the event?").value).to eql("Design System Day")
end
end

context "where the input has type=email" do
before do
TestApp.body = '<form action="/success" method="post"><div class="govuk-form-group">
<label class="govuk-label" for="email">
Email address
</label>
<input class="govuk-input" id="email" name="email" type="email" spellcheck="false" autocomplete="email">
</div></form>'
visit('/')
end

it 'should raise an error' do
expect {
fill_in_govuk_text_field("Email address", with: "[email protected]")
}.to raise_error('Found the field, but it has type="email", expected type="text"')
end
end
end
end

0 comments on commit 7e01018

Please sign in to comment.