Browse Source

Fix tests

pull/103/head
baarkerlounger 4 years ago
parent
commit
d10fc27d2d
  1. 2
      Gemfile
  2. 19
      app/helpers/tasklist_helper.rb
  3. 2
      app/models/form.rb
  4. 2
      app/views/case_logs/_tasklist.html.erb
  5. 6
      spec/factories/case_log.rb
  6. 5
      spec/helpers/tasklist_helper_spec.rb

2
Gemfile

@ -33,8 +33,8 @@ gem "chartkick"
gem "roo" gem "roo"
# Json Schema # Json Schema
gem "json-schema" gem "json-schema"
gem "uk_postcode"
gem "turbo-rails", "~> 0.8" gem "turbo-rails", "~> 0.8"
gem "uk_postcode"
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console

19
app/helpers/tasklist_helper.rb

@ -15,7 +15,7 @@ module TasklistHelper
def get_next_incomplete_section(form, case_log) def get_next_incomplete_section(form, case_log)
subsections = form.all_subsections.keys subsections = form.all_subsections.keys
subsections.find { |subsection| is_incomplete?(subsection, case_log, form, form.questions_for_subsection(subsection)) } subsections.find { |subsection| is_incomplete?(subsection, case_log, form) }
end end
def get_subsections_count(form, case_log, status = :all) def get_subsections_count(form, case_log, status = :all)
@ -25,8 +25,8 @@ module TasklistHelper
subsections.count { |subsection| form.subsection_status(subsection, case_log) == status } subsections.count { |subsection| form.subsection_status(subsection, case_log) == status }
end end
def get_first_page_or_check_answers(subsection, case_log, form, questions) def get_first_page_or_check_answers(subsection, case_log, form)
path = if is_started?(subsection, case_log, form, questions) path = if is_started?(subsection, case_log, form)
"case_log_#{subsection}_check_answers_path" "case_log_#{subsection}_check_answers_path"
else else
"case_log_#{form.first_page_for_subsection(subsection)}_path" "case_log_#{form.first_page_for_subsection(subsection)}_path"
@ -34,24 +34,19 @@ module TasklistHelper
send(path, case_log) send(path, case_log)
end end
def subsection_link(subsection_key, subsection_value, status) def subsection_link(subsection_key, subsection_value, status, form, case_log)
next_page_path = if status != :cannot_start_yet next_page_path = status != :cannot_start_yet ? get_first_page_or_check_answers(subsection_key, case_log, form) : "#"
questions = @form.questions_for_subsection(subsection_key)
get_first_page_or_check_answers(subsection_key, @case_log, @form, questions)
else
"#"
end
link_to(subsection_value["label"], next_page_path, class: "task-name govuk-link") link_to(subsection_value["label"], next_page_path, class: "task-name govuk-link")
end end
private private
def is_incomplete?(subsection, case_log, form, questions) def is_incomplete?(subsection, case_log, form)
status = form.subsection_status(subsection, case_log) status = form.subsection_status(subsection, case_log)
%i[not_started in_progress].include?(status) %i[not_started in_progress].include?(status)
end end
def is_started?(subsection, case_log, form, questions) def is_started?(subsection, case_log, form)
status = form.subsection_status(subsection, case_log) status = form.subsection_status(subsection, case_log)
%i[in_progress completed].include?(status) %i[in_progress completed].include?(status)
end end

2
app/models/form.rb

@ -108,7 +108,7 @@ class Form
end end
def page_routed_to?(page, case_log) def page_routed_to?(page, case_log)
return true unless conditions = page_dependencies(page) return true unless (conditions = page_dependencies(page))
conditions.all? do |question, value| conditions.all? do |question, value|
case_log[question].present? && case_log[question] == value case_log[question].present? && case_log[question] == value

2
app/views/case_logs/_tasklist.html.erb

@ -11,7 +11,7 @@
<li class="app-task-list__item" id=<%= subsection_key %>> <li class="app-task-list__item" id=<%= subsection_key %>>
<% questions_for_subsection = @form.questions_for_subsection(subsection_key) %> <% questions_for_subsection = @form.questions_for_subsection(subsection_key) %>
<% subsection_status = @form.subsection_status(subsection_key, @case_log) %> <% subsection_status = @form.subsection_status(subsection_key, @case_log) %>
<%= subsection_link(subsection_key, subsection_value, subsection_status) %> <%= subsection_link(subsection_key, subsection_value, subsection_status, @form, @case_log) %>
<strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>"> <strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>">
<%= TasklistHelper::STATUSES[subsection_status] %> <%= TasklistHelper::STATUSES[subsection_status] %>
</strong> </strong>

6
spec/factories/case_log.rb

@ -4,7 +4,7 @@ FactoryBot.define do
trait :in_progress do trait :in_progress do
status { 1 } status { 1 }
tenant_code { "TH356" } tenant_code { "TH356" }
postcode { "P0 5ST" } property_postcode { "P0 5ST" }
previous_postcode { "SW2 6HI" } previous_postcode { "SW2 6HI" }
age1 { "17" } age1 { "17" }
end end
@ -114,7 +114,7 @@ FactoryBot.define do
rent_type { 1 } rent_type { 1 }
intermediate_rent_product_name { 2 } intermediate_rent_product_name { 2 }
needs_type { 1 } needs_type { 1 }
purchaser_code { 798794 } purchaser_code { 798_794 }
reason { "Permanently decanted from another property owned by this landlord" } reason { "Permanently decanted from another property owned by this landlord" }
propcode { "123" } propcode { "123" }
majorrepairs { "Yes" } majorrepairs { "Yes" }
@ -131,7 +131,7 @@ FactoryBot.define do
mrcday { 5 } mrcday { 5 }
mrcmonth { 5 } mrcmonth { 5 }
mrcyear { 2020 } mrcyear { 2020 }
incref { 554355 } incref { 554_355 }
sale_completion_date { nil } sale_completion_date { nil }
startdate { nil } startdate { nil }
armedforces { 1 } armedforces { 1 }

5
spec/helpers/tasklist_helper_spec.rb

@ -5,7 +5,6 @@ RSpec.describe TasklistHelper do
let(:case_log) { FactoryBot.build(:case_log, :in_progress) } let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
form_handler = FormHandler.instance form_handler = FormHandler.instance
let(:form) { form_handler.get_form("test_form") } let(:form) { form_handler.get_form("test_form") }
let(:household_characteristics_questions) { form.questions_for_subsection("household_characteristics") }
describe "get next incomplete section" do describe "get next incomplete section" do
it "returns the first subsection name if it is not completed" do it "returns the first subsection name if it is not completed" do
@ -42,11 +41,11 @@ RSpec.describe TasklistHelper do
describe "get_first_page_or_check_answers" do describe "get_first_page_or_check_answers" do
it "returns the check answers page path if the section has been started already" do it "returns the check answers page path if the section has been started already" do
expect(get_first_page_or_check_answers("household_characteristics", case_log, form, household_characteristics_questions)).to match(/check_answers/) expect(get_first_page_or_check_answers("household_characteristics", case_log, form)).to match(/check_answers/)
end end
it "returns the first question page path for the section if it has not been started yet" do it "returns the first question page path for the section if it has not been started yet" do
expect(get_first_page_or_check_answers("household_characteristics", empty_case_log, form, household_characteristics_questions)).to match(/tenant_code/) expect(get_first_page_or_check_answers("household_characteristics", empty_case_log, form)).to match(/tenant_code/)
end end
end end
end end

Loading…
Cancel
Save