From c95ec607b8df17cc1c8ec09f0470b7850c4a80e1 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Tue, 16 Jul 2024 09:44:54 +0100 Subject: [PATCH 1/3] Add active/archived status tags This adds the colours and values for the active and archived status tags. --- app/components/status_tag/component.rb | 2 ++ config/locales/components.en.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/components/status_tag/component.rb b/app/components/status_tag/component.rb index 7991096856..451d1d7643 100644 --- a/app/components/status_tag/component.rb +++ b/app/components/status_tag/component.rb @@ -24,6 +24,8 @@ def tags COLOURS = { accepted: "green", + active: "green", + archived: "grey", assessment: "blue", assessment_in_progress: "blue", assessment_not_started: "grey", diff --git a/config/locales/components.en.yml b/config/locales/components.en.yml index bce8c00ccf..94009c2da5 100644 --- a/config/locales/components.en.yml +++ b/config/locales/components.en.yml @@ -2,6 +2,8 @@ en: components: status_tag: accepted: Accepted + active: Active + archived: Archived assessment: Assessment assessment_in_progress: Assessment in progress assessment_not_started: Assessment not started From dc364f80e41730ddb36b8171f54b880c03eb0107 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Tue, 16 Jul 2024 09:45:44 +0100 Subject: [PATCH 2/3] Fix suitability record factory This fixes issues with the factories related to suitability records. --- app/models/suitability_record.rb | 5 +++++ spec/factories/suitability_records.rb | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/models/suitability_record.rb b/app/models/suitability_record.rb index 8a6260ef78..46aebe69f7 100644 --- a/app/models/suitability_record.rb +++ b/app/models/suitability_record.rb @@ -23,6 +23,7 @@ # fk_rails_... (created_by_id => staff.id) # class SuitabilityRecord < ApplicationRecord + belongs_to :created_by, class_name: "Staff" has_and_belongs_to_many :application_forms has_many :emails, class_name: "SuitabilityRecord::Email" has_many :names, class_name: "SuitabilityRecord::Name" @@ -39,6 +40,8 @@ def archived? class Email < ApplicationRecord self.table_name = "suitability_record_emails" + belongs_to :suitability_record + validates :value, presence: true validates :canonical, presence: true @@ -51,6 +54,8 @@ def value=(value) class Name < ApplicationRecord self.table_name = "suitability_record_names" + belongs_to :suitability_record + validates :value, presence: true end end diff --git a/spec/factories/suitability_records.rb b/spec/factories/suitability_records.rb index 01270dfac5..2f0406d930 100644 --- a/spec/factories/suitability_records.rb +++ b/spec/factories/suitability_records.rb @@ -24,6 +24,8 @@ # FactoryBot.define do factory :suitability_record do + association :created_by, factory: :staff + note { Faker::Lorem.sentence } trait :archived do @@ -32,16 +34,16 @@ end end - factory :suitability_record_email do + factory :suitability_record_email, class: SuitabilityRecord::Email do association :suitability_record - value { Faker::Name.name } + value { Faker::Internet.email } + canonical { EmailAddress.canonical(value) } end - factory :suitability_record_name do + factory :suitability_record_name, class: SuitabilityRecord::Name do association :suitability_record - value { Faker::Internet.email } - canonical { EmailAddress.canonical(value) } + value { Faker::Name.name } end end From 1ca799a65da3aead43dfec2e107c2e89e80b4dbb Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Tue, 16 Jul 2024 09:47:11 +0100 Subject: [PATCH 3/3] Show all suitability records This adds the ability to show all the suitability records, including pagination. --- .../suitability_records_controller.rb | 13 +++++++ 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, 77 insertions(+), 1 deletion(-) diff --git a/app/controllers/assessor_interface/suitability_records_controller.rb b/app/controllers/assessor_interface/suitability_records_controller.rb index a3db51c28a..67f5b68bb6 100644 --- a/app/controllers/assessor_interface/suitability_records_controller.rb +++ b/app/controllers/assessor_interface/suitability_records_controller.rb @@ -1,9 +1,22 @@ # frozen_string_literal: true +require "pagy/extras/array" + module AssessorInterface class SuitabilityRecordsController < BaseController + include Pagy::Backend + def index authorize %i[assessor_interface suitability_record] + + @pagy, @records = + pagy_array( + SuitabilityRecord.includes( + :names, + :emails, + :application_forms, + ).sort_by(&:name), + ) end end end diff --git a/app/models/suitability_record.rb b/app/models/suitability_record.rb index 46aebe69f7..d8b7923a43 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 124f9c9cda..c6080c233d 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 4f7754ab4c..2a28bc175d 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 88501033d1..2c704f69b8 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