-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fill and submit form feature test
- Loading branch information
Showing
2 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters