diff --git a/app/components/address_component.html.erb b/app/components/address_component.html.erb new file mode 100644 index 000000000..656803113 --- /dev/null +++ b/app/components/address_component.html.erb @@ -0,0 +1,3 @@ +

+ <%= sanitize formatted_address %> +

diff --git a/app/components/address_component.rb b/app/components/address_component.rb index b6b9263c0..8057f3b0d 100644 --- a/app/components/address_component.rb +++ b/app/components/address_component.rb @@ -1,12 +1,6 @@ # frozen_string_literal: true class AddressComponent < ViewComponent::Base - erb_template <<~ERB -

- <%= formatted_address %> -

- ERB - def initialize(address:, raw_location: nil) super @address = address @@ -16,11 +10,11 @@ def initialize(address:, raw_location: nil) def formatted_address if @address.present? address_lines = @address.all_address_lines.map(&:strip) - return address_lines.join(',
').html_safe # rubocop:disable Rails/OutputSafety + return address_lines.join(", #{tag.br}") end uri = URI.parse(raw_location) - "#{uri.hostname}".sanitize + "#{uri.hostname}" rescue URI::InvalidURIError raw_location diff --git a/test/components/address_component_test.rb b/test/components/address_component_test.rb index b34100996..51d3dd04f 100644 --- a/test/components/address_component_test.rb +++ b/test/components/address_component_test.rb @@ -5,12 +5,16 @@ class AddressComponentTest < ViewComponent::TestCase setup do - @address = '123 Moss Ln E' + # TODO: once we can make the event factory use a local calendar + # instead of one that makes outgoing HTTP calls, switch to using + # the event factory here. Or remove this TODO once + # we have an integration test + @address = create(:address) @raw_location = 'Unformatted Address, Ungeolocated Lane, Manchester' end def test_component_renders_address - render_inline AddressComponent.new(address: @address, raw_location: @raw_location) - assert_text 'Unformatted Address, Ungeolocated Lane, Manchester' + render_inline(AddressComponent.new(address: @address, raw_location: @raw_location)) + assert_text '123 Moss Ln E, Manchester, Manchester, M15 5DD' end end