diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index aa6982ac2..6545b9a9c 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -31,6 +31,11 @@ class CaseLogsController < ApplicationController redirect_to(send("case_log_#{next_page}_path", @case_log)) end + def check_answers + @case_log = CaseLog.find(params[:case_log_id]) + render "form/check_answers", locals: { case_log_id: @case_log.id } + end + form = Form.new(2021, 2022) form.all_pages.map do |page_key, page_info| define_method(page_key) do diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb new file mode 100644 index 000000000..5f1310211 --- /dev/null +++ b/app/views/form/check_answers.html.erb @@ -0,0 +1,6 @@ +<%= turbo_frame_tag "case_log_form", target: "_top" do %> +

Check the answers you gave for household characteristics

+ <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= f.govuk_submit "Save and continue" %> + <% end %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 6443b9d35..99d2c48ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,10 +3,14 @@ Rails.application.routes.draw do get "about", to: "about#index" get "/", to: "test#index" + form = Form.new(2021, 2022) resources :case_logs do - Form.new(2021, 2022).all_pages.keys.map do |page| + form.all_pages.keys.map do |page| get page.to_s, to: "case_logs##{page}" post page.to_s, to: "case_logs#next_page" + form.all_subsections.keys.map do |subsection| + get "#{subsection}/check_answers", to: "case_logs#check_answers" + end end end end diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 41c92a3b3..48c6c33a5 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -15,12 +15,12 @@ FactoryBot.define do status { 0 } tenant_code { "AB123" } postcode { "LE11 2DW" } - tenant_age { 25 } + 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 + end created_at { Time.zone.now } updated_at { Time.zone.now } end diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 4efc07f8b..3c7ccd498 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -1,6 +1,7 @@ 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 } @@ -96,4 +97,22 @@ RSpec.describe "Test Features" do end end end + + 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 + + it "can be visited by URL" do + visit("case_logs/#{case_log.id}/#{subsection}/check_answers") + expect(page).to have_content("Check the answers you gave for #{subsection.tr('_', ' ')}") + end + end + end end