Browse Source

Merge pull request #517 from communitiesuk/no-bullets-if-one-value

Don’t use bullet list if only one value returned
pull/527/head
Paul Robert Lloyd 3 years ago committed by GitHub
parent
commit
63fc1d74b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/helpers/details_table_helper.rb
  2. 20
      spec/helpers/details_table_helper_spec.rb

8
app/helpers/details_table_helper.rb

@ -1,10 +1,12 @@
module DetailsTableHelper module DetailsTableHelper
def details_html(attribute) def details_html(attribute)
if attribute[:format] == :bullet if attribute[:format] == :bullet && attribute[:value].length > 1
list = attribute[:value].map { |la| "<li>#{la}</li>" }.join list = attribute[:value].map { |value| "<li>#{value}</li>" }.join
simple_format(list, { class: "govuk-list govuk-list--bullet" }, wrapper_tag: "ul") simple_format(list, { class: "govuk-list govuk-list--bullet" }, wrapper_tag: "ul")
else else
simple_format(attribute[:value].to_s, {}, wrapper_tag: "div") value = attribute[:value].is_a?(Array) ? attribute[:value].first : attribute[:value]
simple_format(value.to_s, { class: "govuk-body" }, wrapper_tag: "p")
end end
end end
end end

20
spec/helpers/details_table_helper_spec.rb

@ -7,8 +7,8 @@ RSpec.describe DetailsTableHelper do
context "when given a simple attribute" do context "when given a simple attribute" do
let(:attribute) { { name: "name", value: "Dummy org", editable: true } } let(:attribute) { { name: "name", value: "Dummy org", editable: true } }
it "displays the string wrapped in a div" do it "displays the string wrapped in a p" do
expect(details).to eq("<div>Dummy org</div>") expect(details).to eq("<p class=\"govuk-body\">Dummy org</p>")
end end
end end
@ -27,5 +27,21 @@ RSpec.describe DetailsTableHelper do
expect(details).to eq("<ul class=\"govuk-list govuk-list--bullet\"><li>Camden</li><li>Westminster</li><li>Bristol</li></ul>") expect(details).to eq("<ul class=\"govuk-list govuk-list--bullet\"><li>Camden</li><li>Westminster</li><li>Bristol</li></ul>")
end end
end end
context "when given a bullet point list with one attibute" do
let(:list) { %w[Camden] }
let(:attribute) do
{
name: "local_authorities_operated_in",
value: list,
editable: false,
format: :bullet,
}
end
it "displays the string wrapped in a p" do
expect(details).to eq("<p class=\"govuk-body\">Camden</p>")
end
end
end end
end end

Loading…
Cancel
Save