Skip to content

Commit

Permalink
Omit induction summary rows with no values
Browse files Browse the repository at this point in the history
  • Loading branch information
steventux committed Oct 9, 2023
1 parent b93082a commit deaab96
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/components/induction_summary_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def rows
}
}
end
@rows
@rows.select { |row| row[:value][:text].present? }
end

def title
Expand Down
58 changes: 58 additions & 0 deletions spec/components/induction_summary_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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

expect(rendered.css(".govuk-summary-list__key").map(&:text)).not_to include("Completed")
end
end
end

0 comments on commit deaab96

Please sign in to comment.