Browse Source

Get a second passing test in place

Co-authored-by: Daniel Baark <baarkerlounger@users.noreply.github.com>
pull/25/head
MadeTech Dushan 3 years ago
parent
commit
ed9ce2e137
  1. 9
      app/controllers/case_logs_controller.rb
  2. 2
      app/models/form.rb
  3. 10
      spec/factories/case_log.rb
  4. 20
      spec/features/case_log_spec.rb

9
app/controllers/case_logs_controller.rb

@ -28,7 +28,14 @@ class CaseLogsController < ApplicationController
answers_for_page = page_params(questions_for_page).select { |k, _v| questions_for_page.include?(k) }
@case_log.update!(answers_for_page)
next_page = form.next_page(previous_page)
redirect_to(send("case_log_#{next_page}_path", @case_log))
redirect_path = if next_page == :check_answers
subsection = form.subsection_for_page(previous_page)
"case_log_#{subsection}_check_answers_path"
else
"case_log_#{next_page}_path"
end
redirect_to(send(redirect_path, @case_log))
end
def check_answers

2
app/models/form.rb

@ -50,7 +50,7 @@ class Form
def next_page(previous_page)
subsection = subsection_for_page(previous_page)
previous_page_idx = pages_for_subsection(subsection).keys.index(previous_page)
pages_for_subsection(subsection).keys[previous_page_idx + 1] || previous_page # Placeholder until we have a check answers page
pages_for_subsection(subsection).keys[previous_page_idx + 1] || :check_answers
end
def previous_page(current_page)

10
spec/factories/case_log.rb

@ -11,16 +11,6 @@ FactoryBot.define do
tenant_code { "BZ737" }
postcode { "NW1 7TY" }
end
trait :near_check_answers_household_characteristics do
status { 0 }
tenant_code { "AB123" }
postcode { "LE11 2DW" }
tenant_age { 25 }
tenant_gender { "Male" }
tenant_ethnic_group { "White: English/Scottish/Welsh/Northern Irish/British" }
tenant_nationality { "UK national resident in UK" }
tenant_economic_status { "Part-time - Less than 30 hours" }
end
created_at { Time.zone.now }
updated_at { Time.zone.now }
end

20
spec/features/case_log_spec.rb

@ -1,7 +1,6 @@
require "rails_helper"
RSpec.describe "Test Features" do
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let!(:check_answers_case_log) { FactoryBot.create(:case_log, :near_check_answers_household_characteristics) }
let(:id) { case_log.id }
let(:status) { case_log.status }
@ -101,18 +100,19 @@ RSpec.describe "Test Features" do
describe "check answers page" do
let(:subsection) { "household_characteristics" }
context "only one questions remains to be answered for the household characteristics section" do
# it "redirects to the check answers page when answering the last question and clicking save and continue" do
# visit("/case_logs/#{check_answers_case_log.id}/household_number_of_other_members")
# fill_in("household_number_of_other_members", with: 0)
# click_button("Save and continue")
# expect(page).to have_current_path("/case_logs/#{check_answers_case_log.id}/check-answers")
# end
context "when the user needs to check their answers for a subsection" do
it "can be visited by URL" do
visit("case_logs/#{case_log.id}/#{subsection}/check_answers")
visit("case_logs/#{id}/#{subsection}/check_answers")
expect(page).to have_content("Check the answers you gave for #{subsection.tr('_', ' ')}")
end
let(:last_question_for_subsection) { "household_number_of_other_members" }
it "redirects to the check answers page when answering the last question and clicking save and continue" do
visit("/case_logs/#{id}/#{last_question_for_subsection}")
fill_in(last_question_for_subsection, with: 0)
click_button("Save and continue")
expect(page).to have_current_path("/case_logs/#{id}/#{subsection}/check_answers")
end
end
end
end

Loading…
Cancel
Save