Browse Source

CLDC-1968 Add review page for Sales logs (#1292)

* CLDC-1968 Add review page for Sales logs

* use log#sales?

* Do not use type checking
pull/1309/head
Jack 2 years ago committed by GitHub
parent
commit
d8689c30a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Gemfile
  2. 4
      app/helpers/tasklist_helper.rb
  3. 12
      app/models/lettings_log.rb
  4. 4
      app/models/log.rb
  5. 8
      app/models/sales_log.rb
  6. 40
      app/views/form/review.html.erb
  7. 4
      config/routes.rb
  8. 2
      spec/helpers/tasklist_helper_spec.rb
  9. 5
      spec/models/lettings_log_spec.rb
  10. 7
      spec/models/sales_log_spec.rb
  11. 6
      spec/requests/form_controller_spec.rb

2
Gemfile

@ -68,6 +68,7 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: %i[mri mingw x64_mingw]
gem "dotenv-rails"
gem "factory_bot_rails"
gem "pry-byebug"
gem "parallel_tests"
@ -90,7 +91,6 @@ end
group :test do
gem "capybara", require: false
gem "capybara-lockstep"
gem "factory_bot_rails"
gem "faker"
gem "rspec-rails", require: false
gem "selenium-webdriver", require: false

4
app/helpers/tasklist_helper.rb

@ -39,7 +39,9 @@ module TasklistHelper
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
link = log.sales? ? review_sales_log_path(id: log, sales_log: true) : review_lettings_log_path(log)
"You can #{govuk_link_to 'review and make changes to this log', link} 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

12
app/models/lettings_log.rb

@ -70,6 +70,14 @@ class LettingsLog < Log
collection_start_year
end
def lettings?
true
end
def sales?
false
end
def form_name
return unless startdate
@ -481,10 +489,6 @@ class LettingsLog < Log
location.type_of_unit_before_type_cast if location
end
def lettings?
true
end
def rent_type_detail
form.get_question("rent_type", self)&.label_from_value(rent_type)
end

4
app/models/log.rb

@ -43,6 +43,10 @@ class Log < ApplicationRecord
false
end
def sales?
false
end
def ethnic_refused?
ethnic_group == 17
end

8
app/models/sales_log.rb

@ -38,6 +38,14 @@ class SalesLog < Log
OPTIONAL_FIELDS = %w[saledate_check purchid monthly_charges_value_check old_persons_shared_ownership_value_check].freeze
RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze
def lettings?
false
end
def sales?
true
end
def startdate
saledate
end

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

@ -1,9 +1,18 @@
<% content_for :title, "Review lettings log" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs",
"Log #{@log.id}" => "/lettings-logs/#{@log.id}",
"Review lettings log" => "",
}) %>
<% if @log.sales? %>
<% content_for :title, "Review sales log" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs",
"Log #{@log.id}" => "/sales-logs/#{@log.id}",
"Review sales log" => "",
}) %>
<% else %>
<% content_for :title, "Review lettings log" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs",
"Log #{@log.id}" => "/lettings-logs/#{@log.id}",
"Review lettings log" => "",
}) %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
@ -16,17 +25,16 @@
<% @log.form.sections.map do |section| %>
<h2 class="govuk-heading-m"><%= section.label %></h2>
<% section.subsections.map do |subsection| %>
<div class="x-govuk-summary-card govuk-!-margin-bottom-6">
<div class="x-govuk-summary-card__header">
<h3 class="x-govuk-summary-card__title"><%= subsection.label %></h3>
<% if total_applicable_questions(subsection, @log, current_user).any? %>
<div class="x-govuk-summary-card govuk-!-margin-bottom-6">
<div class="x-govuk-summary-card__header">
<h3 class="x-govuk-summary-card__title"><%= subsection.label %></h3>
</div>
<div class="x-govuk-summary-card__body">
<%= render partial: "form/check_answers_summary_list", locals: { subsection: } %>
</div>
</div>
<div class="x-govuk-summary-card__body">
<%= render partial: "form/check_answers_summary_list", locals: {
subsection:,
lettings_log: @log,
} %>
</div>
</div>
<% end %>
<% end %>
<% end %>
</div>

4
config/routes.rb

@ -171,6 +171,10 @@ Rails.application.routes.draw do
resources :bulk_upload_sales_results, path: "bulk-upload-results", only: [:show]
end
member do
get "review", to: "form#review"
end
FormHandler.instance.sales_forms.each do |_key, form|
form.pages.map do |page|
get page.id.to_s.dasherize, to: "form#show_page"

2
spec/helpers/tasklist_helper_spec.rb

@ -136,7 +136,7 @@ RSpec.describe TasklistHelper do
it "returns relevant text" do
expect(review_log_text(sales_log)).to eq(
"You can #{govuk_link_to 'review and make changes to this log', review_lettings_log_path(sales_log)} until 1 July 2023.".html_safe,
"You can #{govuk_link_to 'review and make changes to this log', review_sales_log_path(id: sales_log, sales_log: true)} until 1 July 2023.".html_safe,
)
end
end

5
spec/models/lettings_log_spec.rb

@ -18,6 +18,11 @@ RSpec.describe LettingsLog do
expect(described_class).to be < ApplicationRecord
end
it "is a not a sales log" do
lettings_log = FactoryBot.build(:lettings_log, created_by: created_by_user)
expect(lettings_log.sales?).to be false
end
it "is a lettings log" do
lettings_log = FactoryBot.build(:lettings_log, created_by: created_by_user)
expect(lettings_log).to be_lettings

7
spec/models/sales_log_spec.rb

@ -12,11 +12,16 @@ RSpec.describe SalesLog, type: :model do
expect(described_class).to be < ApplicationRecord
end
it "is a sales log" do
it "is a not a lettings log" do
sales_log = build(:sales_log, created_by: created_by_user)
expect(sales_log.lettings?).to be false
end
it "is a sales log" do
sales_log = build(:sales_log, created_by: created_by_user)
expect(sales_log.sales?).to be true
end
describe "#new" do
context "when creating a record" do
let(:sales_log) do

6
spec/requests/form_controller_spec.rb

@ -314,6 +314,12 @@ RSpec.describe FormController, type: :request do
get "/lettings-logs/#{setup_complete_lettings_log.id}/review", headers: headers, params: {}
expect(response.body).to match("Review lettings log")
end
it "renders the review page for the sales log" do
log = create(:sales_log, :completed, created_by: user)
get "/sales-logs/#{log.id}/review", headers: headers, params: { sales_log: true }
expect(response.body).to match("Review sales log")
end
end
context "when viewing a user dependent page" do

Loading…
Cancel
Save