Browse Source

Merge pull request #25 from communitiesuk/CLDC-277-create-check-answer-view

CLDC-277: create check answer view
pull/33/head
Dushan 3 years ago committed by GitHub
parent
commit
3d86dbd24f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      app/controllers/case_logs_controller.rb
  2. 39
      app/helpers/check_answers_helper.rb
  3. 2
      app/models/form.rb
  4. 13
      app/views/form/_check_answers_table.html.erb
  5. 2
      app/views/form/_checkbox_question.html.erb
  6. 2
      app/views/form/_radio_question.html.erb
  7. 16
      app/views/form/check_answers.html.erb
  8. 46
      config/forms/2021_2022.json
  9. 6
      config/routes.rb
  10. 23
      doc/adr/adr-006-saving-values.md
  11. 99
      spec/features/case_log_spec.rb
  12. 28
      spec/helpers/check_answers_helper_spec.rb

18
app/controllers/case_logs_controller.rb

@ -28,7 +28,23 @@ 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
@case_log = CaseLog.find(params[:case_log_id])
form = Form.new(2021, 2022)
current_url = request.env["PATH_INFO"]
subsection = current_url.split("/")[-2]
subsection_pages = form.pages_for_subsection(subsection)
render "form/check_answers", locals: { case_log: @case_log, subsection_pages: subsection_pages, subsection: subsection.humanize(capitalize: false) }
end
form = Form.new(2021, 2022)

39
app/helpers/check_answers_helper.rb

@ -0,0 +1,39 @@
module CheckAnswersHelper
def get_answered_questions_total(subsection_pages, case_log)
questions = subsection_pages.values.flat_map do |page|
page["questions"].keys
end
questions.count { |question| case_log[question].present? }
end
def get_total_number_of_questions(subsection_pages)
questions = subsection_pages.values.flat_map do |page|
page["questions"].keys
end
questions.count
end
def create_update_answer_link(case_log_answer, case_log_id, page)
link_name = case_log_answer.blank? ? "Answer" : "Change"
link_to(link_name, "/case_logs/#{case_log_id}/#{page}", class: "govuk-link").html_safe
end
def create_next_missing_question_link(case_log_id, subsection_pages, case_log)
pages_to_fill_in = []
subsection_pages.each do |page_title, page_info|
page_info["questions"].any? { |question| case_log[question].blank? }
pages_to_fill_in << page_title
end
url = "/case_logs/#{case_log_id}/#{pages_to_fill_in.first}"
link_to("Answer the missing questions", url, class: "govuk-link").html_safe
end
def display_answered_questions_summary(subsection_pages, case_log)
if get_answered_questions_total(subsection_pages, case_log) == get_total_number_of_questions(subsection_pages)
'<p class="govuk-body govuk-!-margin-bottom-7">You answered all the questions</p>'.html_safe
else
"<p class=\"govuk-body govuk-!-margin-bottom-7\">You answered #{get_answered_questions_total(subsection_pages, case_log)} of #{get_total_number_of_questions(subsection_pages)} questions</p>
#{create_next_missing_question_link(case_log['id'], subsection_pages, case_log)}".html_safe
end
end
end

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)

13
app/views/form/_check_answers_table.html.erb

@ -0,0 +1,13 @@
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= question_info["check_answer_label"].to_s %>
<dt>
<dd class="govuk-summary-list__value">
<%= case_log[question_title] %>
</dd>
<dd class="govuk-summary-list__actions">
<%= create_update_answer_link(case_log[question_title], case_log["id"], page)%>
</dd>
</div>
</dl>

2
app/views/form/_checkbox_question.html.erb

@ -6,7 +6,7 @@
<% if key.starts_with?("divider") %>
<%= f.govuk_check_box_divider %>
<% else %>
<%= f.govuk_check_box question_key, key, label: { text: val } %>
<%= f.govuk_check_box question_key, val, label: { text: val } %>
<% end %>
<% end %>
<% end %>

2
app/views/form/_radio_question.html.erb

@ -7,7 +7,7 @@
<% if key.starts_with?("divider") %>
<%= f.govuk_radio_divider %>
<% else %>
<%= f.govuk_radio_button question_key, key, label: { text: val } %>
<%= f.govuk_radio_button question_key, val, label: { text: val } %>
<% end %>
<% end %>
<% end %>

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

@ -0,0 +1,16 @@
<%= turbo_frame_tag "case_log_form", target: "_top" do %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-l">Check the answers you gave for <%= subsection %></h1>
<%= display_answered_questions_summary(subsection_pages, case_log) %>
<% subsection_pages.each do |page, page_info| %>
<% page_info["questions"].each do |question_title, question_info| %>
<%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: case_log, page: page } %>
<%end %>
<% end %>
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

46
config/forms/2021_2022.json

@ -14,6 +14,7 @@
"description": "",
"questions":{
"tenant_code": {
"check_answer_label": "Tenant code",
"header": "What is the tenant code?",
"hint_text": "",
"type": "text"
@ -25,6 +26,7 @@
"description": "",
"questions":{
"tenant_age": {
"check_answer_label": "Tenant's age",
"header": "What is the tenant's age?",
"hint_text": "",
"type": "numeric",
@ -39,6 +41,7 @@
"description": "",
"questions":{
"tenant_gender": {
"check_answer_label": "Tenant's gender",
"header": "Which of these best describes the tenant's gender identity?",
"hint_text": "",
"type": "radio",
@ -56,6 +59,7 @@
"description": "",
"questions":{
"tenant_ethnic_group": {
"check_answer_label": "Ethnicity",
"header": "What is the tenant's ethnic group?",
"hint_text": "",
"type": "radio",
@ -88,6 +92,7 @@
"description": "",
"questions":{
"tenant_nationality": {
"check_answer_label": "Nationality",
"header": "What is the tenant's nationality?",
"hint_text": "",
"type": "radio",
@ -117,6 +122,7 @@
"description": "",
"questions":{
"tenant_economic_status": {
"check_answer_label": "Work",
"header": "Which of these best describes the tenant's working situation?",
"hint_text": "",
"type": "radio",
@ -141,6 +147,7 @@
"description": "",
"questions":{
"household_number_of_other_members": {
"check_answer_label": "Number of Other Household Members",
"header": "How many other people are there in the household?",
"hint_text": "The maximum number of others is 7",
"type": "numeric",
@ -416,6 +423,7 @@
"description": "",
"questions":{
"tenancy_code": {
"check_answer_label": "What is the tenancy code?",
"header": "What is the tenancy code?",
"hint_text": "",
"type": "text"
@ -427,6 +435,7 @@
"description": "",
"questions": {
"tenancy_start_date": {
"check_answer_label": "When is the tenancy start date?",
"header": "What is the tenancy start date?",
"hint_text": "For example, 27 3 2007",
"type": "date"
@ -438,6 +447,7 @@
"description": "",
"questions": {
"starter_tenancy": {
"check_answer_label": "Is this a starter or introductory tenancy?",
"header": "Is this a starter tenancy?",
"hint_text": "",
"type": "radio",
@ -453,6 +463,7 @@
"description": "",
"questions":{
"fixed_term_tenancy": {
"check_answer_label": "If the main tenancy is a fixed term tenancy, please provide the length of the fixed term (to the nearest year) excluding any starter/introductory period",
"header": "If fixed-term, what is the length of the fixed-term tenancy after any starter period?",
"hint_text": "To the nearest year",
"type": "numeric",
@ -467,6 +478,7 @@
"description": "",
"questions": {
"tenancy_type": {
"check_answer_label": "Type of main tenancy (after any starter/introductory period)",
"header": "What is the type of tenancy after the starter period has ended?",
"hint_text": "",
"type": "radio",
@ -486,6 +498,7 @@
"description": "",
"questions": {
"letting_type": {
"check_answer_label": "Type of letting",
"header": "Which type of letting is this?",
"hint_text": "",
"type": "radio",
@ -505,6 +518,7 @@
"description": "",
"questions": {
"letting_provider": {
"check_answer_label": "Provider",
"header": "Who is the letting provider?",
"hint_text": "",
"type": "radio",
@ -525,6 +539,7 @@
"description": "",
"questions":{
"property_location": {
"check_answer_label": "Property Location",
"header": "Property location",
"hint_text": "",
"type": "radio",
@ -851,6 +866,7 @@
"description": "",
"questions":{
"property_postcode": {
"check_answer_label": "What was the previous postcode?",
"header": "What is the property's postcode?",
"hint_text": "",
"type": "text"
@ -862,6 +878,7 @@
"description": "",
"questions": {
"property_relet": {
"check_answer_label": "Which type was the property most recently let as?",
"header": "Is this property a relet?",
"hint_text": "",
"type": "radio",
@ -877,6 +894,7 @@
"description": "",
"questions": {
"property_vacancy_reason": {
"check_answer_label": "What is the reason for the property vacancy?",
"header": "What is the reason for the property vacancy?",
"hint_text": "",
"type": "radio",
@ -904,6 +922,7 @@
"description": "",
"questions":{
"property_reference": {
"check_answer_label": "What’s the property reference?",
"header": "What's the property reference?",
"hint_text": "",
"type": "text"
@ -915,6 +934,7 @@
"description": "",
"questions": {
"property_unit_type": {
"check_answer_label": "Which type of unit is the property?",
"header": "Which type of unit is the property?",
"hint_text": "",
"type": "radio",
@ -936,6 +956,7 @@
"description": "",
"questions":{
"property_number_of_bedrooms": {
"check_answer_label": "How many bedrooms are there in the property?",
"header": "How many bedrooms are there in the property?",
"hint_text": "If shared accommodation, enter number of bedrooms occupied by this household; a bed-sit has 1 bedroom",
"type": "numeric",
@ -950,6 +971,7 @@
"description": "",
"questions": {
"property_major_repairs": {
"check_answer_label": "Were major repairs carried out during the void period?",
"header": "Were any major repairs completed during the void period?",
"hint_text": "",
"type": "radio",
@ -965,6 +987,7 @@
"description": "",
"questions": {
"property_major_repairs": {
"check_answer_label": "What was the major repairs completion date?",
"header": "What was the major repairs completion date?",
"hint_text": "For example, 27 3 2007",
"type": "date"
@ -976,6 +999,7 @@
"description": "",
"questions":{
"property_number_of_times_relet": {
"check_answer_label": "How many times has this unit been previously offered since becoming available for relet since the last tenancy ended or as a first let?",
"header": "How many times has this unit been previously offered since becoming available for relet since the last tenancy ended or as a first let? ",
"hint_text": "For an Affordable Rent or Intermediate Rent Letting, only include number of offers as that type. For a property let at the first attempt enter '0' ",
"type": "numeric",
@ -990,6 +1014,7 @@
"description": "",
"questions": {
"property_wheelchair_accessible": {
"check_answer_label": "Is property built or adapted to wheelchair user standards?",
"header": "Is property built or adapted to wheelchair user standards?",
"hint_text": "",
"type": "radio",
@ -1015,6 +1040,7 @@
"description": "",
"questions":{
"net_income": {
"check_answer_label": "Income",
"header": "What is the tenant’s /and partner’s combined income after tax?",
"hint_text": "",
"type": "numeric",
@ -1022,6 +1048,7 @@
"step": "1"
},
"net_income_frequency": {
"check_answer_label": "Income Frequency",
"header": "How often do they receive this income?",
"hint_text": "",
"type": "radio",
@ -1038,6 +1065,7 @@
"description": "",
"questions":{
"net_income_uc_proportion": {
"check_answer_label": "Benefits as a proportion of income",
"header": "How much of the tenant’s income is from Universal Credit, state pensions or benefits?",
"hint_text": "",
"type": "radio",
@ -1055,6 +1083,7 @@
"description": "",
"questions":{
"housing_benefit": {
"check_answer_label": "Universal Credit & Housing Benefit\t",
"header": "Is the tenant likely to be in receipt of any of these housing-related benefits?",
"hint_text": "",
"type": "radio",
@ -1080,6 +1109,7 @@
"description": "",
"questions":{
"rent_frequency": {
"check_answer_label": "Rent Period",
"header": "Which period are rent and other charges due?",
"hint_text": "",
"type": "radio",
@ -1097,6 +1127,7 @@
}
},
"basic_rent": {
"check_answer_label": "Basic Rent",
"header": "What is the basic rent?",
"hint_text": "Eligible for housing benefit or Universal Credit",
"type": "numeric",
@ -1104,6 +1135,7 @@
"step": 1
},
"service_charge": {
"check_answer_label": "Service Charge",
"header": "What is the service charge?",
"hint_text": "Eligible for housing benefit or Universal Credit",
"type": "numeric",
@ -1111,6 +1143,7 @@
"step": 1
},
"personal_service_charge": {
"check_answer_label": "Personal Service Charge",
"header": "What is the personal service charge?",
"hint_text": "Not eligible for housing benefit or Universal Credit. For example, hot water excluding water rates.",
"type": "numeric",
@ -1118,6 +1151,7 @@
"step": 1
},
"support_charge": {
"check_answer_label": "Support Charge",
"header": "What is the support charge?",
"hint_text": "This is to fund housing-related support services included in the tenancy agreement",
"type": "numeric",
@ -1125,6 +1159,7 @@
"step": 1
},
"total_charge": {
"check_answer_label": "Total Charge",
"header": "Total charge?",
"hint_text": "This is the total of rent and all charges",
"type": "numeric",
@ -1132,6 +1167,7 @@
"step": 1
},
"outstanding_amount": {
"check_answer_label": "After housing benefit and/or housing element of UC payment is received, will there be an outstanding amount for basic rent and/or benefit eligible charges?",
"header": "After housing benefit and/or housing element of UC payment is received, will there be an outstanding amount for basic rent and/or benefit eligible charges?",
"hint_text": "",
"type": "radio",
@ -1157,6 +1193,7 @@
"description": "",
"questions":{
"time_lived_in_la": {
"check_answer_label": "How long has the household continuously lived in the local authority area where the new letting is located?",
"header": "How long has the household continuously lived in the local authority area where the new letting is located?",
"hint_text": "",
"type": "radio",
@ -1178,6 +1215,7 @@
"description": "",
"questions":{
"time_on_la_waiting_list": {
"check_answer_label": "How long has the household been on the local authority waiting list where the new letting is located?",
"header": "How long has the household been on the local authority waiting list where the new letting is located?",
"hint_text": "",
"type": "radio",
@ -1199,6 +1237,7 @@
"description": "",
"questions":{
"previous_la": {
"check_answer_label": "The LA in which household lived immediately before this letting\t",
"header": "Which local authority area did the household live in immediately before this letting?",
"hint_text": "Includes temporary accommodation",
"type": "radio",
@ -1525,6 +1564,7 @@
"description": "",
"questions": {
"previous_postcode": {
"check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation",
"header": "Postcode for the previous accommodation",
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",
"type": "text"
@ -1536,6 +1576,7 @@
"description": "",
"questions": {
"reasonable_preference": {
"check_answer_label": "Was the household given Reasonable Preference (i.e. priority) for housing by the Local Authority?",
"header": "Was the household given reasonable preference by the local authority?",
"hint_text": "",
"type": "radio",
@ -1545,6 +1586,7 @@
}
},
"reasonable_preference_reason": {
"check_answer_label": "Reason for reasonable preference",
"header": "Why were they given reasonable preference?",
"hint_text": "Select all that apply",
"type": "checkbox",
@ -1564,6 +1606,7 @@
"description": "",
"questions": {
"cbl_letting": {
"check_answer_label": "Choice-based letting?",
"header": "Was the letting made under choice-based lettings (CBL)? ",
"hint_text": "",
"type": "radio",
@ -1573,6 +1616,7 @@
}
},
"chr_letting": {
"check_answer_label": "Common housing register letting?",
"header": "Was the letting made under common housing register (CHR)? ",
"hint_text": "",
"type": "radio",
@ -1582,6 +1626,7 @@
}
},
"cap_letting": {
"check_answer_label": "Common allocation policy letting?",
"header": "Was the letting made under common allocation policy (CAP)? ",
"hint_text": "",
"type": "radio",
@ -1607,6 +1652,7 @@
"description": "",
"questions":{
"declaration": {
"check_answer_label": "",
"header": "What is the tenant code?",
"hint_text": "",
"type": "text"

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

23
doc/adr/adr-006-saving-values.md

@ -0,0 +1,23 @@
### ADR - 006: Saving values to the database
We have opted to save values to the database directly instead of saving keys/numbers that need to be converted with enums in models using active record.
### Saving values to the database
There are a few reasons we have opted to save the values directly, they are as follows
- The data will be easier to consume and analyse for anyone associated with the project who needs to do so but does not necessarily have the technical skills to access it through Rails i.e. A person could get the data directly from the database and it would require no additional work to be usable for reporting purposes
- Currently there is no need to abstract the data as the data should be safe from being accessed by anyone external to the project
- It doesn't require additional dev work to map keys/numbers to values, we can just pull the values out directly and use them in the code, for example on the check answers page
### Drawbacks
- Changing the wording/casing of the answers could result in discrepancies in the database
- There is a small risk that if the database is accessed by someone unauthorised they would have access to personally identifiable information if we were to collect Any. We will be mitigating this risk by encrypting the production database
This decision is not too difficult to change and can be revisited in the future if there is sufficient reason to switch to storing keys/numbers and using enums and active record to convert those to the appropriate values.

99
spec/features/case_log_spec.rb

@ -1,16 +1,17 @@
require "rails_helper"
RSpec.describe "Test Features" do
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let!(:empty_case_log) { FactoryBot.create(:case_log) }
let(:id) { case_log.id }
let(:status) { case_log.status }
question_answers = {
tenant_code: { type: "text", answer: "BZ737" },
tenant_age: { type: "numeric", answer: 25 },
tenant_gender: { type: "radio", answer: "1" },
tenant_ethnic_group: { type: "radio", answer: "2" },
tenant_nationality: { type: "radio", answer: "0" },
tenant_economic_status: { type: "radio", answer: "4" },
tenant_gender: { type: "radio", answer: "Female" },
tenant_ethnic_group: { type: "radio", answer: "Prefer not to say" },
tenant_nationality: { type: "radio", answer: "Lithuania" },
tenant_economic_status: { type: "radio", answer: "Jobseeker" },
household_number_of_other_members: { type: "numeric", answer: 2 },
}
@ -37,7 +38,7 @@ RSpec.describe "Test Features" do
click_button("Save and continue")
expect(page).to have_field("tenant-age-field")
click_button("Save and continue")
expect(page).to have_field("tenant-gender-0-field")
expect(page).to have_field("tenant-gender-male-field")
visit page.driver.request.env["HTTP_REFERER"]
expect(page).to have_field("tenant-age-field")
end
@ -58,7 +59,7 @@ RSpec.describe "Test Features" do
when "text"
fill_in(question.to_s, with: answer)
when "radio"
choose("#{question.to_s.tr('_', '-')}-#{answer}-field")
choose("#{question.to_s.dasherize}-#{answer.parameterize}-field")
else
fill_in(question.to_s, with: answer)
end
@ -96,4 +97,90 @@ RSpec.describe "Test Features" do
end
end
end
describe "check answers page" do
let(:subsection) { "household_characteristics" }
context "when the user needs to check their answers for a subsection" do
def fill_in_number_question(case_log_id, question, value)
visit("/case_logs/#{case_log_id}/#{question}")
fill_in(question.to_s, with: value)
click_button("Save and continue")
end
def answer_all_questions_in_income_subsection
visit("/case_logs/#{empty_case_log.id}/net_income")
fill_in("net_income", with: 18_000)
choose("net-income-frequency-yearly-field")
click_button("Save and continue")
choose("net-income-uc-proportion-all-field")
click_button("Save and continue")
choose("housing-benefit-housing-benefit-but-not-universal-credit-field")
click_button("Save and continue")
end
it "can be visited by URL" do
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
fill_in_number_question(id, last_question_for_subsection, 0)
expect(page).to have_current_path("/case_logs/#{id}/#{subsection}/check_answers")
end
it "has question headings based on the subsection" do
visit("case_logs/#{id}/#{subsection}/check_answers")
question_labels = ["Tenant code", "Tenant's age", "Tenant's gender", "Ethnicity", "Nationality", "Work", "Number of Other Household Members"]
question_labels.each do |label|
expect(page).to have_content(label)
end
end
it "should display answers given by the user for the question in the subsection" do
fill_in_number_question(empty_case_log.id, "tenant_age", 28)
choose("tenant-gender-non-binary-field")
click_button("Save and continue")
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
expect(page).to have_content("28")
expect(page).to have_content("Non-binary")
end
it "should have an answer link for questions missing an answer" do
visit("case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
assert_selector "a", text: /Answer\z/, count: 7
assert_selector "a", text: "Change", count: 0
expect(page).to have_link("Answer", href: "/case_logs/#{empty_case_log.id}/tenant_age")
end
it "should have a change link for answered questions" do
fill_in_number_question(empty_case_log.id, "tenant_age", 28)
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
assert_selector "a", text: /Answer\z/, count: 6
assert_selector "a", text: "Change", count: 1
expect(page).to have_link("Change", href: "/case_logs/#{empty_case_log.id}/tenant_age")
end
it "should have a link pointing to the first question if no questions are answered" do
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
expect(page).to have_content("You answered 0 of 7 questions")
expect(page).to have_link("Answer the missing questions", href: "/case_logs/#{empty_case_log.id}/tenant_code")
end
it "should have a link pointing to the next empty question if some questions are answered" do
fill_in_number_question(empty_case_log.id, "net_income", 18_000)
visit("/case_logs/#{empty_case_log.id}/income_and_benefits/check_answers")
expect(page).to have_content("You answered 1 of 4 questions")
expect(page).to have_link("Answer the missing questions", href: "/case_logs/#{empty_case_log.id}/net_income")
end
it "should not display the missing answer questions link if all questions are answered" do
answer_all_questions_in_income_subsection
expect(page).to have_content("You answered all the questions")
assert_selector "a", text: "Answer the missing questions", count: 0
end
end
end
end

28
spec/helpers/check_answers_helper_spec.rb

@ -0,0 +1,28 @@
require "rails_helper"
RSpec.describe CheckAnswersHelper do
describe "Get answered questions total" do
let!(:case_log) { FactoryBot.create(:case_log) }
@form = Form.new(2021, 2022)
subsection_pages = @form.pages_for_subsection("income_and_benefits")
it "returns 0 if no questions are answered" do
expect(get_answered_questions_total(subsection_pages, case_log)).to equal(0)
end
it "returns 1 if 1 question gets answered" do
case_log["net_income"] = "123"
expect(get_answered_questions_total(subsection_pages, case_log)).to equal(1)
end
end
describe "Get total number of questions" do
let!(:case_log) { FactoryBot.create(:case_log) }
@form = Form.new(2021, 2022)
subsection_pages = @form.pages_for_subsection("income_and_benefits")
it "returns the total number of questions for a subsection" do
expect(get_total_number_of_questions(subsection_pages)).to eq(4)
end
end
end
Loading…
Cancel
Save