From d8266896454f56f511c9cdb2839d1d5ec0ba0674 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Tue, 16 Jul 2024 09:47:11 +0100 Subject: [PATCH] Show all suitability records This adds the ability to show all the suitability records, including pagination. --- .../suitability_records_controller.rb | 9 +++++ app/models/suitability_record.rb | 8 +++++ .../suitability_records/index.html.erb | 34 +++++++++++++++++++ .../assessor_interface/suitability_records.rb | 5 +++ .../assessor_interface/suitability_spec.rb | 18 +++++++++- 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/app/controllers/assessor_interface/suitability_records_controller.rb b/app/controllers/assessor_interface/suitability_records_controller.rb index a3db51c28..407c9e84a 100644 --- a/app/controllers/assessor_interface/suitability_records_controller.rb +++ b/app/controllers/assessor_interface/suitability_records_controller.rb @@ -2,8 +2,17 @@ module AssessorInterface class SuitabilityRecordsController < BaseController + include Pagy::Backend + def index authorize %i[assessor_interface suitability_record] + + @pagy, @records = + pagy( + SuitabilityRecord.includes(:names, :emails, :application_forms).order( + "suitability_record_names.value": :asc, + ), + ) end end end diff --git a/app/models/suitability_record.rb b/app/models/suitability_record.rb index 46aebe69f..d8b7923a4 100644 --- a/app/models/suitability_record.rb +++ b/app/models/suitability_record.rb @@ -33,6 +33,14 @@ class SuitabilityRecord < ApplicationRecord validates :note, presence: true validates :archive_note, presence: true, if: :archived? + def name + names.min.value + end + + def status + archived? ? "archived" : "active" + end + def archived? archived_at.present? end diff --git a/app/views/assessor_interface/suitability_records/index.html.erb b/app/views/assessor_interface/suitability_records/index.html.erb index 124f9c9cd..c6080c233 100644 --- a/app/views/assessor_interface/suitability_records/index.html.erb +++ b/app/views/assessor_interface/suitability_records/index.html.erb @@ -3,3 +3,37 @@ <% content_for :page_title, title %>

<%= title %>

+ +<% @records.each_with_index do |suitability_record, index| %> + <% unless index.zero? %> +
+ <% end %> + +
+

<%= suitability_record.name %>

+ + <%= govuk_summary_list(actions: false) do |summary_list| + summary_list.with_row do |row| + row.with_key { "Date added" } + row.with_value { suitability_record.created_at.to_fs } + end + + summary_list.with_row do |row| + row.with_key { "Date last updated" } + row.with_value { suitability_record.updated_at.to_fs } + end + + summary_list.with_row do |row| + row.with_key { "Country trained in" } + row.with_value { CountryName.from_code(suitability_record.country_code) } + end + + summary_list.with_row do |row| + row.with_key { "Suitability status" } + row.with_value { render StatusTag::Component.new(suitability_record.status) } + end + end %> +
+<% end %> + +<%= govuk_pagination(pagy: @pagy) %> diff --git a/spec/support/autoload/page_objects/assessor_interface/suitability_records.rb b/spec/support/autoload/page_objects/assessor_interface/suitability_records.rb index 4f7754ab4..2a28bc175 100644 --- a/spec/support/autoload/page_objects/assessor_interface/suitability_records.rb +++ b/spec/support/autoload/page_objects/assessor_interface/suitability_records.rb @@ -6,6 +6,11 @@ class SuitabilityRecords < SitePrism::Page set_url "/assessor/suitability-records" element :heading, "h1" + + sections :records, "article" do + element :heading, "h2" + element :summary_list, GovukSummaryList, ".govuk-summary-list" + end end end end diff --git a/spec/system/assessor_interface/suitability_spec.rb b/spec/system/assessor_interface/suitability_spec.rb index 88501033d..2c704f69b 100644 --- a/spec/system/assessor_interface/suitability_spec.rb +++ b/spec/system/assessor_interface/suitability_spec.rb @@ -6,13 +6,20 @@ before { given_suitability_is_enabled } after { given_suitability_is_disabled } - it "add suitability records" do + it "view suitability records" do given_i_am_authorized_as_a_user(assessor) + given_a_record_exists when_i_visit_the(:assessor_suitability_records_page) then_i_see_the_suitability_records end + it "add suitability records" do + given_i_am_authorized_as_a_user(assessor) + + when_i_visit_the(:assessor_suitability_records_page) + end + def given_suitability_is_enabled FeatureFlags::FeatureFlag.deactivate(:suitability) end @@ -21,8 +28,17 @@ def given_suitability_is_disabled FeatureFlags::FeatureFlag.deactivate(:suitability) end + def given_a_record_exists + suitability_record = create(:suitability_record) + create(:suitability_record_name, suitability_record:, value: "John Smith") + end + def then_i_see_the_suitability_records expect(assessor_suitability_records_page.heading).to be_visible + expect(assessor_suitability_records_page.records.size).to eq(1) + expect(assessor_suitability_records_page.records.first.heading.text).to eq( + "John Smith", + ) end def assessor