-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP-4512: Add linking case invitation
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
1 parent
1010b74
commit e000fdc
Showing
8 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/controllers/providers/linking_case_invitations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/views/providers/linking_case_invitations/show.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
spec/requests/providers/linking_case_invitations_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |