diff --git a/app/helpers/details_table_helper.rb b/app/helpers/details_table_helper.rb new file mode 100644 index 000000000..a3204c138 --- /dev/null +++ b/app/helpers/details_table_helper.rb @@ -0,0 +1,10 @@ +module DetailsTableHelper + def details_html(attribute) + if attribute[:format] == :bullet + list = attribute[:value].map { |la| "
  • #{la}
  • "}.join("\n") + simple_format(list, { class: "govuk-list govuk-list--bullet" }, wrapper_tag: "ul") + else + simple_format(attribute[:value].to_s, {}, wrapper_tag: "div") + end + end +end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index bd8b77fdc..a5151be71 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -36,13 +36,17 @@ class Organisation < ApplicationRecord !!data_protection_confirmations.order(created_at: :desc).first&.confirmed end + def local_authorities + organisation_las.pluck(:ons_code) + end + def display_attributes [ { name: "name", value: name, editable: true }, { name: "address", value: address_string, editable: true }, { name: "telephone_number", value: phone, editable: true }, { name: "type", value: "Org type", editable: false }, - { name: "local_authorities_operated_in", value: local_authorities, editable: false }, + { name: "local_authorities_operated_in", value: local_authorities, editable: false, format: :bullet }, { name: "holds_own_stock", value: holds_own_stock.to_s.humanize, editable: false }, { name: "other_stock_owners", value: other_stock_owners, editable: false }, { name: "managing_agents", value: managing_agents, editable: false }, diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index 0cd186f2e..d59761d27 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -12,7 +12,7 @@ <% if can_edit_org?(current_user) && attr[:editable] %> <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s.humanize } %> - <% row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } %> + <% row.value { details_html(attr) } %> <% row.action( visually_hidden_text: "name", href: edit_organisation_path, @@ -22,7 +22,7 @@ <% else %> <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s.humanize } %> - <% row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } %> + <% row.value { details_html(attr) } %> <% row.action %> <% end %> <% end %> diff --git a/spec/helpers/table_details_helper_spec.rb b/spec/helpers/table_details_helper_spec.rb new file mode 100644 index 000000000..0b3470e5a --- /dev/null +++ b/spec/helpers/table_details_helper_spec.rb @@ -0,0 +1,32 @@ +require "rails_helper" + +RSpec.describe DetailsTableHelper do + + describe "details html" do + subject { details_html(attribute) } + + context "when given a simple attribute" do + let(:attribute) { { name: "name", value: "Dummy org", editable: true } } + + it "displays the string wrapped in a div" do + expect(subject).to eq("
    Dummy org
    ") + end + end + + context "when given a bullet point list of attibutes" do + let(:list) { ["Camden", "Westminster", "Bristol"] } + let(:attribute) do + { + name: "local_authorities_operated_in", + value: list, + editable: false, + format: :bullet, + } + end + + it "displays the string wrapped in an unordered list with the correct classes" do + expect(subject).to eq("") + end + end + end +end