Browse Source

CLDC 2405: Show more information on the sales log info component (#1732)

* CLDC-2405: Wip

* CLDC-2405: html modified to include new fields, method added to model

* CDLC-2405: LogSummaryComponent split into sales and lettings files

* CLDC-2405: sales log ownership method adjusted and added to view

* CLDC-2405: log summary tests added and adjusted

* CLDC-2405: cleanup

* CLDC-2405: linting
pull/1737/head
Aaron Spencer 2 years ago committed by GitHub
parent
commit
0ffa6ebc86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/components/lettings_log_summary_component.html.erb
  2. 13
      app/components/lettings_log_summary_component.rb
  3. 50
      app/components/sales_log_summary_component.html.erb
  4. 2
      app/components/sales_log_summary_component.rb
  5. 17
      app/models/sales_log.rb
  6. 7
      app/views/logs/_log_list.html.erb
  7. 25
      spec/components/lettings_log_summary_component_spec.rb
  8. 99
      spec/components/sales_log_summary_component_spec.rb

11
app/components/log_summary_component.html.erb → app/components/lettings_log_summary_component.html.erb

@ -3,11 +3,11 @@
<div class="govuk-grid-column-one-half"> <div class="govuk-grid-column-one-half">
<header class="app-log-summary__header"> <header class="app-log-summary__header">
<h2 class="app-log-summary__title"> <h2 class="app-log-summary__title">
<%= govuk_link_to log.lettings? ? lettings_log_path(log) : sales_log_path(log) do %> <%= govuk_link_to lettings_log_path(log) do %>
<span class="govuk-visually-hidden">Log </span><%= log.id %> <span class="govuk-visually-hidden">Log </span><%= log.id %>
<% end %> <% end %>
</h2> </h2>
<% if log.lettings? && (log.tenancycode? or log.propcode?) %> <% if log.tenancycode? or log.propcode? %>
<dl class="app-metadata app-metadata--inline"> <dl class="app-metadata app-metadata--inline">
<% if log.tenancycode? %> <% if log.tenancycode? %>
<div class="app-metadata__item"> <div class="app-metadata__item">
@ -24,8 +24,7 @@
</dl> </dl>
<% end %> <% end %>
</header> </header>
<% if log.needstype? or log.startdate? %>
<% if log.lettings? && (log.needstype? or log.startdate?) %>
<p class="govuk-body govuk-!-margin-bottom-2"> <p class="govuk-body govuk-!-margin-bottom-2">
<% if log.needstype? %> <% if log.needstype? %>
<%= log.is_general_needs? ? "General needs" : "Supported housing" %><br> <%= log.is_general_needs? ? "General needs" : "Supported housing" %><br>
@ -35,7 +34,6 @@
<% end %> <% end %>
</p> </p>
<% end %> <% end %>
<% if current_user.support? || current_user.organisation.has_managing_agents? %> <% if current_user.support? || current_user.organisation.has_managing_agents? %>
<dl class="app-metadata"> <dl class="app-metadata">
<% if log.owning_organisation %> <% if log.owning_organisation %>
@ -44,7 +42,7 @@
<dd class="app-metadata__definition"><%= log.owning_organisation&.name %></dd> <dd class="app-metadata__definition"><%= log.owning_organisation&.name %></dd>
</div> </div>
<% end %> <% end %>
<% if log.lettings? && log.managing_organisation %> <% if log.managing_organisation %>
<div class="app-metadata__item"> <div class="app-metadata__item">
<dt class="app-metadata__term">Managed by</dt> <dt class="app-metadata__term">Managed by</dt>
<dd class="app-metadata__definition"><%= log.managing_organisation&.name %></dd> <dd class="app-metadata__definition"><%= log.managing_organisation&.name %></dd>
@ -53,7 +51,6 @@
</dl> </dl>
<% end %> <% end %>
</div> </div>
<footer class="govuk-grid-column-one-half app-log-summary__footer"> <footer class="govuk-grid-column-one-half app-log-summary__footer">
<p class="govuk-body govuk-!-margin-bottom-2"> <p class="govuk-body govuk-!-margin-bottom-2">
<%= log_status %> <%= log_status %>

13
app/components/lettings_log_summary_component.rb

@ -0,0 +1,13 @@
class LettingsLogSummaryComponent < ViewComponent::Base
attr_reader :current_user, :log
def initialize(current_user:, log:)
@current_user = current_user
@log = log
super
end
def log_status
helpers.status_tag(log.status)
end
end

50
app/components/sales_log_summary_component.html.erb

@ -0,0 +1,50 @@
<article class="app-log-summary">
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<header class="app-log-summary__header">
<h2 class="app-log-summary__title">
<%= govuk_link_to sales_log_path(log) do %>
<span class="govuk-visually-hidden">Log </span><%= log.id %>
<% end %>
</h2>
<dl class="app-metadata app-metadata--inline">
<% if log.purchaser_code %>
<div class="app-metadata__item">
<dt class="app-metadata__term">Purchaser</dt>
<dd class="app-metadata__definition"><%= log.purchaser_code %></dd>
</div>
<% end %>
</dl>
</header>
<p class="govuk-body govuk-!-margin-bottom-2">
<% if log.ownership_scheme %>
<%= log.ownership_scheme(uppercase: true) %><br>
<% end %>
<% if log.saledate %>
Sale completed <time datetime="<%= log.saledate.iso8601 %>"><%= log.saledate.to_formatted_s(:govuk_date) %></time>
<% end %>
</p>
<% if current_user.support? || current_user.organisation.has_managing_agents? %>
<dl class="app-metadata">
<% if log.owning_organisation %>
<div class="app-metadata__item">
<dt class="app-metadata__term">Owned by</dt>
<dd class="app-metadata__definition"><%= log.owning_organisation&.name %></dd>
</div>
<% end %>
</dl>
<% end %>
</div>
<footer class="govuk-grid-column-one-half app-log-summary__footer">
<p class="govuk-body govuk-!-margin-bottom-2">
<%= log_status %>
</p>
<p class="govuk-body">
Created <time datetime="<%= log.created_at.iso8601 %>"><%= log.created_at.to_formatted_s(:govuk_date) %></time>
<% if log.created_by %>
<span class="app-log-summary__footer--actor">by <%= log.created_by.name || log.created_by.email %></span>
<% end %>
</p>
</footer>
</div>
</article>

2
app/components/log_summary_component.rb → app/components/sales_log_summary_component.rb

@ -1,4 +1,4 @@
class LogSummaryComponent < ViewComponent::Base class SalesLogSummaryComponent < ViewComponent::Base
attr_reader :current_user, :log attr_reader :current_user, :log
def initialize(current_user:, log:) def initialize(current_user:, log:)

17
app/models/sales_log.rb

@ -61,6 +61,10 @@ class SalesLog < Log
attribute_names attribute_names
end end
def purchaser_code
purchid
end
def form_name def form_name
return unless saledate return unless saledate
@ -379,12 +383,13 @@ class SalesLog < Log
beds.nil? ? nil : [beds, LaSaleRange::MAX_BEDS].min beds.nil? ? nil : [beds, LaSaleRange::MAX_BEDS].min
end end
def ownership_scheme def ownership_scheme(uppercase: false)
case ownershipsch ownership_scheme = case ownershipsch
when 1 then "shared ownership" when 1 then "shared ownership"
when 2 then "discounted ownership" when 2 then "discounted ownership"
when 3 then "outright sale" when 3 then "outright or other sale"
end end
uppercase ? ownership_scheme.capitalize : ownership_scheme
end end
def combined_income def combined_income

7
app/views/logs/_log_list.html.erb

@ -11,12 +11,15 @@
</div> </div>
<div class="govuk-grid-column-one-quarter govuk-!-text-align-right"> <div class="govuk-grid-column-one-quarter govuk-!-text-align-right">
<% if logs&.any? && (display_delete_logs?(@current_user, searched, filter_type) || in_organisations_tab?) %> <% if logs&.any? && (display_delete_logs?(@current_user, searched, filter_type) || in_organisations_tab?) %>
<%# remove @ on current user %>
<%= govuk_link_to "Delete logs", delete_logs_path, class: "app-!-colour-red" %> <%= govuk_link_to "Delete logs", delete_logs_path, class: "app-!-colour-red" %>
<% end %> <% end %>
</div> </div>
</div> </div>
</h2> </h2>
<% logs.map do |log| %> <% logs.map do |log| %>
<%= render(LogSummaryComponent.new(current_user:, log:)) %> <% if log.sales? %>
<%= render SalesLogSummaryComponent.new(current_user:, log:) %>
<% else %>
<%= render LettingsLogSummaryComponent.new(current_user:, log:) %>
<% end %>
<% end %> <% end %>

25
spec/components/log_summary_component_spec.rb → spec/components/lettings_log_summary_component_spec.rb

@ -1,15 +1,14 @@
require "rails_helper" require "rails_helper"
RSpec.describe LogSummaryComponent, type: :component do RSpec.describe LettingsLogSummaryComponent, type: :component do
let(:support_user) { FactoryBot.create(:user, :support) } let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user) } let(:coordinator_user) { FactoryBot.create(:user) }
let(:propcode) { "P3647" } let(:propcode) { "P3647" }
let(:tenancycode) { "T62863" } let(:tenancycode) { "T62863" }
let(:lettings_log) { FactoryBot.create(:lettings_log, needstype: 1, tenancycode:, propcode:, startdate: Time.zone.today) } let(:lettings_log) { FactoryBot.create(:lettings_log, needstype: 1, tenancycode:, propcode:, startdate: Time.zone.today) }
let(:sales_log) { FactoryBot.create(:sales_log) }
context "when rendering lettings log for a support user" do context "when rendering lettings log for a support user" do
it "show the log summary with organisational relationships" do it "shows the log summary with organisational relationships" do
result = render_inline(described_class.new(current_user: support_user, log: lettings_log)) result = render_inline(described_class.new(current_user: support_user, log: lettings_log))
expect(result).to have_link(lettings_log.id.to_s) expect(result).to have_link(lettings_log.id.to_s)
@ -25,29 +24,11 @@ RSpec.describe LogSummaryComponent, type: :component do
end end
context "when rendering lettings log for a data coordinator user" do context "when rendering lettings log for a data coordinator user" do
it "show the log summary" do it "does not show the user who the log is owned and managed by" do
result = render_inline(described_class.new(current_user: coordinator_user, log: lettings_log)) result = render_inline(described_class.new(current_user: coordinator_user, log: lettings_log))
expect(result).not_to have_content("Owned by") expect(result).not_to have_content("Owned by")
expect(result).not_to have_content("Managed by") expect(result).not_to have_content("Managed by")
end end
end end
context "when rendering sales log for a support user" do
it "show the log summary with organisational relationships" do
result = render_inline(described_class.new(current_user: support_user, log: sales_log))
expect(result).to have_content("Owned by\n DLUHC")
expect(result).not_to have_content("Managed by")
end
end
context "when rendering sales log for a data coordinator user" do
it "show the log summary" do
result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log))
expect(result).not_to have_content("Owned by")
expect(result).not_to have_content("Managed by")
end
end
end end

99
spec/components/sales_log_summary_component_spec.rb

@ -0,0 +1,99 @@
require "rails_helper"
RSpec.describe SalesLogSummaryComponent, type: :component do
let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user) }
let(:purchid) { "62863" }
let(:ownershipsch) { "0" }
let(:saledate) { Time.zone.today }
let(:sales_log) { FactoryBot.create(:sales_log, ownershipsch:, purchid:, saledate:) }
context "when rendering sales log for a support user" do
it "shows the log summary with organisational relationships" do
result = render_inline(described_class.new(current_user: support_user, log: sales_log))
expect(result).to have_content("Owned by\n DLUHC")
expect(result).not_to have_content("Managed by")
end
end
context "when rendering sales log for a data coordinator user" do
it "does not show the user who the log is owned and managed by" do
result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log))
expect(result).not_to have_content("Owned by")
expect(result).not_to have_content("Managed by")
end
end
describe "what is shown in regards to sale completion" do
context "when a sale is completed" do
let(:saledate) { Time.zone.today }
it "shows the sale completion date" do
result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log))
expect(result).to have_content("Sale completed")
end
end
context "when a sale is completed and a purchaser id is provided" do
let(:purchid) { "62863" }
let(:saledate) { Time.zone.today }
it "shows the purchaser id" do
result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log))
expect(result).to have_content(purchid)
end
end
context "when the sale is not completed" do
let(:saledate) { nil }
it "does not show a sale completed date" do
result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log))
expect(result).not_to have_content("Sale completed")
end
end
end
describe "what is shown dependant on ownership type" do
context "when the ownership scheme is shared ownership" do
let(:ownershipsch) { "1" }
it "displayed the correct ownership type" do
result = render_inline(described_class.new(current_user: support_user, log: sales_log))
expect(result).to have_content("Shared ownership")
expect(result).not_to have_content("Discounted ownership")
expect(result).not_to have_content("Outright or other sale")
end
end
context "when the ownership scheme is discounted ownership" do
let(:ownershipsch) { "2" }
it "displayed the correct ownership type" do
result = render_inline(described_class.new(current_user: support_user, log: sales_log))
expect(result).not_to have_content("Shared ownership")
expect(result).to have_content("Discounted ownership")
expect(result).not_to have_content("Outright or other sale")
end
end
context "when the ownership scheme is outright or other sale" do
let(:ownershipsch) { "3" }
it "displayed the correct ownership type" do
result = render_inline(described_class.new(current_user: support_user, log: sales_log))
expect(result).not_to have_content("Shared ownership")
expect(result).not_to have_content("Discounted ownership")
expect(result).to have_content("Outright or other sale")
end
end
end
end
Loading…
Cancel
Save