Skip to content

Commit

Permalink
removed show_title and ArgumentError as no longer needed, added test …
Browse files Browse the repository at this point in the history
…to check for no title
  • Loading branch information
sarahcrack committed Dec 11, 2024
1 parent 1158fbb commit 93e9ca6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/components/content/results_box_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="results-box-component">
<% if show_title %>
<% if title %>
<div class="results-box__title">
<%= title %>
</div>
Expand Down
9 changes: 2 additions & 7 deletions app/components/content/results_box_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ class ResultsBoxComponent < ViewComponent::Base

include ContentHelper

def initialize(heading:, fee:, course_length:, funding:, text:, link_text:, link_target:, border_color: :grey, show_title: false, title: nil)
def initialize(heading:, fee:, course_length:, funding:, text:, link_text:, link_target:, title: nil, border_color: :grey)
super

if show_title && title.nil?
raise ArgumentError, "Title must be provided when show_title is true"
end

@title = show_title ? substitute_values(title) : nil
@title = substitute_values(title)
@heading = substitute_values(heading)
@fee = substitute_values(fee)
@course_length = substitute_values(course_length)
Expand All @@ -20,7 +16,6 @@ def initialize(heading:, fee:, course_length:, funding:, text:, link_text:, link
@link_text = link_text
@link_target = link_target
@border_color = border_color
@show_title = show_title
end

def border_class
Expand Down
4 changes: 1 addition & 3 deletions spec/components/content/results_box_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
let(:funding) { "Scholarships or bursaries, as well as student loans, are available if you're eligible" }
let(:text) { "Find out which qualifications you need, what funding you can get and how to train to teach." }
let(:title) { nil }
let(:show_title) { false }
let(:border_color) { :grey }
let(:link_text) { "Find out more about postgraduate initial teacher training" }
let(:link_target) { "/train-to-be-a-teacher" }
Expand All @@ -24,7 +23,6 @@
course_length: course_length,
funding: funding,
text: text,
show_title: show_title,
title: title,
border_color: border_color,
link_text: link_text,
Expand All @@ -38,10 +36,10 @@
it { is_expected.to have_css(".results-box__value", text: course_length) }
it { is_expected.to have_css(".results-box__value", text: funding) }
it { is_expected.to have_css(".results-box--grey") }
it { is_expected.to have_no_css(".results-box__title", text: title) }

context "when a title is provided" do
let(:title) { "Most popular route" }
let(:show_title) { true }

it { is_expected.to have_css(".results-box__title", text: title) }
end
Expand Down

0 comments on commit 93e9ca6

Please sign in to comment.