Browse Source

Cldc 1211 close collection period (#1044)

* Conditionally display a correct review log text

* do not allow the aswers from previous collection windows to be changed

* does not let the user navigate to questions for previous collection year logs

* Fix tests

* Add some docs

* Extract collection period check into a before_action and change path to rails route

* update the tasklist message
pull/1057/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
a1bd59552d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/components/check_answers_summary_list_card_component.html.erb
  2. 7
      app/controllers/form_controller.rb
  3. 8
      app/helpers/tasklist_helper.rb
  4. 4
      app/models/log.rb
  5. 12
      app/views/form/_check_answers_summary_list.html.erb
  6. 2
      app/views/form/review.html.erb
  7. 2
      app/views/logs/edit.html.erb
  8. 6
      docs/form/definition.md
  9. 1
      spec/features/form/accessible_autocomplete_spec.rb
  10. 2
      spec/features/form/check_answers_page_spec.rb
  11. 1
      spec/features/form/checkboxes_spec.rb
  12. 2
      spec/features/form/conditional_questions_spec.rb
  13. 2
      spec/features/form/form_navigation_spec.rb
  14. 1
      spec/features/form/page_routing_spec.rb
  15. 1
      spec/features/form/progressive_total_field_spec.rb
  16. 1
      spec/features/form/saving_data_spec.rb
  17. 1
      spec/features/form/tasklist_page_spec.rb
  18. 2
      spec/features/form/validations_spec.rb
  19. 6
      spec/requests/form_controller_spec.rb
  20. 38
      spec/requests/lettings_logs_controller_spec.rb

12
app/components/check_answers_summary_list_card_component.html.erb

@ -25,11 +25,13 @@
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %>
<% end %>
<% row.action(
text: question.action_text(log),
href: question.action_href(log, question.page.id),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% if @log.collection_period_open? %>
<% row.action(
text: question.action_text(log),
href: question.action_href(log, question.page.id),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% end %>
<% end %>
<% end %>
<% end %>

7
app/controllers/form_controller.rb

@ -2,6 +2,7 @@ class FormController < ApplicationController
before_action :authenticate_user!
before_action :find_resource, only: %i[submit_form review]
before_action :find_resource_by_named_id, except: %i[submit_form review]
before_action :check_collection_period, only: %i[submit_form show_page]
def submit_form
if @log
@ -176,4 +177,10 @@ private
responses_for_page[question.id].nil? || responses_for_page[question.id].blank?
end
end
def check_collection_period
return unless @log
redirect_to lettings_log_path(@log) unless @log.collection_period_open?
end
end

8
app/helpers/tasklist_helper.rb

@ -36,4 +36,12 @@ module TasklistHelper
subsection.label
end
end
def review_log_text(log)
if log.collection_period_open?
"You can #{govuk_link_to 'review and make changes to this log', review_lettings_log_path(log)} until #{(log.form.end_date).to_formatted_s(:govuk_date)}.".html_safe
else
"This log is from the #{log.form.start_date.year}/#{log.form.start_date.year + 1} collection window, which is now closed."
end
end
end

4
app/models/log.rb

@ -45,6 +45,10 @@ class Log < ApplicationRecord
managing_organisation&.provider_type
end
def collection_period_open?
form.end_date > Time.zone.today
end
private
def update_status!

12
app/views/form/_check_answers_summary_list.html.erb

@ -13,11 +13,13 @@
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %>
<% end %>
<% row.action(
text: question.action_text(@log),
href: question.action_href(@log, question.page.id),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% if @log.collection_period_open? %>
<% row.action(
text: question.action_text(@log),
href: question.action_href(@log, question.page.id),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% end %>
<% end %>
<% end %>
<% end %>

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

@ -11,7 +11,7 @@
<%= content_for(:title) %>
</h1>
<p class="govuk-body">
You can review and make changes to this log until 2nd June <%= @log.collection_start_year.present? ? @log.collection_start_year + 1 : "" %>.
<%= review_log_text(@log) %>
</p>
<% @log.form.sections.map do |section| %>
<h2 class="govuk-heading-m"><%= section.label %></h2>

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

@ -29,7 +29,7 @@
<%= status_tag(@log.status) %>
</p>
<p class="govuk-body">
You can <%= govuk_link_to "review and make changes to this log", "/lettings-logs/#{@log.id}/review" %> until 2nd June <%= @log.collection_start_year.present? ? @log.collection_start_year + 1 : "" %>.
<%= review_log_text(@log) %>
</p>
<% end %>
<%= render "tasklist" %>

6
docs/form/definition.md

@ -55,6 +55,9 @@ A form has the following attributes:
- `start_date`: The start date of the form, in ISO 8601 format
- `end_date`: The end date of the form, in ISO 8601 format
Each form has an `end_date` which for JSON forms is defined in the form definition JSON file and for code defined forms it is set to 1st July, 1 year after the start year.
Logs with a form that has `end_date` in the past can no longer be edited through the UI.
## Form views
The main view used for rendering the form is the `app/views/form/page.html.erb` view as the Form contains multiple pages (which live in subsections within sections). This page view then renders the appropriate partials for the question types of the questions on the current page.
@ -79,3 +82,6 @@ The form controller handles the form submission as well as the rendering of the
## FormHandler helper class
The FormHandler helper is a helper that loads all of the defined forms and initialises them as Form objects. It can also be used to get specific forms if needed.
When the log type is chosen and the date is entered in the setup section of the form, an appropriate form for that log is selected and associated with the log.
The current collection window gets incremented automatically in `FormHandler` and is determined within the `form_name_from_start_year`by looking at `current_collection_start_year` method which would increment the collection window on the 1st of April each year.

1
spec/features/form/accessible_autocomplete_spec.rb

@ -19,6 +19,7 @@ RSpec.describe "Accessible Automcomplete" do
end
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

2
spec/features/form/check_answers_page_spec.rb

@ -43,6 +43,8 @@ RSpec.describe "Form Check Answers Page" do
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day)
sign_in user
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end

1
spec/features/form/checkboxes_spec.rb

@ -16,6 +16,7 @@ RSpec.describe "Checkboxes" do
let(:id) { lettings_log.id }
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
RequestHelper.stub_http_requests
sign_in user
end

2
spec/features/form/conditional_questions_spec.rb

@ -25,6 +25,8 @@ RSpec.describe "Form Conditional Questions" do
before do
sign_in user
allow(sales_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end

2
spec/features/form/form_navigation_spec.rb

@ -35,6 +35,8 @@ RSpec.describe "Form Navigation" do
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day)
sign_in user
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end

1
spec/features/form/page_routing_spec.rb

@ -16,6 +16,7 @@ RSpec.describe "Form Page Routing" do
let(:validator) { lettings_log._validators[nil].first }
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(validator).to receive(:validate_pregnancy).and_return(true)
sign_in user
end

1
spec/features/form/progressive_total_field_spec.rb

@ -14,6 +14,7 @@ RSpec.describe "Accessible Automcomplete" do
end
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

1
spec/features/form/saving_data_spec.rb

@ -30,6 +30,7 @@ RSpec.describe "Form Saving Data" do
end
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

1
spec/features/form/tasklist_page_spec.rb

@ -44,6 +44,7 @@ RSpec.describe "Task List" do
let(:status) { lettings_log.status }
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

2
spec/features/form/validations_spec.rb

@ -34,6 +34,8 @@ RSpec.describe "validations" do
let(:id) { lettings_log.id }
before do
allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
sign_in user
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end

6
spec/requests/form_controller_spec.rb

@ -35,6 +35,7 @@ RSpec.describe FormController, type: :request do
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end
@ -87,6 +88,10 @@ RSpec.describe FormController, type: :request do
let(:lettings_log_year_1) { create(:lettings_log, startdate: Time.zone.local(2021, 5, 1), owning_organisation: organisation, created_by: user) }
let(:lettings_log_year_2) { create(:lettings_log, :about_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation, created_by: user) }
before do
allow(lettings_log_year_1.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
end
it "displays the correct question details for each lettings log based on form year" do
get "/lettings-logs/#{lettings_log_year_1.id}/tenant-code-test", headers: headers, params: {}
expect(response.body).to include("What is the tenant code?")
@ -505,6 +510,7 @@ RSpec.describe FormController, type: :request do
before do
completed_lettings_log.update!(ecstat1: 1, earnings: 130, hhmemb: 1) # we're not routing to that page, so it gets cleared?§
allow(completed_lettings_log).to receive(:net_income_soft_validation_triggered?).and_return(true)
allow(completed_lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
post "/lettings-logs/#{completed_lettings_log.id}/form", params: interrupt_params, headers: headers.merge({ "HTTP_REFERER" => referrer })
end

38
spec/requests/lettings_logs_controller_spec.rb

@ -620,7 +620,7 @@ RSpec.describe LettingsLogsController, type: :request do
end
context "when requesting a specific lettings log" do
let(:completed_lettings_log) { FactoryBot.create(:lettings_log, :completed) }
let!(:completed_lettings_log) { FactoryBot.create(:lettings_log, :completed, owning_organisation: user.organisation, managing_organisation: user.organisation, created_by: user) }
let(:id) { completed_lettings_log.id }
before do
@ -672,6 +672,26 @@ RSpec.describe LettingsLogsController, type: :request do
assert_select ".govuk-tag", text: /Completed/, count: 0
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end
it "displays a link to update the log for currently editable logs" do
completed_lettings_log.update!(startdate: Time.zone.local(2022, 4, 1), tenancylength: nil)
completed_lettings_log.reload
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.end_date).to eq(Time.zone.local(2023, 7, 1))
expect(completed_lettings_log.status).to eq("completed")
expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{completed_lettings_log.id}/review")
end
it "displays a closed collection window message for previous collection year logs" do
completed_lettings_log.update!(startdate: Time.zone.local(2021, 4, 1))
completed_lettings_log.reload
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.end_date).to eq(Time.zone.local(2022, 7, 1))
expect(completed_lettings_log.status).to eq("completed")
expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.")
end
end
context "with a lettings log with a single section complete" do
@ -741,6 +761,7 @@ RSpec.describe LettingsLogsController, type: :request do
postcode_known: "No")
end
let(:id) { postcode_lettings_log.id }
let(:completed_lettings_log) { FactoryBot.create(:lettings_log, :completed, owning_organisation: user.organisation, managing_organisation: user.organisation, created_by: user, startdate: Time.zone.local(2021, 4, 1)) }
before do
stub_request(:get, /api.postcodes.io/)
@ -774,6 +795,21 @@ RSpec.describe LettingsLogsController, type: :request do
get "/lettings-logs/#{id}/income-and-benefits/check-answers"
expect(CGI.unescape_html(response.body)).to include("You didn’t answer this question")
end
it "does not allow you to change the answers for previous collection year logs" do
get "/lettings-logs/#{completed_lettings_log.id}/setup/check-answers", headers: { "Accept" => "text/html" }, params: {}
expect(page).not_to have_link("Change")
expect(page).not_to have_link("Answer")
get "/lettings-logs/#{completed_lettings_log.id}/income-and-benefits/check-answers", headers: { "Accept" => "text/html" }, params: {}
expect(page).not_to have_link("Change")
expect(page).not_to have_link("Answer")
end
it "does not let the user navigate to questions for previous collection year logs" do
get "/lettings-logs/#{completed_lettings_log.id}/needs-type", headers: { "Accept" => "text/html" }, params: {}
expect(response).to redirect_to("/lettings-logs/#{completed_lettings_log.id}")
end
end
context "when requesting CSV download" do

Loading…
Cancel
Save