Browse Source

feat: update some tests

pull/1958/head
natdeanlewissoftwire 3 years ago
parent
commit
0ab6e716e4
  1. 2
      spec/features/schemes_spec.rb
  2. 24
      spec/helpers/schemes_helper_spec.rb
  3. 6
      spec/requests/locations_controller_spec.rb
  4. 68
      spec/requests/schemes_controller_spec.rb

2
spec/features/schemes_spec.rb

@ -1069,7 +1069,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")
expect(page).to have_link("Change", href: /schemes\/#{scheme.id}\/edit-name/, count: 2)
expect(page).to have_link("Change", href: /schemes\/#{scheme.id}\/edit-name/, count: 3)
end
end
end

24
spec/helpers/schemes_helper_spec.rb

@ -128,7 +128,7 @@ RSpec.describe SchemesHelper do
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme, support_user)).to eq(attributes)
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
it "returns correct display attributes for a coordinator user" do
@ -139,6 +139,7 @@ RSpec.describe SchemesHelper do
{ 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" },
@ -147,7 +148,7 @@ RSpec.describe SchemesHelper do
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme, coordinator_user)).to eq(attributes)
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
end
@ -173,7 +174,7 @@ RSpec.describe SchemesHelper do
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme, support_user)).to eq(attributes)
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
it "returns correct display attributes for a coordinator user" do
@ -184,6 +185,7 @@ RSpec.describe SchemesHelper do
{ 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" },
@ -192,7 +194,7 @@ RSpec.describe SchemesHelper do
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2021" },
]
expect(display_scheme_attributes(scheme, coordinator_user)).to eq(attributes)
expect(display_scheme_attributes(scheme)).to eq(attributes)
end
context "when the managing organisation is the owning organisation" do
@ -206,7 +208,7 @@ RSpec.describe SchemesHelper 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, support_user).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021")
end
@ -221,7 +223,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
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
@ -235,7 +237,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
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
@ -251,7 +253,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
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
@ -265,7 +267,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
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
@ -282,7 +284,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
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
@ -297,7 +299,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
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

6
spec/requests/locations_controller_spec.rb

@ -179,7 +179,7 @@ RSpec.describe LocationsController, type: :request do
get "/schemes/#{scheme.id}/locations"
end
context "when coordinator attempts to see scheme belonging to a different organisation" do
context "when coordinator attempts to see scheme belonging to a different (and not their parent) organisation" do
let(:another_scheme) { create(:scheme) }
before do
@ -302,8 +302,8 @@ RSpec.describe LocationsController, type: :request do
end
end
it "does not allow adding new locations" do
expect(page).not_to have_button("Add a location")
it "does allow adding new locations" do
expect(page).to have_button("Add a location")
end
end
end

68
spec/requests/schemes_controller_spec.rb

@ -457,7 +457,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(specific_scheme.intended_stay)
end
context "when coordinator attempts to see scheme belonging to a different organisation" do
context "when coordinator attempts to see scheme belonging to a different (and not their parent) organisation" do
let!(:specific_scheme) { create(:scheme) }
it "returns 401" do
@ -474,7 +474,6 @@ RSpec.describe SchemesController, type: :request do
end
context "when looking at scheme details" do
let(:user) { create(:user, :data_coordinator) }
let!(:scheme) { create(:scheme, owning_organisation: user.organisation) }
let(:add_deactivations) { scheme.scheme_deactivation_periods << scheme_deactivation_period }
@ -535,21 +534,68 @@ RSpec.describe SchemesController, type: :request do
context "when coordinator attempts to see scheme belonging to a parent organisation" do
let(:parent_organisation) { create(:organisation) }
let!(:specific_scheme) { create(:scheme, owning_organisation: parent_organisation) }
let(:add_deactivations) { specific_scheme.scheme_deactivation_periods << scheme_deactivation_period }
before do
create(:location, scheme: specific_scheme)
create(:organisation_relationship, parent_organisation:, child_organisation: user.organisation)
Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user
add_deactivations
specific_scheme.save!
get "/schemes/#{specific_scheme.id}"
end
it "shows the scheme" do
expect(page).to have_content(specific_scheme.id_to_display)
after do
Timecop.unfreeze
end
it "does not allow editing the scheme" do
expect(page).not_to have_link("Change")
expect(page).not_to have_content("Reactivate this scheme")
expect(page).not_to have_content("Deactivate this scheme")
context "with active scheme" do
let(:add_deactivations) {}
it "shows the scheme" do
expect(page).to have_content(specific_scheme.id_to_display)
end
it "allows editing" do
expect(page).to have_link("Change")
end
it "renders deactivate this scheme" do
expect(response).to have_http_status(:ok)
expect(page).to have_link("Deactivate this scheme", href: "/schemes/#{specific_scheme.id}/new-deactivation")
end
end
context "with deactivated scheme" do
let(:scheme_deactivation_period) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9), scheme: specific_scheme) }
it "renders reactivate this scheme" do
expect(response).to have_http_status(:ok)
expect(page).to have_link("Reactivate this scheme", href: "/schemes/#{specific_scheme.id}/new-reactivation")
end
end
context "with scheme that's deactivating soon" do
let(:scheme_deactivation_period) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12), scheme: specific_scheme) }
it "does not render toggle scheme link" do
expect(response).to have_http_status(:ok)
expect(page).not_to have_link("Reactivate this scheme")
expect(page).not_to have_link("Deactivate this scheme")
end
end
context "with scheme that's deactivating in more than 6 months" do
let(:scheme_deactivation_period) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2023, 5, 12), scheme: specific_scheme) }
it "does not render toggle scheme link" do
expect(response).to have_http_status(:ok)
expect(page).not_to have_link("Reactivate this scheme")
expect(page).to have_link("Deactivate this scheme")
expect(response.body).not_to include("<strong class=\"govuk-tag govuk-tag--yellow\">Deactivating soon</strong>")
expect(response.body).to include("<strong class=\"govuk-tag govuk-tag--green\">Active</strong>")
end
end
end
@ -1813,7 +1859,7 @@ RSpec.describe SchemesController, type: :request do
expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 2
assert_select "a", text: /Change/, count: 3
end
end
end
@ -1958,7 +2004,7 @@ RSpec.describe SchemesController, type: :request do
expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 2
assert_select "a", text: /Change/, count: 3
end
end
end
@ -2016,7 +2062,7 @@ RSpec.describe SchemesController, type: :request do
expect(response).to have_http_status(:ok)
expect(page).to have_content("Scheme details")
expect(page).to have_content("This scheme contains confidential information")
expect(page).not_to have_content("Which organisation owns the housing stock for this scheme?")
expect(page).to have_content("Which organisation owns the housing stock for this scheme?")
end
context "when attempting to access secondary-client-group scheme page for another organisation" do

Loading…
Cancel
Save