-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrate the AddressComponent to using ViewComponent (#2638)
Co-authored-by: Dr Kim Foale <[email protected]>
- Loading branch information
1 parent
e4b2ed6
commit 4a78e5f
Showing
10 changed files
with
48 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,4 +131,4 @@ Lint/SelfAssignment: | |
Enabled: false | ||
Lint/RedundantCopDisableDirective: | ||
Enabled: false | ||
|
||
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
app/components/address/_address.html.erb → app/components/address_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<p class="place_info__address" property="address" typeof="PostalAddress"> | ||
<%= formatted_address %> | ||
<%= sanitize formatted_address %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddressComponent < ViewComponent::Base | ||
def initialize(address:, raw_location: nil) | ||
super | ||
@address = address | ||
@raw_location = raw_location | ||
end | ||
|
||
def formatted_address | ||
if @address.present? | ||
address_lines = @address.all_address_lines.map(&:strip) | ||
return address_lines.join(", #{tag.br}") | ||
end | ||
|
||
uri = URI.parse(@raw_location) | ||
"<a href='#{uri}'>#{uri.hostname}</a>" | ||
|
||
rescue URI::InvalidURIError | ||
@raw_location | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
require 'view_component/test_case' | ||
|
||
class AddressComponentTest < ViewComponent::TestCase | ||
setup do | ||
# 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 '123 Moss Ln E, Manchester, Manchester, M15 5DD' | ||
end | ||
end |