Skip to content

Commit

Permalink
Add ability to archive suitability records
Browse files Browse the repository at this point in the history
This makes it possible to archive (and unarchive) a suitability record
having implemented the design.
  • Loading branch information
thomasleese committed Jul 19, 2024
1 parent 854df6e commit a67c846
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ def edit
end

def update
if suitability_record.archived?
suitability_record.update!(
archived_at: nil,
archived_by: nil,
archive_note: "",
)
redirect_to [:edit, :assessor_interface, suitability_record]
return
end

@form =
SuitabilityRecordForm.new(
form_params.merge(suitability_record:, user: current_staff),
Expand All @@ -71,6 +81,23 @@ def update
end
end

def archive
@form = ArchiveSuitabilityRecordForm.new(suitability_record:)
end

def destroy
@form =
ArchiveSuitabilityRecordForm.new(
archive_form_params.merge(suitability_record:, user: current_staff),
)

if @form.save
redirect_to action: :index
else
render :archive, status: :unprocessable_entity
end
end

private

def form_params
Expand All @@ -85,6 +112,12 @@ def form_params
)
end

def archive_form_params
params.require(
:assessor_interface_archive_suitability_record_form,
).permit(:note)
end

def suitability_record
@suitability_record ||=
authorize [:assessor_interface, SuitabilityRecord.find(params[:id])]
Expand Down
16 changes: 16 additions & 0 deletions app/views/assessor_interface/suitability_records/archive.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% title = "Archive suitability record for #{@suitability_record.name}" %>

<% content_for :page_title, title %>
<% content_for :back_link_url, assessor_interface_suitability_records_path %>

<%= form_with model: @form, url: [:assessor_interface, @suitability_record], method: :delete do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-l"><%= title %></h1>

<%= f.govuk_text_area :note %>

<%= f.govuk_submit "Archive record" do %>
<%= govuk_link_to "Cancel", %i[assessor_interface suitability_records] %>
<% end %>
<% end %>
25 changes: 21 additions & 4 deletions app/views/assessor_interface/suitability_records/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,30 @@
row.with_key { "Suitability reasons" }
row.with_value { @suitability_record.note }
end

if @suitability_record.archived?
summary_list.with_row do |row|
row.with_key { "Date archived" }
row.with_value { @suitability_record.archived_at.to_fs }
end

summary_list.with_row do |row|
row.with_key { "Reason for archiving" }
row.with_value { @suitability_record.archive_note }
end
end
end %>

<h2 class="govuk-heading-m">Update record</h2>
<% if @suitability_record.archived? %>
<%= f.govuk_submit "Set to active", secondary: true %>
<% else %>
<h2 class="govuk-heading-m">Update record</h2>

<%= render "form_fields", f: %>
<%= render "form_fields", f: %>

<%= f.govuk_submit "Update record" do %>
<%= govuk_link_to "Cancel", %i[assessor_interface suitability_records] %>
<%= f.govuk_submit "Update record" do %>
<%= govuk_button_link_to "Archive record", [:archive, :assessor_interface, @suitability_record], secondary: true, id: "app-archive-button" %>
<%= govuk_link_to "Cancel", %i[assessor_interface suitability_records] %>
<% end %>
<% end %>
<% end %>
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@
to: "uploads#show",
as: :application_form_document_upload

resources :suitability_records,
path: "/suitability-records",
only: %i[index new create edit update]
resources :suitability_records, path: "/suitability-records" do
get "archive", on: :member
end
end

namespace :eligibility_interface, path: "/eligibility" do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module PageObjects
module AssessorInterface
class ArchiveSuitabilityRecord < SitePrism::Page
set_url "/assessor/suitability-records/{id}/archive"

section :form, "form" do
element :note_field,
"#assessor-interface-archive-suitability-record-form-note-field"
element :submit_button, ".govuk-button:not(.govuk-button--secondary)"
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class EditSuitabilityRecord < SuitabilityRecordFormPage
set_url "/assessor/suitability-records/{id}/edit"

element :heading, "h1"

element :archive_button, "#app-archive-button"
end
end
end
5 changes: 5 additions & 0 deletions spec/support/page_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def assessor_applications_page
PageObjects::AssessorInterface::Applications.new
end

def assessor_archive_suitability_record_page
@assessor_archive_suitability_record_page ||=
PageObjects::AssessorInterface::ArchiveSuitabilityRecord.new
end

def assessor_assessment_recommendation_review_page
@assessor_assessment_recommendation_review_page ||=
PageObjects::AssessorInterface::AssessmentRecommendationReview.new
Expand Down
19 changes: 18 additions & 1 deletion spec/system/assessor_interface/suitability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
then_i_see_the_suitability_records
end

it "create and edit suitability records" do
it "create and edit and archive suitability records" do
given_i_am_authorized_as_a_user(assessor)

when_i_visit_the(:assessor_suitability_records_page)
Expand All @@ -31,6 +31,13 @@
when_i_fill_in_the_fields
and_i_submit_the_form
then_i_see_the_suitability_records

when_i_click_on_the_suitability_record
then_i_see_the(:assessor_edit_suitability_record_page)

when_i_click_archive
then_i_see_the(:assessor_archive_suitability_record_page)
and_i_submit_the_archive_form
end

def given_suitability_is_enabled
Expand Down Expand Up @@ -79,6 +86,16 @@ def when_i_click_on_the_suitability_record
assessor_suitability_records_page.records.first.heading.link.click
end

def when_i_click_archive
assessor_edit_suitability_record_page.archive_button.click
end

def and_i_submit_the_archive_form
form = assessor_archive_suitability_record_page.form
form.note_field.fill_in with: "A note."
form.submit_button.click
end

def assessor
@assessor ||= create(:staff, :with_assess_permission)
end
Expand Down

0 comments on commit a67c846

Please sign in to comment.