Skip to content

Commit

Permalink
Rename to fill_in_govuk_text_field
Browse files Browse the repository at this point in the history
  • Loading branch information
frankieroberto committed Sep 13, 2023
1 parent b132d7c commit b2bec9d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module GovukRSpecHelpers
class FillInGovUKField
class FillInGovUKTextField

attr_reader :page, :label, :hint, :with

Expand Down Expand Up @@ -135,8 +135,8 @@ def check_there_is_only_one_element_with_id(aria_described_by_id)

end

def fill_in_govuk_field(label, hint: nil, with:)
FillInGovUKField.new(page:, label:, hint:, with:).fill_in
def fill_in_govuk_text_field(label, hint: nil, with:)
FillInGovUKTextField.new(page:, label:, hint:, with:).fill_in
end

RSpec.configure do |rspec|
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk_rspec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
require_relative 'summarise_matcher'

require_relative 'click_govuk_link'
require_relative 'fill_in_govuk_field'
require_relative 'fill_in_govuk_text_field'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require "spec_helper"

RSpec.describe "fill_in_govuk_field", type: :feature do
RSpec.describe "fill_in_govuk_text_field", type: :feature do

context "where the input is correctly associated with a label" do
before do
Expand All @@ -18,31 +18,31 @@

context "and the full label is specified" do
it 'should be successful' do
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
expect(page.find_field("What is the name of the event?").value).to eql("Design System Day")
end
end

context "and a partial label is specified" do
it 'should raise an error' do
expect {
fill_in_govuk_field("What is the name", with: "Design System Day")
fill_in_govuk_text_field("What is the name", with: "Design System Day")
}.to raise_error('Unable to find label with the text "What is the name" but did find label with the text "What is the name of the event?" - use the full label text')
end
end

context "and the name of the input is used" do
it 'should raise an error' do
expect {
fill_in_govuk_field("eventName", with: "Design System Day")
fill_in_govuk_text_field("eventName", with: "Design System Day")
}.to raise_error('Use the full label text "What is the name of the event?" instead of the field name')
end
end

context "and a hint is is specified" do
it 'should raise an error' do
expect {
fill_in_govuk_field("What is the name of the event?", hint: "The name you’ll use on promotional material", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", hint: "The name you’ll use on promotional material", with: "Design System Day")
}.to raise_error('Found the field but could not find the hint "The name you’ll use on promotional material"')
end
end
Expand All @@ -63,7 +63,7 @@

it 'should raise an error' do
expect {
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
}.to raise_error('Found the label but it is missing a "for" attribute to associate it with an input')
end
end
Expand All @@ -83,7 +83,7 @@

it 'should raise an error' do
expect {
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
}.to raise_error('Found the label but it is missing a "for" attribute to associate it with an input')
end
end
Expand All @@ -103,7 +103,7 @@

it 'should raise an error' do
expect {
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
}.to raise_error('Found the label but there is no field with the ID "event-name" which matches the label‘s "for" attribute')
end
end
Expand All @@ -124,7 +124,7 @@

it 'should raise an error' do
expect {
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
}.to raise_error('Found the label but there there are 2 elements with the ID "event-name" which matches the label‘s "for" attribute')
end
end
Expand All @@ -144,7 +144,7 @@

it 'should raise an error' do
expect {
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
}.to raise_error('Found the label but but it is associated with a <div> element instead of a form field')
end
end
Expand All @@ -167,22 +167,22 @@

context "and the label is specified but the hint isn’t" do
it "should be successful" do
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
expect(page.find_field("What is the name of the event?").value).to eql("Design System Day")
end
end

context "and the label and the hint are specified" do
it "should be successful" do
fill_in_govuk_field("What is the name of the event?", hint: "The name you’ll use on promotional material", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", hint: "The name you’ll use on promotional material", with: "Design System Day")
expect(page.find_field("What is the name of the event?").value).to eql("Design System Day")
end
end

context "and a different hint is specified" do
it "should be raise an error" do
expect {
fill_in_govuk_field("What is the name of the event?", hint: "Make it a catchy name", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", hint: "Make it a catchy name", with: "Design System Day")
}.to raise_error('Found the label but the associated hint is "The name you’ll use on promotional material" not "Make it a catchy name"')
end
end
Expand All @@ -206,7 +206,7 @@

it "should raise an error" do
expect {
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
}.to raise_error('Found the field but it has an "aria-describedby=event-name-hint" attribute and no hint with that ID exists')
end
end
Expand All @@ -232,7 +232,7 @@

it "should raise an error" do
expect {
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
}.to raise_error('Found the field but it has an "aria-describedby=event-name-hint" attribute and 2 elements with that ID exist')
end
end
Expand All @@ -256,7 +256,7 @@
context "and the hint is specified" do
it "should raise an error" do
expect {
fill_in_govuk_field("What is the name of the event?", hint: "The name you’ll use on promotional material", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", hint: "The name you’ll use on promotional material", with: "Design System Day")
}.to raise_error('Found the field and the hint, but not field is not associated with the hint using aria-describedby')
end
end
Expand All @@ -283,14 +283,14 @@

context "and the just the label is specified" do
it 'should be successful' do
fill_in_govuk_field("What is the name of the event?", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", with: "Design System Day")
expect(page.find_field("What is the name of the event?").value).to eql("Design System Day")
end
end

context "and the the label and hint are specified" do
it 'should be successful' do
fill_in_govuk_field("What is the name of the event?", hint: "The name you’ll use on promotional material", with: "Design System Day")
fill_in_govuk_text_field("What is the name of the event?", hint: "The name you’ll use on promotional material", with: "Design System Day")
expect(page.find_field("What is the name of the event?").value).to eql("Design System Day")
end
end
Expand Down

0 comments on commit b2bec9d

Please sign in to comment.