Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to view suitability records #2309

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/components/status_tag/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def tags

COLOURS = {
accepted: "green",
active: "green",
archived: "grey",
assessment: "blue",
assessment_in_progress: "blue",
assessment_not_started: "grey",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions app/models/suitability_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,13 +33,23 @@ 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

class Email < ApplicationRecord
self.table_name = "suitability_record_emails"

belongs_to :suitability_record

validates :value, presence: true
validates :canonical, presence: true

Expand All @@ -51,6 +62,8 @@ def value=(value)
class Name < ApplicationRecord
self.table_name = "suitability_record_names"

belongs_to :suitability_record

validates :value, presence: true
end
end
34 changes: 34 additions & 0 deletions app/views/assessor_interface/suitability_records/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,37 @@
<% content_for :page_title, title %>

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

<% @records.each_with_index do |suitability_record, index| %>
<% unless index.zero? %>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible govuk-!-margin-top-9 govuk-!-margin-bottom-9" />
<% end %>

<article>
<h2 class="govuk-heading-m"><%= suitability_record.name %></h2>

<%= 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 %>
</article>
<% end %>

<%= govuk_pagination(pagy: @pagy) %>
2 changes: 2 additions & 0 deletions config/locales/components.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions spec/factories/suitability_records.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#
FactoryBot.define do
factory :suitability_record do
association :created_by, factory: :staff

note { Faker::Lorem.sentence }

trait :archived do
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 17 additions & 1 deletion spec/system/assessor_interface/suitability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading