Skip to content

Commit

Permalink
Add fill and submit form feature test
Browse files Browse the repository at this point in the history
  • Loading branch information
SamJamCul committed Dec 1, 2023
1 parent 2d93f32 commit 586c757
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
79 changes: 79 additions & 0 deletions spec/features/fill_in_and_submit_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
require "rails_helper"

feature "Fill in and submit a form", type: :feature, feature_email_confirmations_enabled: true do
let(:pages) { [(build :page, :with_text_settings, id: 1, form_id: 1, routing_conditions: [])] }
let(:form) { build :form, :live, id: 1, name: "Fill in this form", pages:, start_page: 1 }
let(:question_text) { pages[0].question_text }
let(:answer_text) { "Answer text" }

let(:req_headers) do
{
"X-API-Token" => Settings.forms_api.auth_key,
"Accept" => "application/json",
}
end

let(:post_headers) do
{
"X-API-Token" => Settings.forms_api.auth_key,
"Content-Type" => "application/json",
}
end

before do
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/api/v1/forms/1", req_headers, form.to_json, 200
mock.get "/api/v1/forms/1/live", req_headers, form.to_json(include: [:pages]), 200
end
end

scenario "As a form filler" do
when_i_visit_the_form_start_page
then_i_should_see_the_first_question

when_i_fill_in_the_question
and_i_click_on_continue
then_i_should_see_the_check_your_answers_page

when_i_opt_out_of_email_confirmation
and_i_submit_my_form
then_my_form_should_be_submitted
end

def when_i_visit_the_form_start_page
visit form_path(mode: "form", form_id: 1, form_slug: "fill-in-this-form")
expect_page_to_have_no_axe_errors(page)
end

def then_i_should_see_the_first_question
expect(page.find("h1")).to have_text question_text
end

def when_i_fill_in_the_question
fill_in question_text, with: answer_text
end

def and_i_click_on_continue
click_button "Continue"
end

def then_i_should_see_the_check_your_answers_page
expect(page.find("h1")).to have_text "Check your answers before submitting your form"
expect(page).to have_text question_text
expect(page).to have_text answer_text
expect_page_to_have_no_axe_errors(page)
end

def when_i_opt_out_of_email_confirmation
choose "No"
end

def and_i_submit_my_form
click_on "Submit"
end

def then_my_form_should_be_submitted
expect(page.find("h1")).to have_text "Your form has been submitted"
expect_page_to_have_no_axe_errors(page)
end
end
8 changes: 6 additions & 2 deletions spec/support/axe_feature_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module AxeFeatureHelpers
ARIA_ALLOWED_ATTR = "aria-allowed-attr".freeze

def expect_page_to_have_no_axe_errors(page)
expect(page).to be_axe_clean.according_to(:wcag2a, :wcag2aa, :wcag21a, :wcag21aa)
expect(page).to be_axe_clean.according_to(:wcag2a, :wcag2aa, :wcag21a, :wcag21aa).skipping ARIA_ALLOWED_ATTR
expect(page).to be_axe_clean.excluding(".govuk-radios__input").checking_only ARIA_ALLOWED_ATTR
end

def expect_component_to_have_no_axe_errors(page)
expect(page).to be_axe_clean.within("#main-content").according_to(:wcag2a, :wcag2aa, :wcag21a, :wcag21aa)
expect(page).to be_axe_clean.within("#main-content").according_to(:wcag2a, :wcag2aa, :wcag21a, :wcag21aa).skipping ARIA_ALLOWED_ATTR
expect(page).to be_axe_clean.within("#main-content").excluding(".govuk-radios__input").checking_only ARIA_ALLOWED_ATTR
end
end

Expand Down

0 comments on commit 586c757

Please sign in to comment.