-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathemail_confirmation_spec.rb
More file actions
46 lines (39 loc) · 1.86 KB
/
email_confirmation_spec.rb
File metadata and controls
46 lines (39 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require "rails_helper"
feature "Email confirmation", type: :feature do
let(:steps) { [build(:v2_question_page_step, :with_text_settings, id: 1, routing_conditions: [], question_text:)] }
let(:form) { build :v2_form_document, :live?, form_id: 1, name: "Apply for a juggling license", steps:, start_page: 1 }
let(:question_text) { Faker::Lorem.question }
let(:text_answer) { Faker::Lorem.sentence }
let(:req_headers) { { "Accept" => "application/json" } }
let(:post_headers) { { "Content-Type" => "application/json" } }
before do
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/api/v2/forms/1/live", req_headers, form.to_json, 200
end
end
scenario "opting out of email submission returns the confirmation page without confirmation email text" do
fill_in_form
choose "No", visible: false
click_button "Submit"
expect(page.find("h1")).to have_text I18n.t("form.submitted.title")
expect(page).not_to have_text I18n.t("form.submitted.email_sent")
end
scenario "opting in to email submission returns the confirmation page with confirmation email text" do
fill_in_form
choose "Yes", visible: false
fill_in "What email address do you want us to send your confirmation to?", with: "example@example.gov.uk"
click_button "Submit"
expect(page.find("h1")).to have_text I18n.t("form.submitted.title")
expect(page).to have_text I18n.t("form.submitted.email_sent")
end
def fill_in_form
visit form_path(mode: "form", form_id: 1, form_slug: "apply-for-a-juggling-licence")
expect(page.find("h1")).to have_text question_text
expect_page_to_have_no_axe_errors(page)
fill_in question_text, with: text_answer
click_button "Continue"
expect(page.find("h1")).to have_text I18n.t("form.check_your_answers.title")
expect(page).to have_text question_text
expect(page).to have_text text_answer
end
end