From 5205e1d7693ffc37dae20d62f6957e23c608e262 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 17 Nov 2022 13:54:06 +0000 Subject: [PATCH] route deactivated scheme to reactivation page --- app/controllers/locations_controller.rb | 4 ++ app/views/locations/show.html.erb | 2 +- config/routes.rb | 1 + .../factories/location_deactivation_period.rb | 1 + spec/features/schemes_spec.rb | 42 ++++++++++++++++++- 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index b9132305f..16344d27c 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -49,6 +49,10 @@ class LocationsController < ApplicationController redirect_to scheme_location_path(@scheme, @location) end + def new_reactivation + render "toggle_active", locals: { action: "reactivate" } + end + def reactivate render "toggle_active", locals: { action: "reactivate" } end diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index 52607d582..d9f0fc09e 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -27,6 +27,6 @@ <% if @location.active? %> <%= govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(scheme_id: @scheme.id, location_id: @location.id), warning: true %> <% else %> - <%= govuk_button_link_to "Reactivate this location", scheme_location_reactivate_path(scheme_id: @scheme.id, location_id: @location.id) %> + <%= govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(scheme_id: @scheme.id, location_id: @location.id) %> <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index f90f70534..97c7c56bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,6 +61,7 @@ Rails.application.routes.draw do get "new-deactivation", to: "locations#new_deactivation" get "deactivate-confirm", to: "locations#deactivate_confirm" get "reactivate", to: "locations#reactivate" + get "new-reactivation", to: "locations#new_reactivation" patch "new-deactivation", to: "locations#new_deactivation" patch "deactivate", to: "locations#deactivate" end diff --git a/spec/factories/location_deactivation_period.rb b/spec/factories/location_deactivation_period.rb index 6a3ab70c3..7d2355ca2 100644 --- a/spec/factories/location_deactivation_period.rb +++ b/spec/factories/location_deactivation_period.rb @@ -1,5 +1,6 @@ FactoryBot.define do factory :location_deactivation_period do + deactivation_date { Time.zone.local(2022, 4, 1) } reactivation_date { nil } end end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 67660b8ad..59f7b8008 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -693,8 +693,10 @@ RSpec.describe "Schemes scheme Features" do context "when I click to see individual scheme" do let(:scheme) { schemes.first } let!(:location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) } + let!(:deactivated_location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) } - before do + before do + deactivated_location.location_deactivation_periods << FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4)) click_link(scheme.service_name) end @@ -752,6 +754,44 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_current_path("/schemes/#{scheme.id}/locations") end + + context "when location is incative" do + context "and I click to view the location" do + before do + click_link(deactivated_location.postcode) + end + + it "displays details about the selected location" do + expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{deactivated_location.id}") + expect(page).to have_content(deactivated_location.postcode) + expect(page).to have_content(deactivated_location.location_admin_district) + expect(page).to have_content(deactivated_location.name) + expect(page).to have_content(deactivated_location.units) + expect(page).to have_content(deactivated_location.type_of_unit) + expect(page).to have_content(deactivated_location.mobility_type) + expect(page).to have_content(deactivated_location.location_code) + expect(page).to have_content("Active from 4 April 2022 to 3 June 2022 Deactivated on 4 June 2022") + expect(page).to have_content("Deactivated") + end + + it "allows to reactivate a location" do + click_link("Reactivate this location") + expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{deactivated_location.id}/new-reactivation") + end + + context "when I press the back button" do + before do + click_link "Back" + end + + it "I see location details" do + expect(page).to have_content scheme.locations.first.id + expect(page).to have_current_path("/schemes/#{scheme.id}/locations") + end + end + end + end + context "when I click to change location name" do before do click_link(location.postcode)