Browse Source

test: improvements to tests

pull/987/head
Sam Seed 4 years ago
parent
commit
3edc7ce20f
  1. 4
      app/helpers/schemes_helper.rb
  2. 2
      app/views/schemes/show.html.erb
  3. 43
      spec/helpers/schemes_helper_spec.rb

4
app/helpers/schemes_helper.rb

@ -1,5 +1,5 @@
module SchemesHelper module SchemesHelper
def display_scheme_attributes(scheme) def display_scheme_attributes(scheme, user)
base_attributes = [ base_attributes = [
{ name: "Scheme code", value: scheme.id_to_display }, { name: "Scheme code", value: scheme.id_to_display },
{ name: "Name", value: scheme.service_name, edit: true }, { name: "Name", value: scheme.service_name, edit: true },
@ -21,7 +21,7 @@ module SchemesHelper
base_attributes.append({ name: "Status", value: status_tag(scheme.status) }) base_attributes.append({ name: "Status", value: status_tag(scheme.status) })
end end
if current_user.data_coordinator? if user.data_coordinator?
base_attributes.delete_if {|item| item[:name] == "Housing stock owned by"} base_attributes.delete_if {|item| item[:name] == "Housing stock owned by"}
end end

2
app/views/schemes/show.html.erb

@ -19,7 +19,7 @@
<h2 class="govuk-visually-hidden">Scheme</h2> <h2 class="govuk-visually-hidden">Scheme</h2>
<%= govuk_summary_list do |summary_list| %> <%= govuk_summary_list do |summary_list| %>
<% display_scheme_attributes(@scheme).each do |attr| %> <% display_scheme_attributes(@scheme, current_user).each do |attr| %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name] } %> <% row.key { attr[:name] } %>
<% row.value { details_html(attr) } %> <% row.value { details_html(attr) } %>

43
spec/helpers/schemes_helper_spec.rb

@ -1,5 +1,7 @@
require "rails_helper" require "rails_helper"
include TagHelper
RSpec.describe SchemesHelper do RSpec.describe SchemesHelper do
describe "Active periods" do describe "Active periods" do
let(:scheme) { FactoryBot.create(:scheme, created_at: Time.zone.today) } let(:scheme) { FactoryBot.create(:scheme, created_at: Time.zone.today) }
@ -88,16 +90,43 @@ RSpec.describe SchemesHelper do
end end
describe "display_scheme_attributes" do describe "display_scheme_attributes" do
let!(:scheme) { FactoryBot.create(:scheme, created_at: Time.zone.local(2022, 4, 1)) } let (owning
let!(:scheme) { FactoryBot.create(:scheme,
id: 1,
created_at: Time.zone.local(2022, 4, 1),
service_name: 'Test name'
owning_organisation
) }
let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) }
it "returns correct display attributes for a support user" do
attributes = [
{ name: "Scheme code", value: "S1" },
{ name: "Name", value: "Test name", edit: true },
{ name: "Confidential information", value: scheme.sensitive, edit: true },
{ name: "Type of scheme", value: scheme.scheme_type },
{ name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act },
{ name: "Housing stock owned by", value: ""scheme.owning_organisation.name"", edit: true },
{ name: "Support services provided by", value: scheme.arrangement_type },
{ name: "Primary client group", value: scheme.primary_client_group },
{ name: "Has another client group", value: scheme.has_other_client_group },
{ name: "Secondary client group", value: scheme.secondary_client_group },
{ name: "Level of support given", value: scheme.support_type },
{ name: "Intended length of stay", value: scheme.intended_stay },
{ name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: status_tag(:active) },
]
expect(display_scheme_attributes(scheme, support_user)).to eq(attributes)
end
it "returns correct display attributes" do it "returns correct display attributes for a coordinator user" do
attributes = [ attributes = [
{ name: "Scheme code", value: scheme.id_to_display }, { name: "Scheme code", value: scheme.id_to_display },
{ name: "Name", value: scheme.service_name, edit: true }, { name: "Name", value: scheme.service_name, edit: true },
{ name: "Confidential information", value: scheme.sensitive, edit: true }, { name: "Confidential information", value: scheme.sensitive, edit: true },
{ name: "Type of scheme", value: scheme.scheme_type }, { name: "Type of scheme", value: scheme.scheme_type },
{ name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act }, { name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act },
{ name: "Housing stock owned by", value: scheme.owning_organisation.name, edit: true },
{ name: "Support services provided by", value: scheme.arrangement_type }, { name: "Support services provided by", value: scheme.arrangement_type },
{ name: "Primary client group", value: scheme.primary_client_group }, { name: "Primary client group", value: scheme.primary_client_group },
{ name: "Has another client group", value: scheme.has_other_client_group }, { name: "Has another client group", value: scheme.has_other_client_group },
@ -105,15 +134,15 @@ RSpec.describe SchemesHelper do
{ name: "Level of support given", value: scheme.support_type }, { name: "Level of support given", value: scheme.support_type },
{ name: "Intended length of stay", value: scheme.intended_stay }, { name: "Intended length of stay", value: scheme.intended_stay },
{ name: "Availability", value: "Active from 1 April 2022" }, { name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: :active }, { name: "Status", value: status_tag(:active) },
] ]
expect(display_scheme_attributes(scheme)).to eq(attributes) expect(display_scheme_attributes(scheme, coordinator_user)).to eq(attributes)
end end
context "when viewing availability" do context "when viewing availability" do
context "with no deactivations" do context "with no deactivations" do
it "displays created_at as availability date" do it "displays created_at as availability date" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from #{scheme.created_at.to_formatted_s(:govuk_date)}") expect(availability_attribute).to eq("Active from #{scheme.created_at.to_formatted_s(:govuk_date)}")
end end
@ -211,7 +240,7 @@ RSpec.describe SchemesHelper do
end end
it "displays the timeline of availability" do it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022") expect(availability_attribute).to eq("Active from 1 April 2022 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
end end

Loading…
Cancel
Save