Browse Source
* 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: lintingpull/1737/head
Aaron Spencer
2 years ago
committed by
GitHub
8 changed files with 186 additions and 38 deletions
@ -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 |
@ -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> |
@ -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:) |
@ -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…
Reference in new issue