Browse Source

Allow scheme editing for support users

pull/2084/head
Kat 2 years ago
parent
commit
d423d24447
  1. 2
      app/controllers/schemes_controller.rb
  2. 3
      app/helpers/check_answers_helper.rb
  3. 19
      app/helpers/schemes_helper.rb
  4. 22
      app/models/scheme.rb
  5. 4
      app/views/schemes/_scheme_summary_list_row.html.erb
  6. 2
      app/views/schemes/check_answers.html.erb
  7. 5
      app/views/schemes/confirm_secondary.html.erb
  8. 8
      app/views/schemes/details.html.erb
  9. 8
      app/views/schemes/primary_client_group.html.erb
  10. 5
      app/views/schemes/secondary_client_group.html.erb
  11. 29
      app/views/schemes/show.html.erb
  12. 5
      app/views/schemes/support.html.erb
  13. 3
      spec/factories/scheme.rb
  14. 24
      spec/features/schemes_spec.rb
  15. 228
      spec/helpers/schemes_helper_spec.rb

2
app/controllers/schemes_controller.rb

@ -310,7 +310,7 @@ private
end
def redirect_if_scheme_confirmed
redirect_to @scheme if @scheme.confirmed?
redirect_to @scheme if @scheme.confirmed? && !current_user.support?
end
def deactivate_success_notice

3
app/helpers/check_answers_helper.rb

@ -12,7 +12,8 @@ module CheckAnswersHelper
end
def can_change_scheme_answer?(attribute_name, scheme)
return false unless current_user.support? || current_user.data_coordinator?
return true if current_user.support?
return false unless current_user.data_coordinator?
editable_attributes = ["Name", "Confidential information", "Housing stock owned by"]

19
app/helpers/schemes_helper.rb

@ -1,23 +1,4 @@
module SchemesHelper
def display_scheme_attributes(scheme)
[
{ name: "Scheme code", value: scheme.id_to_display },
{ name: "Name", value: scheme.service_name, edit: true },
{ name: "Status", value: status_tag_from_resource(scheme) },
{ 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 },
scheme.has_other_client_group == "Yes" ? { name: "Secondary client group", value: scheme.secondary_client_group } : nil,
{ name: "Level of support given", value: scheme.support_type },
{ name: "Intended length of stay", value: scheme.intended_stay },
{ name: "Availability", value: scheme_availability(scheme) },
].compact
end
def scheme_availability(scheme)
availability = ""
scheme_active_periods(scheme).each do |period|

22
app/models/scheme.rb

@ -187,37 +187,37 @@ class Scheme < ApplicationRecord
def check_details_attributes
[
{ name: "Scheme code", value: id_to_display, id: "id" },
{ name: "Name", value: service_name, id: "service_name" },
{ name: "Confidential information", value: sensitive, id: "sensitive" },
{ name: "Type of scheme", value: scheme_type, id: "scheme_type" },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act" },
{ name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id" },
{ name: "Support services provided by", value: arrangement_type, id: "arrangement_type" },
{ name: "Name", value: service_name, id: "service_name", edit: true },
{ name: "Confidential information", value: sensitive, id: "sensitive", edit: true },
{ name: "Type of scheme", value: scheme_type, id: "scheme_type", edit: true },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act", edit: true },
{ name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id", edit: true },
{ name: "Support services provided by", value: arrangement_type, id: "arrangement_type", edit: true },
]
end
def check_primary_client_attributes
[
{ name: "Primary client group", value: primary_client_group, id: "primary_client_group" },
{ name: "Primary client group", value: primary_client_group, id: "primary_client_group", edit: true },
]
end
def check_secondary_client_confirmation_attributes
[
{ name: "Has another client group", value: has_other_client_group, id: "has_other_client_group" },
{ name: "Has another client group", value: has_other_client_group, id: "has_other_client_group", edit: true },
]
end
def check_secondary_client_attributes
[
{ name: "Secondary client group", value: secondary_client_group, id: "secondary_client_group" },
{ name: "Secondary client group", value: secondary_client_group, id: "secondary_client_group", edit: true },
]
end
def check_support_attributes
[
{ name: "Level of support given", value: support_type, id: "support_type" },
{ name: "Intended length of stay", value: intended_stay, id: "intended_stay" },
{ name: "Level of support given", value: support_type, id: "support_type", edit: true },
{ name: "Intended length of stay", value: intended_stay, id: "intended_stay", edit: true },
]
end

4
app/views/schemes/_scheme_summary_list_row.html.erb

@ -1,4 +1,4 @@
<div class="<%= "govuk-summary-list__row #{scheme.confirmed? && !can_change_scheme_answer?(attribute[:name], @scheme) ? 'govuk-summary-list__row--no-actions' : ''}" %>">
<div class="<%= "govuk-summary-list__row #{scheme.confirmed? && !can_change_scheme_answer?(attribute[:name], @scheme) && !attribute[:edit] ? 'govuk-summary-list__row--no-actions' : ''}" %>">
<dt class="govuk-summary-list__key">
<%= attribute[:name].to_s %>
</dt>
@ -15,7 +15,7 @@
</dd>
<% end %>
<% if can_change_scheme_answer?(attribute[:name], scheme) %>
<% if can_change_scheme_answer?(attribute[:name], scheme) && attribute[:edit] %>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href="<%= change_link %>">Change</a>
</dd>

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

@ -9,7 +9,7 @@
<h2 class="govuk-visually-hidden">Scheme</h2>
<dl class="govuk-summary-list">
<% @scheme.check_details_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: @scheme.confirmed? ? scheme_edit_name_path(@scheme) : scheme_details_path(@scheme, check_answers: true) } %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(@scheme) } %>
<% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %>

5
app/views/schemes/confirm_secondary.html.erb

@ -23,9 +23,10 @@
<%= f.hidden_field :page, value: "confirm-secondary" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

8
app/views/schemes/details.html.erb

@ -9,7 +9,11 @@
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>
<% if @scheme.id.present? %>
<%= render partial: "organisations/headings", locals: { main: "Scheme details", sub: @scheme.service_name } %>
<% else %>
<%= render partial: "organisations/headings", locals: { main: "Create a new supported housing scheme", sub: nil } %>
<% end %>
<%= f.govuk_text_field :service_name,
label: { text: "Scheme name", size: "m" },
@ -72,8 +76,10 @@
<%= f.hidden_field :page, value: "details" %>
<% if request.query_parameters["check_answers"] %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

8
app/views/schemes/primary_client_group.html.erb

@ -25,14 +25,16 @@
legend: nil %>
<%= f.hidden_field :page, value: "primary-client-group" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
<% if request.query_parameters["select_managing_org"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

5
app/views/schemes/secondary_client_group.html.erb

@ -23,9 +23,10 @@
<%= f.hidden_field :page, value: "secondary-client-group" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

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

@ -19,24 +19,29 @@
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id)) %>
<h2 class="govuk-visually-hidden">Scheme</h2>
<%= govuk_inset_text(text: edit_scheme_text(@scheme, current_user)) %>
<%= govuk_summary_list do |summary_list| %>
<% display_scheme_attributes(@scheme).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% row.value do %>
<%= details_html(attr) %>
<% if attr[:name] == "Status" && @scheme.confirmed? && @scheme.locations.confirmed.none? && LocationPolicy.new(current_user, @scheme.locations.new).create? %>
<span class="app-!-colour-muted">Complete this scheme by adding a location using the <%= govuk_link_to("‘locations’ tab", scheme_locations_path(@scheme)) %>.</span>
<dl class="govuk-summary-list">
<% @scheme.check_details_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(scheme_id: @scheme.id) } %>
<% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_primary_client_group_path(@scheme, check_answers: true) } %>
<% end %>
<% if SchemePolicy.new(current_user, @scheme).update? %>
<% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id)) if attr[:edit] %>
<% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_confirm_secondary_client_group_path(@scheme, check_answers: true) } %>
<% end %>
<% if @scheme.has_other_client_group == "Yes" %>
<% @scheme.check_secondary_client_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_secondary_client_group_path(@scheme, check_answers: true) } %>
<% end %>
<% end %>
<% @scheme.check_support_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_support_path(@scheme, check_answers: true) } %>
<% end %>
</dl>
</div>
</div>

5
app/views/schemes/support.html.erb

@ -37,7 +37,12 @@
<%= f.hidden_field :page, value: "support" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<%= f.govuk_submit "Save changes" %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

3
spec/factories/scheme.rb

@ -4,7 +4,7 @@ FactoryBot.define do
sensitive { Faker::Number.within(range: 0..1) }
registered_under_care_act { 1 }
support_type { [0, 2, 3, 4, 5].sample }
scheme_type { 0 }
scheme_type { 4 }
arrangement_type { "D" }
intended_stay { %w[M P S V X].sample }
primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
@ -13,6 +13,7 @@ FactoryBot.define do
owning_organisation { FactoryBot.create(:organisation) }
confirmed { true }
created_at { Time.zone.local(2021, 4, 1) }
total_units { 2 }
trait :export do
sensitive { 1 }
registered_under_care_act { 1 }

24
spec/features/schemes_spec.rb

@ -390,7 +390,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "does not let you change details other than the name, confidential information and housing stock owner" do
assert_selector "a", text: "Change", count: 3
assert_selector "a", text: "Change", count: 11
end
end
end
@ -621,7 +621,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "displays change links" do
assert_selector "a", text: "Change", count: 11
assert_selector "a", text: "Change", count: 10
end
it "allows changing details questions" do
@ -629,7 +629,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
fill_in "Scheme name", with: "Example"
click_button "Save and continue"
click_button "Save changes"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example"
@ -645,7 +645,7 @@ RSpec.describe "Schemes scheme Features" do
it "indicates if the scheme is not complete" do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true", match: :first)
choose "Yes"
click_button "Save and continue"
click_button "Save changes"
visit("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content("You didn’t answer this question")
end
@ -687,7 +687,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "displays change links" do
assert_selector "a", text: "Change", count: 12
assert_selector "a", text: "Change", count: 11
end
it "allows changing details questions" do
@ -695,7 +695,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
fill_in "Scheme name", with: "Example"
click_button "Save and continue"
click_button "Save changes"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example"
@ -711,14 +711,14 @@ RSpec.describe "Schemes scheme Features" do
it "keeps the provider answer when switching between other provider options" do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true", match: :first)
choose "Yes"
click_button "Save and continue"
click_button "Save changes"
expect(find_field("Offenders and people at risk of offending")).to be_checked
end
it "does not display the answer if it's changed to the same support provider" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
choose "The same organisation that owns the housing stock"
click_button "Save and continue"
click_button "Save changes"
expect(page).not_to have_content("Organisation providing support")
end
end
@ -766,11 +766,11 @@ RSpec.describe "Schemes scheme Features" do
context "when I click to change scheme name" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/edit-name", match: :first)
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
end
it "shows available fields to edit" do
expect(page).to have_current_path("/schemes/#{scheme.id}/edit-name")
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
expect(page).to have_content "Scheme details"
end
@ -784,7 +784,7 @@ RSpec.describe "Schemes scheme Features" do
it "lets me see amended details on the check answers page" do
expect(page).to have_content "FooBar"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
assert_selector "a", text: "Change", count: 3
assert_selector "a", text: "Change", count: 11
end
it "lets me save the scheme" do
@ -1021,7 +1021,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "does not let you change details other than the name, confidential information and housing stock owner" do
assert_selector "a", text: "Change", count: 3
assert_selector "a", text: "Change", count: 11
end
end
end

228
spec/helpers/schemes_helper_spec.rb

@ -88,234 +88,6 @@ RSpec.describe SchemesHelper do
end
include TagHelper
describe "display_scheme_attributes" do
let(:owning_organisation) { FactoryBot.create(:organisation, name: "Acme LTD Owning") }
let(:managing_organisation) { FactoryBot.create(:organisation, name: "Acme LTD Managing") }
let!(:scheme) do
FactoryBot.create(:scheme,
service_name: "Test service_name",
sensitive: 0,
scheme_type: 7,
registered_under_care_act: 3,
owning_organisation:,
arrangement_type: "V",
primary_client_group: "S",
has_other_client_group: 1,
secondary_client_group: "I",
support_type: 4,
intended_stay: "P",
created_at: Time.zone.local(2022, 4, 1))
end
let!(:scheme_where_managing_organisation_is_owning_organisation) { FactoryBot.create(:scheme, arrangement_type: "D") }
let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) }
context "when scheme has no locations" do
it "returns correct display attributes" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Status", value: status_tag(:incomplete) },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
end
context "when scheme has a location" do
before do
FactoryBot.create(:location, scheme:)
end
it "returns correct display attributes" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Status", value: status_tag(:active) },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
context "when the managing organisation is the owning organisation" do
it "doesn't show the organisation providing support" do
attributes = display_scheme_attributes(scheme_where_managing_organisation_is_owning_organisation).find { |x| x[:name] == "Organisation providing support" }
expect(attributes).to be_nil
end
end
context "when viewing availability" do
context "with no deactivations" do
it "displays current collection start date as availability date if created_at is later than collection start date" do
scheme.update!(created_at: Time.zone.local(2022, 4, 16))
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021")
end
end
context "with previous deactivations" do
context "and all reactivated deactivations" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022\nActive from 28 September 2022")
end
end
context "and non reactivated deactivation" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022")
end
end
end
context "with out of order deactivations" do
context "and all reactivated deactivations" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 18 June 2022 to 23 September 2022\nDeactivated on 24 September 2022\nActive from 28 September 2022")
end
end
context "and one non reactivated deactivation" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022")
end
end
end
context "with multiple out of order deactivations" do
context "and one non reactivated deactivation" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022 to 23 October 2022\nDeactivated on 24 October 2022\nActive from 28 October 2022")
end
end
end
context "with intersecting deactivations" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), scheme:)
Timecop.return
scheme.reload
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
end
end
end
end
context "when scheme has no secondary client group" do
before do
scheme.update!(has_other_client_group: 0)
end
it "returns correct display attributes" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Status", value: status_tag(:incomplete) },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "No" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
end
context "when scheme was merged from another organisation" do
before do
FactoryBot.create(:location, scheme:)
scheme.startdate = Time.zone.local(2023, 1, 5)
end
it "returns correct availability" do
expect(display_scheme_attributes(scheme)).to include({ name: "Availability", value: "Active from 5 January 2023" })
end
end
end
describe "edit_scheme_text" do
let(:parent_organisation) { FactoryBot.create(:organisation, name: "Parent") }
let(:child_organisation) { FactoryBot.create(:organisation, name: "Child") }

Loading…
Cancel
Save