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

Omit summary list rows with no values #383

Merged
merged 3 commits into from
Oct 11, 2023
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
10 changes: 6 additions & 4 deletions app/components/check_records/npq_summary_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class="govuk-!-margin-bottom-9">
<h2 class="govuk-heading-m">National professional qualifications (NPQ)</h2>
<%= render GovukComponent::SummaryListComponent.new(rows:) %>
</div>
<% if rows.any? %>
<div class="govuk-!-margin-bottom-9">
<h2 class="govuk-heading-m">National professional qualifications (NPQ)</h2>
<%= render GovukComponent::SummaryListComponent.new(rows:) %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class="govuk-!-margin-bottom-9">
<h2 class="govuk-heading-m"><%= title %></h2>
<%= render GovukComponent::SummaryListComponent.new(rows:) %>
</div>
<% if rows.any? %>
<div class="govuk-!-margin-bottom-9">
<h2 class="govuk-heading-m"><%= title %></h2>
<%= render GovukComponent::SummaryListComponent.new(rows:) %>
</div>
<% end %>
17 changes: 12 additions & 5 deletions app/components/check_records/qualification_summary_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ class CheckRecords::QualificationSummaryComponent < ViewComponent::Base
alias_method :title, :name

def rows
return itt_rows if itt?
return mq_rows if mq?
return induction_rows if induction?

[{ key: { text: "Date awarded" }, value: { text: awarded_at&.to_fs(:long_uk) } }]
@rows = (
if itt?
itt_rows
elsif mq?
mq_rows
elsif induction?
induction_rows if induction?
else
[{ key: { text: "Date awarded" }, value: { text: awarded_at&.to_fs(:long_uk) } }]
end
)
@rows.select { |row| row[:value][:text].present? }
end

def induction_rows
Expand Down
4 changes: 2 additions & 2 deletions app/components/induction_summary_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<h2 class="govuk-summary-card__title"><%= title %></h2>
</div>
<div class="govuk-summary-card__content">
<%= render GovukComponent::SummaryListComponent.new(rows:) %>
<%= render GovukComponent::SummaryListComponent.new(rows:) if rows.any? %>
<%= render GovukComponent::DetailsComponent.new(classes: detail_classes, summary_text: "Induction history") do %>
<%= render GovukComponent::SummaryListComponent.new(classes: list_classes, rows: history) %>
<%= render GovukComponent::SummaryListComponent.new(classes: list_classes, rows: history) if history.any? %>
<% end %>
</div>
</div>
3 changes: 2 additions & 1 deletion app/components/induction_summary_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def history
]
end
.flatten
.select { |row| row[:value][:text].present? }
end

def rows
Expand Down Expand Up @@ -88,7 +89,7 @@ def rows
}
}
end
@rows
@rows.select { |row| row[:value][:text].present? }
end

def title
Expand Down
2 changes: 1 addition & 1 deletion app/components/qualification_summary_component.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render GovukComponent::SummaryListComponent.new(rows:, card: { title: }) %>
<%= render GovukComponent::SummaryListComponent.new(rows:, card: { title: }) if rows.any? %>
2 changes: 1 addition & 1 deletion app/components/qualification_summary_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def rows
}
end

@rows
@rows.select { |row| row[:value][:text].present? }
end

def itt_rows
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require "rails_helper"

RSpec.describe CheckRecords::QualificationSummaryComponent, test: :with_fake_quals_data, type: :component do
describe "rendering" do
let(:fake_quals_data) do
Hashie::Mash.new(
quals_data(trn: "1234567")
.deep_transform_keys(&:to_s)
.deep_transform_keys(&:underscore)
)
end
let(:qualification) do
Qualification.new(
name: "Initial teacher training (ITT)",
awarded_at: fake_quals_data.end_date&.to_date,
type: :itt,
details: fake_quals_data.fetch("initial_teacher_training").first
)
end
let(:component) { described_class.new(qualification:) }
let(:rendered) { render_inline(component) }
let(:rows) { rendered.css(".govuk-summary-list__row") }

it "renders the qualification name" do
expect(rendered.css("h2").text).to eq(qualification.name)
end

it "renders the qualification" do
expect(rows[0].text).to include(qualification.details.dig(:qualification, :name))
end

it "renders the qualification provider" do
expect(rows[1].text).to include(qualification.details.dig(:provider, :name))
end

it "renders the qualification programme type" do
expect(rows[2].text).to include(qualification.details.programme_type_description)
end

it "renders the qualification subject" do
expect(rows[3].text).to include(qualification.details.subjects.first.name.titleize)
end

it "renders the qualification age range" do
expect(rows[4].text).to include(qualification.details.age_range&.description)
end

it "renders the qualification course end date" do
expect(rows[5].text).to include(Date.parse(qualification.details.end_date).to_fs(:long_uk))
end

it "renders the qualification status" do
expect(rows[6].text).to include(qualification.details.result)
end

it "omits rows with no value" do
qualification.details.end_date = nil
qualification.details.result = nil
expect(rows.text).not_to include("Course end date")
expect(rows.text).not_to include("Course result")
end
end
end
60 changes: 60 additions & 0 deletions spec/components/induction_summary_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require "rails_helper"

RSpec.describe InductionSummaryComponent, test: :with_fake_quals_data, type: :component do
describe "rendering" do
let(:fake_quals_data) do
Hashie::Mash.new(
quals_data(trn: "1234567")
.deep_transform_keys(&:to_s)
.deep_transform_keys(&:underscore)
)
end
let(:induction) { fake_quals_data.fetch("induction") }
let(:qualification) do
Qualification.new(
name: "Induction summary",
awarded_at: induction.end_date&.to_date,
type: :itt,
details: induction
)
end
let(:component) { described_class.new(qualification:) }
let(:rendered) { render_inline(component) }

it "renders the component title" do
expect(rendered.css(".govuk-summary-card__title").text).to eq("Induction summary")
end

it "renders the component rows" do
rows = rendered.css(".govuk-summary-list__row")
expect(rows[0].css(".govuk-summary-list__key").text).to eq("Status")
expect(rows[0].css(".govuk-summary-list__value").text).to eq("Pass")

expect(rows[1].css(".govuk-summary-list__key").text).to eq("Completed")
expect(rows[1].css(".govuk-summary-list__value").text).to eq(" 1 October 2022")

expect(rows[2].css(".govuk-summary-list__key").text).to eq("Certificate")
expect(rows[2].css(".govuk-summary-list__value").text).to eq("Download Induction certificate")

expect(rows[3].css(".govuk-summary-list__key").text).to eq("Appropriate body")
expect(rows[3].css(".govuk-summary-list__value").text).to eq("Induction body")

expect(rows[4].css(".govuk-summary-list__key").text).to eq("Start date")
expect(rows[4].css(".govuk-summary-list__value").text).to eq(" 1 September 2022")

expect(rows[5].css(".govuk-summary-list__key").text).to eq("End date")
expect(rows[5].css(".govuk-summary-list__value").text).to eq(" 1 October 2022")

expect(rows[6].css(".govuk-summary-list__key").text).to eq("Number of terms")
expect(rows[6].css(".govuk-summary-list__value").text).to eq("1")
end

it "renders does not render empty component rows" do
component.qualification.awarded_at = nil
component.qualification.details.periods.first.end_date = nil

expect(rendered.css(".govuk-summary-list__key").map(&:text)).not_to include("Completed")
expect(rendered.css(".govuk-summary-list__key").map(&:text)).not_to include("End date")
end
end
end
67 changes: 67 additions & 0 deletions spec/components/qualification_summary_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require "rails_helper"

RSpec.describe QualificationSummaryComponent, test: :with_fake_quals_data, type: :component do
describe "rendering" do
let(:fake_quals_data) do
Hashie::Mash.new(
quals_data(trn: "1234567")
.deep_transform_keys(&:to_s)
.deep_transform_keys(&:underscore)
)
end
let(:qualification) do
Qualification.new(
name: "Initial teacher training (ITT)",
awarded_at: fake_quals_data.end_date&.to_date,
type: :itt,
details: fake_quals_data.fetch("initial_teacher_training").first
)
end
let(:component) { described_class.new(qualification:) }
let(:rendered) { render_inline(component) }
let(:rows) { rendered.css(".govuk-summary-list__row") }

it "renders the qualification name" do
expect(rendered.css("h2").text).to eq(qualification.name)
end

it "renders the qualification" do
expect(rows[0].text).to include(qualification.details.dig(:qualification, :name))
end

it "renders the qualification provider" do
expect(rows[1].text).to include(qualification.details.dig(:provider, :name))
end

it "renders the qualification programme type" do
expect(rows[2].text).to include(qualification.details.programme_type_description)
end

it "renders the qualification subject" do
expect(rows[3].text).to include(qualification.details.subjects.first.name.titleize)
end

it "renders the qualification course start date" do
expect(rows[4].text).to include(Date.parse(qualification.details.start_date).to_fs(:long_uk))
end

it "renders the qualification course end date" do
expect(rows[5].text).to include(Date.parse(qualification.details.end_date).to_fs(:long_uk))
end

it "renders the qualification status" do
expect(rows[6].text).to include(qualification.details.result)
end

it "renders the qualification age range" do
expect(rows[7].text).to include(qualification.details.age_range&.description)
end

it "omits rows with no value" do
qualification.details.end_date = nil
qualification.details.result = nil
expect(rows.text).not_to include("Course end date")
expect(rows.text).not_to include("Course result")
end
end
end
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@

config.include ActiveJob::TestHelper
config.include ActiveSupport::Testing::TimeHelpers
config.include FakeQualificationsData, test: :with_fake_quals_data
config.include ViewComponent::TestHelpers, type: :component
end
Loading