Browse Source

DRY spec helpers

pull/109/head
baarkerlounger 4 years ago
parent
commit
13b08cf6c0
  1. 19
      spec/features/form/check_answers_page_spec.rb
  2. 18
      spec/features/form/helpers.rb
  3. 19
      spec/features/form/tasklist_page_spec.rb
  4. 8
      spec/features/form/validations_spec.rb

19
spec/features/form/check_answers_page_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
require_relative "helpers"
RSpec.describe "Form Check Answers Page" do
include Helpers
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let!(:empty_case_log) { FactoryBot.create(:case_log) }
let(:id) { case_log.id }
@ -12,23 +14,6 @@ RSpec.describe "Form Check Answers Page" do
let(:subsection) { "household_characteristics" }
let(:conditional_subsection) { "conditional_question" }
def fill_in_number_question(case_log_id, question, value, path)
visit("/case_logs/#{case_log_id}/#{path}")
fill_in("case-log-#{question.to_s.dasherize}-field", with: value)
click_button("Save and continue")
end
def answer_all_questions_in_income_subsection(case_log)
visit("/case_logs/#{case_log.id}/net_income")
fill_in("case-log-earnings-field", with: 18_000)
choose("case-log-incfreq-yearly-field")
click_button("Save and continue")
choose("case-log-benefits-all-field")
click_button("Save and continue")
choose("case-log-hb-prefer-not-to-say-field")
click_button("Save and continue")
end
context "when the user needs to check their answers for a subsection" do
it "can be visited by URL" do
visit("case_logs/#{id}/#{subsection}/check_answers")

18
spec/features/form/helpers.rb

@ -0,0 +1,18 @@
module Helpers
def fill_in_number_question(case_log_id, question, value, path)
visit("/case_logs/#{case_log_id}/#{path}")
fill_in("case-log-#{question.to_s.dasherize}-field", with: value)
click_button("Save and continue")
end
def answer_all_questions_in_income_subsection(case_log)
visit("/case_logs/#{case_log.id}/net_income")
fill_in("case-log-earnings-field", with: 18_000)
choose("case-log-incfreq-yearly-field")
click_button("Save and continue")
choose("case-log-benefits-all-field")
click_button("Save and continue")
choose("case-log-hb-prefer-not-to-say-field")
click_button("Save and continue")
end
end

19
spec/features/form/tasklist_page_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
require_relative "helpers"
RSpec.describe "Task List" do
include Helpers
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let!(:empty_case_log) { FactoryBot.create(:case_log) }
let(:id) { case_log.id }
@ -10,23 +12,6 @@ RSpec.describe "Task List" do
allow_any_instance_of(CaseLogsController).to receive(:authenticate_user!).and_return(true)
end
def fill_in_number_question(case_log_id, question, value, path)
visit("/case_logs/#{case_log_id}/#{path}")
fill_in("case-log-#{question.to_s.dasherize}-field", with: value)
click_button("Save and continue")
end
def answer_all_questions_in_income_subsection(case_log)
visit("/case_logs/#{case_log.id}/net_income")
fill_in("case-log-earnings-field", with: 18_000)
choose("case-log-incfreq-yearly-field")
click_button("Save and continue")
choose("case-log-benefits-all-field")
click_button("Save and continue")
choose("case-log-hb-prefer-not-to-say-field")
click_button("Save and continue")
end
it "displays a tasklist header" do
visit("/case_logs/#{id}")
expect(page).to have_content("Tasklist for log #{id}")

8
spec/features/form/validations_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
require_relative "helpers"
RSpec.describe "validations" do
include Helpers
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let!(:empty_case_log) { FactoryBot.create(:case_log) }
let(:id) { case_log.id }
@ -9,12 +11,6 @@ RSpec.describe "validations" do
allow_any_instance_of(CaseLogsController).to receive(:authenticate_user!).and_return(true)
end
def fill_in_number_question(case_log_id, question, value, path)
visit("/case_logs/#{case_log_id}/#{path}")
fill_in("case-log-#{question.to_s.dasherize}-field", with: value)
click_button("Save and continue")
end
describe "Question validation" do
context "given an invalid tenant age" do
it " of less than 0 it shows validation" do

Loading…
Cancel
Save