Browse Source

Mark subsection as completed if it is not displayed in the tasklist and hide it from the UI

pull/1109/head
Kat 2 years ago
parent
commit
959cbc070f
  1. 8
      app/models/form/subsection.rb
  2. 2
      app/models/log.rb
  3. 2
      app/views/logs/_tasklist.html.erb
  4. 15
      spec/models/lettings_log_spec.rb

8
app/models/form/subsection.rb

@ -24,9 +24,7 @@ class Form::Subsection
end
def status(log)
unless enabled?(log)
return :cannot_start_yet
end
return :cannot_start_yet unless enabled?(log)
qs = applicable_questions(log)
qs_optional_removed = qs.reject { |q| log.optional_fields.include?(q.id) }
@ -49,4 +47,8 @@ class Form::Subsection
(q.displayed_to_user?(log) && !q.derived?) || q.has_inferred_check_answers_value?(log)
end
end
def displayed_in_tasklist?(_log)
true
end
end

2
app/models/log.rb

@ -63,7 +63,7 @@ private
end
def all_fields_completed?
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) if subsection.displayed_in_tasklist?(self) }.uniq.compact
subsection_statuses == [:completed]
end

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

@ -9,7 +9,7 @@
<% end %>
<ul class="app-task-list__items">
<% section.subsections.map do |subsection| %>
<% if subsection.applicable_questions(@log).count > 0 || !subsection.enabled?(@log) %>
<% if subsection.displayed_in_tasklist?(@log) && (subsection.applicable_questions(@log).count > 0 || !subsection.enabled?(@log)) %>
<% subsection_status = subsection.status(@log) %>
<li class="app-task-list__item">
<span class="app-task-list__task-name" id="<%= subsection.id.dasherize %>">

15
spec/models/lettings_log_spec.rb

@ -184,6 +184,21 @@ RSpec.describe LettingsLog do
expect(completed_lettings_log.not_started?).to be(false)
expect(completed_lettings_log.completed?).to be(true)
end
context "when only a subsection that is hidden in tasklist is not completed" do
let(:household_characteristics_subsection) { completed_lettings_log.form.get_subsection("household_characteristics") }
before do
allow(household_characteristics_subsection).to receive(:displayed_in_tasklist?).and_return(false)
completed_lettings_log.update!(tenancycode: nil)
end
it "is set to completed" do
expect(completed_lettings_log.in_progress?).to be(false)
expect(completed_lettings_log.not_started?).to be(false)
expect(completed_lettings_log.completed?).to be(true)
end
end
end
describe "weekly_net_income" do

Loading…
Cancel
Save