Browse Source

add check answers page with passing test

pull/25/head
MadeTech Dushan 3 years ago
parent
commit
a04a31105c
  1. 5
      app/controllers/case_logs_controller.rb
  2. 6
      app/views/form/check_answers.html.erb
  3. 6
      config/routes.rb
  4. 19
      spec/features/case_log_spec.rb

5
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

6
app/views/form/check_answers.html.erb

@ -0,0 +1,6 @@
<%= turbo_frame_tag "case_log_form", target: "_top" do %>
<h1 class="govuk-heading-l">Check the answers you gave for household characteristics</h1>
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>

6
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

19
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

Loading…
Cancel
Save