Skip to content

Commit

Permalink
AP-4512: Add linking case invitation
Browse files Browse the repository at this point in the history
Add controller, form, view and spec for page which asks
user if they would like to link their application to
another application
  • Loading branch information
agoldstone93 committed Nov 2, 2023
1 parent 1010b74 commit e000fdc
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/controllers/providers/linking_case_invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Providers
class LinkingCaseInvitationsController < ProviderBaseController
def show
@form = LinkingCase::InvitationForm.new(model: legal_aid_application)
end

def update
@form = LinkingCase::InvitationForm.new(form_params)

render :show unless save_continue_or_draft(@form)
end

private

def form_params
merge_with_model(legal_aid_application) do
next {} unless params[:legal_aid_application]

params.require(:legal_aid_application).permit(:link_case)
end
end
end
end
9 changes: 9 additions & 0 deletions app/forms/linking_case/invitation_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module LinkingCase
class InvitationForm < BaseForm
form_for LegalAidApplication

attr_accessor :link_case

validates :link_case, presence: true, unless: proc { draft? || link_case.present? }
end
end
4 changes: 4 additions & 0 deletions app/services/flow/flows/provider_start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ProviderStart < FlowSteps
end,
check_answers: :check_provider_answers,
},
linking_case_invitations: {
path: ->(application) { urls.providers_legal_aid_application_linking_case_invitation_path(application) },
forward: :address_lookups,
},
address_lookups: {
path: ->(application) { urls.providers_legal_aid_application_address_lookup_path(application) },
forward: :address_selections,
Expand Down
18 changes: 18 additions & 0 deletions app/views/providers/linking_case_invitations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%= form_with(
url: providers_legal_aid_application_linking_case_invitation_path,
model: @form,
method: :patch,
local: true,
) do |form| %>

<%= page_template page_title: t(".heading"),
template: :basic,
form: do %>

<%= form.govuk_collection_radio_buttons :link_case, yes_no_options, :value, :label,
legend: { text: t(".heading"), size: "xl", tag: "h1" },
hint: { text: t(".hint") } %>

<%= next_action_buttons(form:, show_draft: true) %>
<% end %>
<% end %>
2 changes: 2 additions & 0 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ en:
date_not_in_range: "The date you used delegated functions cannot be before %{months}"
client_declaration_confirmed:
accepted: Confirm this information is correct and that you'll get a signed declaration
link_case:
blank: Select yes if you would like to link an application to your application
other_assets_declaration:
attributes:
valuable_items_value:
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ en:
h1-heading: Is %{office_code} your office account number?
error: Select yes if this is the account number of the office handling this application
no_another_office: No, another office is handling this application
linking_case_invitations:
show:
heading: Do you want to link an application to your application?
hint: Guidance about linking cases
proceeding_merits_task:
linked_children:
show:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
resource :in_scope_of_laspo, only: %i[show update], controller: "application_merits_task/in_scope_of_laspos"
resource :nature_of_urgencies, only: %i[show update], controller: "application_merits_task/nature_of_urgencies"
resource :merits_task_list, only: %i[show update]
resource :linking_case_invitation, only: %i[show update]

resource :uploaded_evidence_collection, only: %i[show update destroy] do
get "/list", to: "uploaded_evidence_collections#list"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require "rails_helper"

RSpec.describe Providers::LinkingCaseInvitationsController do
let(:legal_aid_application) { create(:legal_aid_application) }
let(:provider) { legal_aid_application.provider }

before { login_as provider }

describe "GET /providers/applications/:legal_aid_application_id/linking_case_invitation" do
it "renders page with expected heading" do
get providers_legal_aid_application_linking_case_invitation_path(legal_aid_application)
expect(response).to have_http_status(:ok)
expect(page).to have_css("h1", text: "Do you want to link an application to your application?")
end
end

describe "PATCH /providers/applications/:legal_aid_application_id/linking_case_invitation" do
before { patch providers_legal_aid_application_linking_case_invitation_path(legal_aid_application), params: }

context "when form submitted with Save as draft button" do
let(:params) { { legal_aid_application: { link_case: "" }, draft_button: "Save and come back later" } }

it "redirects to the list of applications" do
expect(response).to redirect_to providers_legal_aid_applications_path
end
end

context "when no chosen" do
let(:params) { { legal_aid_application: { link_case: "false" } } }

it "redirects to the address_lookup page" do
expect(response).to redirect_to(providers_legal_aid_application_address_lookup_path(legal_aid_application))
end
end

context "when no answer chosen" do
let(:params) { { legal_aid_application: { link_case: "" }, continue_button: "Save and continue" } }

it "stays on the page if there is a validation error" do
expect(response).to have_http_status(:ok)
expect(page).to have_error_message("Select yes if you would like to link an application to your application")
end
end

def have_error_message(text)
have_css(".govuk-error-summary__list > li", text:)
end
end
end

0 comments on commit e000fdc

Please sign in to comment.