Browse Source

Use date_picker in scheme deactivations

pull/2891/head
Kat 4 months ago
parent
commit
eecd08eaa9
  1. 8
      app/controllers/schemes_controller.rb
  2. 10
      app/views/schemes/toggle_active.html.erb
  3. 16
      spec/requests/schemes_controller_spec.rb

8
app/controllers/schemes_controller.rb

@ -356,13 +356,11 @@ private
return return
elsif params[:scheme_deactivation_period]["#{key}_type".to_sym] == "default" elsif params[:scheme_deactivation_period]["#{key}_type".to_sym] == "default"
return FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period return FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
elsif params[:scheme_deactivation_period][key.to_sym].present?
return params[:scheme_deactivation_period][key.to_sym]
end end
day = params[:scheme_deactivation_period]["#{key}(3i)"] day = params[:scheme_deactivation_period][key.to_s].split("/")[0]
month = params[:scheme_deactivation_period]["#{key}(2i)"] month = params[:scheme_deactivation_period][key.to_s].split("/")[1]
year = params[:scheme_deactivation_period]["#{key}(1i)"] year = params[:scheme_deactivation_period][key.to_s].split("/")[2]
return nil if [day, month, year].any?(&:blank?) return nil if [day, month, year].any?(&:blank?)
Time.zone.local(year.to_i, month.to_i, day.to_i) if Date.valid_date?(year.to_i, month.to_i, day.to_i) Time.zone.local(year.to_i, month.to_i, day.to_i) if Date.valid_date?(year.to_i, month.to_i, day.to_i)

10
app/views/schemes/toggle_active.html.erb

@ -25,10 +25,14 @@
"other", "other",
label: { text: "For tenancies starting after a certain date" }, label: { text: "For tenancies starting after a certain date" },
**basic_conditional_html_attributes({ "deactivation_date" => %w[other] }, "scheme") do %> **basic_conditional_html_attributes({ "deactivation_date" => %w[other] }, "scheme") do %>
<%= f.govuk_date_field date_question(action), <%= render partial: "components/date_picker", locals: {
resource: @scheme,
question_id: date_question(action),
legend: { text: "Date", size: "m" }, legend: { text: "Date", size: "m" },
hint: { text: "For example, 27 3 2025" }, resource_type: "scheme",
width: 20 %> hint: "For example, 27/3/2025",
f:,
} %>
<% end %> <% end %>
<% end %> <% end %>
<%= f.govuk_submit "Continue" %> <%= f.govuk_submit "Continue" %>

16
spec/requests/schemes_controller_spec.rb

@ -2749,7 +2749,7 @@ RSpec.describe SchemesController, type: :request do
end end
context "with other date" do context "with other date" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "10/10/2022" } } }
context "and affected logs" do context "and affected logs" do
it "redirects to the confirmation page" do it "redirects to the confirmation page" do
@ -2901,7 +2901,7 @@ RSpec.describe SchemesController, type: :request do
end end
context "when invalid date is entered" do context "when invalid date is entered" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "10/44/2022" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_content) expect(response).to have_http_status(:unprocessable_content)
@ -2910,7 +2910,7 @@ RSpec.describe SchemesController, type: :request do
end end
context "when the date is entered is before the beginning of current collection window" do context "when the date is entered is before the beginning of current collection window" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "10/4/2020" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_content) expect(response).to have_http_status(:unprocessable_content)
@ -2919,7 +2919,7 @@ RSpec.describe SchemesController, type: :request do
end end
context "when the day is not entered" do context "when the day is not entered" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "/2/2022" } } }
it "displays page with an error message" do it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_content) expect(response).to have_http_status(:unprocessable_content)
@ -2928,7 +2928,7 @@ RSpec.describe SchemesController, type: :request do
end end
context "when the month is not entered" do context "when the month is not entered" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "2//2022" } } }
it "displays page with an error message" do it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_content) expect(response).to have_http_status(:unprocessable_content)
@ -2937,7 +2937,7 @@ RSpec.describe SchemesController, type: :request do
end end
context "when the year is not entered" do context "when the year is not entered" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "2/2/" } } }
it "displays page with an error message" do it "displays page with an error message" do
expect(response).to have_http_status(:unprocessable_content) expect(response).to have_http_status(:unprocessable_content)
@ -2947,7 +2947,7 @@ RSpec.describe SchemesController, type: :request do
context "when there is an earlier open deactivation" do context "when there is an earlier open deactivation" do
let(:deactivation_date) { Time.zone.local(2022, 10, 10) } let(:deactivation_date) { Time.zone.local(2022, 10, 10) }
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "8", "deactivation_date(2i)": "9", "deactivation_date(1i)": "2023" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "8/9/2023" } } }
let(:add_deactivations) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 5), reactivation_date: nil, scheme:) } let(:add_deactivations) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 5), reactivation_date: nil, scheme:) }
before do before do
@ -2968,7 +2968,7 @@ RSpec.describe SchemesController, type: :request do
context "when there is a later open deactivation" do context "when there is a later open deactivation" do
let(:deactivation_date) { Time.zone.local(2022, 10, 10) } let(:deactivation_date) { Time.zone.local(2022, 10, 10) }
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "8", "deactivation_date(2i)": "9", "deactivation_date(1i)": "2022" } } } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "8/9/2022" } } }
let(:add_deactivations) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 5), reactivation_date: nil, scheme:) } let(:add_deactivations) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 5), reactivation_date: nil, scheme:) }
it "redirects to the confirmation page" do it "redirects to the confirmation page" do

Loading…
Cancel
Save