Browse Source

Display active status is location/scheme deactivation is in more than 6 months

pull/1701/head
Kat 3 years ago
parent
commit
3eeb3f60e0
  1. 2
      app/helpers/locations_helper.rb
  2. 2
      app/helpers/schemes_helper.rb
  3. 8
      app/helpers/tag_helper.rb
  4. 4
      app/models/location.rb
  5. 4
      app/models/scheme.rb
  6. 2
      app/views/locations/index.html.erb
  7. 2
      app/views/locations/show.html.erb
  8. 2
      app/views/schemes/_scheme_list.html.erb
  9. 13
      spec/requests/locations_controller_spec.rb
  10. 12
      spec/requests/schemes_controller_spec.rb

2
app/helpers/locations_helper.rb

@ -69,7 +69,7 @@ module LocationsHelper
end
def toggle_location_link(location)
return govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(location.scheme, location), warning: true if location.active?
return govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(location.scheme, location), warning: true if location.active? || location.deactivates_in_more_than_6_months?
return govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(location.scheme, location) if location.deactivated?
end

2
app/helpers/schemes_helper.rb

@ -40,7 +40,7 @@ module SchemesHelper
end
def toggle_scheme_link(scheme)
return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active?
return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active? || scheme.deactivates_in_more_than_6_months?
return govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(scheme) if scheme.deactivated?
end

8
app/helpers/tag_helper.rb

@ -27,11 +27,13 @@ module TagHelper
deactivated: "grey",
}.freeze
def status_tag(status, classes = [])
def status_tag(resource, classes = [])
display_status = resource.status
display_status = :active if resource.deactivates_in_more_than_6_months?
govuk_tag(
classes:,
colour: COLOUR[status.to_sym],
text: TEXT[status.to_sym],
colour: COLOUR[display_status.to_sym],
text: TEXT[display_status.to_sym],
)
end
end

4
app/models/location.rb

@ -108,6 +108,10 @@ class Location < ApplicationRecord
status == :reactivating_soon
end
def deactivates_in_more_than_6_months?
status == :deactivating_soon && open_deactivation.present? && open_deactivation.deactivation_date > 6.months.from_now
end
def validate_postcode
if !postcode&.match(POSTCODE_REGEXP)
error_message = I18n.t("validations.postcode")

4
app/models/scheme.rb

@ -242,4 +242,8 @@ class Scheme < ApplicationRecord
def deactivated?
status == :deactivated
end
def deactivates_in_more_than_6_months?
status == :deactivating_soon && open_deactivation.present? && open_deactivation.deactivation_date > 6.months.from_now
end
end

2
app/views/locations/index.html.erb

@ -54,7 +54,7 @@
end), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.name) %>
<% row.cell(text: location.id) %>
<% row.cell(text: status_tag(location.status)) %>
<% row.cell(text: status_tag(location)) %>
<% end %>
<% end %>
<% end %>

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

@ -15,7 +15,7 @@
<% display_location_attributes(@location).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% row.value { attr[:attribute].eql?("status") ? status_tag(attr[:value]) : details_html(attr) } %>
<% row.value { attr[:attribute].eql?("status") ? status_tag(@location) : details_html(attr) } %>
<% if LocationPolicy.new(current_user, @location).update? %>
<% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %>
<% end %>

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

@ -17,7 +17,7 @@
<% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: scheme.id_to_display) %>
<% row.cell(text: scheme.locations&.count) %>
<% row.cell(text: status_tag(scheme.status)) %>
<% row.cell(text: status_tag(scheme)) %>
<% end %>
<% end %>
<% end %>

13
spec/requests/locations_controller_spec.rb

@ -1673,6 +1673,19 @@ RSpec.describe LocationsController, type: :request do
expect(response).to have_http_status(:ok)
expect(page).not_to have_link("Reactivate this location")
expect(page).not_to have_link("Deactivate this location")
expect(page).to have_content("Deactivating soon")
end
end
context "with location that's deactivating in more than 6 months" do
let(:location_deactivation_period) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 12), location:) }
it "does render toggle location link" do
expect(response).to have_http_status(:ok)
expect(page).not_to have_link("Reactivate this location")
expect(page).to have_link("Deactivate this location")
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

12
spec/requests/schemes_controller_spec.rb

@ -330,6 +330,18 @@ RSpec.describe SchemesController, type: :request do
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:) }
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
context "when coordinator attempts to see scheme belonging to a parent organisation" do

Loading…
Cancel
Save