Skip to content

Commit

Permalink
Show all suitability records
Browse files Browse the repository at this point in the history
This adds the ability to show all the suitability records, including
pagination.
  • Loading branch information
thomasleese committed Jul 16, 2024
1 parent 6a29296 commit 048885c
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions app/models/suitability_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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" : "status"
end

def archived?
archived_at.present?
end
Expand Down
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" />
<% 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) %>
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

0 comments on commit 048885c

Please sign in to comment.