diff --git a/app/controllers/assessor_interface/application_forms_controller.rb b/app/controllers/assessor_interface/application_forms_controller.rb index 07a0c0d04e..6df1b0ef26 100644 --- a/app/controllers/assessor_interface/application_forms_controller.rb +++ b/app/controllers/assessor_interface/application_forms_controller.rb @@ -32,6 +32,27 @@ def status @view_object = show_view_object end + def edit + authorize [:assessor_interface, application_form] + + @form = ApplicationFormNameForm.new + end + + def update + authorize [:assessor_interface, application_form] + + @form = + ApplicationFormNameForm.new( + form_params.merge(application_form:, user: current_staff), + ) + + if @form.save + redirect_to [:assessor_interface, application_form] + else + render :edit, status: :unprocessable_entity + end + end + def withdraw authorize [:assessor_interface, application_form] end @@ -65,5 +86,12 @@ def show_view_object def application_form @application_form ||= show_view_object.application_form end + + def form_params + params.require(:assessor_interface_application_form_name_form).permit( + :given_names, + :family_name, + ) + end end end diff --git a/app/views/assessor_interface/application_forms/edit.html.erb b/app/views/assessor_interface/application_forms/edit.html.erb new file mode 100644 index 0000000000..19eaf45ce6 --- /dev/null +++ b/app/views/assessor_interface/application_forms/edit.html.erb @@ -0,0 +1,34 @@ +<% title = "Change details for ‘#{application_form_full_name(@application_form)}’" %> + +<% content_for :page_title, "#{"Error: " if @form.errors.any?}#{title}" %> +<% content_for :back_link_url, assessor_interface_application_form_path(@application_form) %> + +<%= form_with model: @form, url: [:assessor_interface, @application_form], method: :put do |f| %> + <%= f.govuk_error_summary %> + +
Use this form to change one or more of the names.
+ + <%= f.govuk_text_field :given_names %> + <%= f.govuk_text_field :family_name %> + + <%= f.govuk_submit do %> + <%= govuk_link_to "Cancel", [:assessor_interface, @application_form] %> + <% end %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 0f4ba1bd7d..7579986f51 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,9 +14,7 @@ namespace :assessor_interface, path: "/assessor" do root to: redirect("/assessor/applications") - resources :application_forms, - path: "/applications", - only: %i[index show destroy] do + resources :application_forms, path: "/applications", except: :new do collection do post "filters/apply", to: "application_forms#apply_filters" get "filters/clear", to: "application_forms#clear_filters" diff --git a/spec/support/autoload/page_objects/assessor_interface/edit_application.rb b/spec/support/autoload/page_objects/assessor_interface/edit_application.rb new file mode 100644 index 0000000000..a690df1cd8 --- /dev/null +++ b/spec/support/autoload/page_objects/assessor_interface/edit_application.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module PageObjects + module AssessorInterface + class EditApplication < SitePrism::Page + set_url "/assessor/applications/{application_form_id}/edit" + + section :form, "form" do + element :given_names_field, + "#assessor-interface-application-form-name-form-given-names-field" + element :family_name_field, + "#assessor-interface-application-form-name-form-family-name-field" + element :submit_button, ".govuk-button" + end + end + end +end diff --git a/spec/support/page_helpers.rb b/spec/support/page_helpers.rb index 935f59f849..f67c1e11ab 100644 --- a/spec/support/page_helpers.rb +++ b/spec/support/page_helpers.rb @@ -27,6 +27,11 @@ def assessor_assessment_section_page PageObjects::AssessorInterface::AssessmentSection.new end + def assessor_edit_application_page + @assessor_edit_application_page ||= + PageObjects::AssessorInterface::EditApplication.new + end + def assessor_edit_professional_standing_request_location_page @assessor_edit_professional_standing_request_location_page ||= PageObjects::AssessorInterface::EditProfessionalStandingRequestLocation.new diff --git a/spec/system/assessor_interface/change_application_form_name_spec.rb b/spec/system/assessor_interface/change_application_form_name_spec.rb index e69de29bb2..0bbc3d7190 100644 --- a/spec/system/assessor_interface/change_application_form_name_spec.rb +++ b/spec/system/assessor_interface/change_application_form_name_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Assessor change application form name", type: :system do + before do + given_the_service_is_open + given_there_is_an_application_form + end + + it "checks manage applications permission" do + given_i_am_authorized_as_a_user(assessor) + + when_i_visit_the(:assessor_edit_application_page, application_form_id:) + then_i_see_the_forbidden_page + end + + it "allows changing application form name" do + given_i_am_authorized_as_a_user(manager) + + when_i_visit_the(:assessor_application_page, application_id:) + then_i_see_the(:assessor_application_page) + + when_i_click_on_change_name + then_i_see_the(:assessor_edit_application_page, application_form_id:) + + when_i_fill_in_the_name + then_i_see_the(:assessor_application_page, application_id:) + end + + def given_there_is_an_application_form + application_form + end + + def when_i_click_on_change_name + assessor_application_page + .summary_list + .find_row(key: "Name") + .actions + .link + .click + end + + def when_i_fill_in_the_name + assessor_edit_application_page.form.given_names_field.fill_in with: + "New given names" + assessor_edit_application_page.form.family_name_field.fill_in with: + "New family name" + assessor_edit_application_page.form.submit_button.click + end + + def application_form + @application_form ||= + create( + :application_form, + :submitted, + :with_personal_information, + :with_assessment, + ) + end + + delegate :id, to: :application_form, prefix: true + alias_method :application_id, :application_form_id + + def assessor + create(:staff, :confirmed, :with_award_decline_permission) + end + + def manager + create(:staff, :confirmed, :with_change_name_permission) + end +end