Skip to content

Commit

Permalink
[CPNPQ-2470] Edge case application details page (#2158)
Browse files Browse the repository at this point in the history
* [CPDNPQ-2470] Application in review details page

* [CPDNPQ-2470] Add ability to edit application notes
  • Loading branch information
rwrrll authored Jan 31, 2025
1 parent d702195 commit f5f4542
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module NpqSeparation
module Admin
module Applications
class NotesController < NpqSeparation::AdminController
before_action :set_application

def edit; end

def update
if @application.update(notes_params)
flash[:success] = "Notes updated."
redirect_to npq_separation_admin_application_review_path(@application)
else
render :edit
end
end

private

def notes_params
params.require(:application).permit(:notes)
end

def set_application
@application = Application.find(params[:id])
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def index
@pagy, @applications = pagy(applications, limit: 9)
end

def show
@application = Application.find(params[:id])
end

private

def employment_types
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ def show_otp_code_in_ui(current_env, admin)

tag.p("OTP code: #{admin.otp_hash}")
end

def lead_provider_approval_status_badge(lead_provider_approval_status)
colour = {
pending: "blue",
accepted: "green",
rejected: "red",
}.fetch(lead_provider_approval_status.to_sym, "grey")

govuk_tag(text: lead_provider_approval_status.humanize, colour:)
end
end
17 changes: 17 additions & 0 deletions app/views/npq_separation/admin/applications/notes/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1 class="govuk-heading-xl"><%= @application.user.full_name %></h1>

<%= form_with model: @application, url: npq_separation_admin_applications_notes_path(@application) do |f| %>
<%= f.govuk_error_summary %>

<%=
f.govuk_text_area :notes,
label: { text: 'Notes about changes to this registration', size: "m" },
hint: { text: "Please add the date and your initials when adding a note, and add above any existing notes. Notes are for internal use only." },
max_chars: 1_000
%>

<div class="govuk-button-group">
<%= f.govuk_submit "Update notes" %>
<%= govuk_link_to "Cancel", npq_separation_admin_application_review_path(@application) %>
</div>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
@applications.each do |application|
body.with_row do |row|
row.with_cell do
concat govuk_link_to(application.user.full_name, npq_separation_admin_user_path(application.user))
concat govuk_link_to(application.user.full_name, npq_separation_admin_application_review_path(application))
concat tag.p(application.employment_type.try(:humanize), class: 'govuk-body-s govuk-!-margin-top-1 govuk-!-margin-bottom-1')
concat tag.p(application.employer_name_to_display, class: 'govuk-body-s govuk-!-margin-top-1 govuk-!-margin-bottom-1')
end
row.with_cell(text: boolean_red_green_tag(application.eligible_for_funding))
row.with_cell(text: application.lead_provider_approval_status.humanize)
row.with_cell(text: lead_provider_approval_status_badge(application.lead_provider_approval_status))
row.with_cell(text: application.notes)
row.with_cell(text: application.created_at.to_formatted_s(:govuk_short))
end
Expand Down
129 changes: 129 additions & 0 deletions app/views/npq_separation/admin/applications/reviews/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<h1 class="govuk-heading-l"><%= @application.user.full_name %></h1>

<p class="govuk-body govuk-!-margin-bottom-2">
<strong>Applicant ID:</strong>
<%= @application.user.ecf_id %>
</p>

<p class="govuk-body govuk-!-margin-bottom-2">
<strong>Email:</strong>
<%= @application.user.email %>
</p>

<p class="govuk-body govuk-!-margin-bottom-2">
<strong>Date of birth:</strong>
<%= @application.user.date_of_birth.to_fs(:govuk_short) %>
|
<strong>National Insurance:</strong>
<%= @application.user.national_insurance_number.presence || 'Not provided' %>
</p>

<p class="govuk-body govuk-!-margin-bottom-2">
<strong>TRN:</strong>
<%= @application.user.trn %>
<%= boolean_red_green_tag(@application.user.trn_verified?, @application.user.trn_verified? ? "Validated" : "Not validated") %>
</p>

<p class="govuk-body govuk-!-margin-bottom-6">
<strong>Get an Identity ID:</strong>
<%= @application.user.uid.presence || 'Not set' %>
</p>

<%=
govuk_summary_list(card: { title: "Course details" }) do |sl|
sl.with_row do |row|
row.with_key(text: "NPQ course")
row.with_value(text: "#{@application.course.name} (#{@application.course.short_code})")
end
sl.with_row do |row|
row.with_key(text: "Provider")
row.with_value(text: @application.lead_provider.name)
end
sl.with_row do |row|
row.with_key(text: "Provider approval status")
row.with_value(text: lead_provider_approval_status_badge(@application.lead_provider_approval_status))
end
end
%>

<%=
govuk_summary_list(card: { title: "Funding details" }) do |sl|
sl.with_row do |row|
row.with_key(text: "Eligible for funding")
row.with_value(text: boolean_red_green_tag(@application.eligible_for_funding))
row.with_action(text: "Change", href: new_npq_separation_admin_applications_change_funding_eligibility_path(@application))
end
sl.with_row do |row|
row.with_key(text: "Funded place")
row.with_value(text: boolean_red_green_nil_tag(@application.funded_place))
end
sl.with_row do |row|
row.with_key(text: "Notes")
row.with_value(text: @application.notes)
row.with_action(text: "Change", href: edit_npq_separation_admin_applications_notes_path(@application))
end
end
%>

<%=
govuk_summary_list(card: { title: "Work details" }) do |sl|
sl.with_row do |row|
row.with_key(text: "Works in England")
row.with_value(text: boolean_red_green_tag(@application.teacher_catchment == "england"))
end
sl.with_row do |row|
row.with_key(text: "Work setting")
row.with_value(text: @application.work_setting.try(:humanize))
end
sl.with_row do |row|
row.with_key(text: "Employment type")
row.with_value(text: @application.employment_type.try(:humanize))
end
sl.with_row do |row|
row.with_key(text: "Employer name")
row.with_value(text: @application.employer_name_to_display)
end
sl.with_row do |row|
row.with_key(text: "Role")
row.with_value(text: @application.employment_role)
end
end
%>

<%=
govuk_summary_list(card: { title: "Schedule" }) do |sl|
sl.with_row do |row|
row.with_key(text: "Cohort")
row.with_value(text: @application.cohort.start_year)
end
sl.with_row do |row|
row.with_key(text: "Schedule identifier")
row.with_value(text: @application.schedule.try(:identifier))
end
end
%>

<%=
govuk_summary_list(card: { title: "Registration details" }) do |sl|
sl.with_row do |row|
row.with_key(text: "Participant ID")
row.with_value(text: @application.user.ecf_id)
end
sl.with_row do |row|
row.with_key(text: "Application ID")
row.with_value(text: @application.ecf_id)
end
sl.with_row do |row|
row.with_key(text: "Registration submission date")
row.with_value(text: @application.created_at.to_fs(:govuk_short))
end
sl.with_row do |row|
row.with_key(text: "Last updated date")
row.with_value(text: @application.updated_at.to_fs(:govuk_short))
end
end
%>

<%= govuk_details(summary_text: "View registration as it appears on the Lead Provider API V3") do %>
<pre class="govuk-!-font-size-16" style="overflow: auto;"><code><%= JSON.pretty_generate API::ApplicationSerializer.render_as_hash(@application, view: :v3, root: "data") %></code></pre>
<% end %>
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,14 @@

resources :applications, only: %i[index show] do
collection do
resources :reviews, controller: "applications/reviews", as: "application_reviews", only: %i[index]
resources :reviews, controller: "applications/reviews", as: "application_reviews", only: %i[index show]
end
member do
namespace :applications, path: nil do
resource :revert_to_pending, controller: "revert_to_pending", only: %i[new create]
resource :change_training_status, only: %i[new create]
resource :change_funding_eligibility, only: %i[new create]
resource :notes, only: %i[edit update]
end
end
end
Expand Down
82 changes: 79 additions & 3 deletions spec/features/npq_separation/admin/applications_in_review_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
RSpec.feature "Applications in review", type: :feature do
include Helpers::AdminLogin

let(:cohort_21) { create(:cohort, start_year: 2021) }
let(:cohort_22) { create(:cohort, start_year: 2022) }
let(:cohort_21) { create :cohort, start_year: 2021 }
let(:cohort_22) { create :cohort, start_year: 2022 }

let!(:normal_application) { create(:application) }
let!(:application_for_hospital_school) { create(:application, employment_type: "hospital_school", employer_name: Faker::Company.name, cohort: cohort_21, referred_by_return_to_teaching_adviser: "yes") }
let!(:application_for_hospital_school) { create(:application, :accepted, employment_type: "hospital_school", employer_name: Faker::Company.name, cohort: cohort_21, referred_by_return_to_teaching_adviser: "yes") }
let!(:application_for_la_supply_teacher) { create(:application, employment_type: "local_authority_supply_teacher", cohort: cohort_22, referred_by_return_to_teaching_adviser: "no") }
let!(:application_for_la_virtual_school) { create(:application, employment_type: "local_authority_virtual_school") }
let!(:application_for_lead_mentor) { create(:application, employment_type: "local_authority_virtual_school") }
Expand All @@ -16,6 +16,8 @@
let!(:application_for_rtta_yes) { create(:application, referred_by_return_to_teaching_adviser: "yes") }
let!(:application_for_rtta_no) { create(:application, referred_by_return_to_teaching_adviser: "no") }

let(:serialized_application) { { application: 1 } }

before do
sign_in_as create(:admin)
visit npq_separation_admin_applications_path
Expand Down Expand Up @@ -128,4 +130,78 @@
expect(page).not_to have_text(application_for_hospital_school.user.full_name)
expect(page).not_to have_text(application_for_la_supply_teacher.user.full_name)
end

scenario "viewing an application" do
allow(API::ApplicationSerializer).to receive(:render_as_hash).and_return(serialized_application)
application = application_for_hospital_school.reload
application.user.update! uid: SecureRandom.uuid

click_on application.user.full_name

expect(page).to have_css("h1", text: application.user.full_name)

expect(page).to have_text("Applicant ID: #{application.user.ecf_id}")
expect(page).to have_text("Email: #{application.user.email}")
expect(page).to have_text("Date of birth: #{application.user.date_of_birth.to_fs(:govuk_short)}")
expect(page).to have_text("National Insurance: Not provided")
expect(page).to have_text("TRN: #{application.user.trn} Not validated")
expect(page).to have_text("Get an Identity ID: #{application.user.uid}")

summary_lists = all(".govuk-summary-list")

expect(page).to have_css("h2", text: "Course details")
within(summary_lists[0]) do |summary_list|
expect(summary_list).to have_summary_item("NPQ course", "#{application.course.name} (#{application.course.short_code})")
expect(summary_list).to have_summary_item("Provider", application.lead_provider.name)
expect(summary_list).to have_summary_item("Provider approval status", application.lead_provider_approval_status.humanize)
end

expect(page).to have_css("h2", text: "Funding details")
within(summary_lists[1]) do |summary_list|
expect(summary_list).to have_summary_item("Eligible for funding", "No")
expect(summary_list).to have_summary_item("Funded place", "No")
expect(summary_list).to have_summary_item("Notes", application.notes)
end

expect(page).to have_css("h2", text: "Work details")
within(summary_lists[2]) do |summary_list|
expect(summary_list).to have_summary_item("Works in England", "Yes")
expect(summary_list).to have_summary_item("Work setting", application.work_setting)
expect(summary_list).to have_summary_item("Employment type", application.employment_type.humanize)
expect(summary_list).to have_summary_item("Employer name", application.employer_name)
expect(summary_list).to have_summary_item("Role", application.employment_role)
end

expect(page).to have_css("h2", text: "Schedule")
within(summary_lists[3]) do |summary_list|
expect(summary_list).to have_summary_item("Cohort", application.cohort.start_year)
expect(summary_list).to have_summary_item("Schedule identifier", application.schedule.identifier)
end

expect(page).to have_css("h2", text: "Registration details")
within(summary_lists[4]) do |summary_list|
expect(summary_list).to have_summary_item("Participant ID", application.user.ecf_id)
expect(summary_list).to have_summary_item("Application ID", application.ecf_id)
expect(summary_list).to have_summary_item("Registration submission date", application.created_at.to_fs(:govuk_short))
expect(summary_list).to have_summary_item("Last updated date", application.updated_at.to_fs(:govuk_short))
end

find("summary", text: "View registration as it appears on the Lead Provider API V3").click
expect(page).to have_text JSON.pretty_generate(serialized_application)
end

scenario "updating notes" do
click_on application_for_hospital_school.user.full_name

within(".govuk-summary-list__row", text: "Notes") do
click_on "Change"
end

fill_in "Notes about changes to this registration", with: "Some notes"
click_on "Update notes"

within(".govuk-summary-list__row", text: "Notes") do
expect(page).to have_text("Some notes")
end
end
end

0 comments on commit f5f4542

Please sign in to comment.