Skip to content

Commit ec50c42

Browse files
authored
Merge pull request #58 from alphagov/do-not-render-a-link-when-base-path-is-not-present
Don’t render a link when Host Edition has no base_path
2 parents 733bc45 + ed94171 commit ec50c42

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

app/components/document/show/host_editions_table_component.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def sort_link(param)
108108
end
109109

110110
def frontend_path(content_item)
111+
return nil if content_item.base_path.nil?
112+
111113
Plek.website_root + content_item.base_path
112114
end
113115

@@ -125,8 +127,13 @@ def content_link_text(content_item)
125127
end
126128

127129
def content_link(content_item)
128-
link_to(content_link_text(content_item),
129-
frontend_path(content_item), class: "govuk-link", target: "_blank", rel: "noopener")
130+
path = frontend_path(content_item)
131+
132+
if path
133+
link_to(content_link_text(content_item), path, class: "govuk-link", target: "_blank", rel: "noopener")
134+
else
135+
content_item.title
136+
end
130137
end
131138

132139
def updated_field_for(content_item)

test/components/document/show/host_editions_table_component_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,38 @@ def self.it_returns_unknown_user
144144
end
145145
end
146146

147+
describe "when a base_path is nil" do
148+
let(:host_content_item) do
149+
HostContentItem.new(
150+
"title" => "Some title",
151+
"base_path" => nil,
152+
"document_type" => "document_type",
153+
"publishing_app" => "publisher",
154+
"last_edited_by_editor" => last_edited_by_editor,
155+
"last_edited_at" => Time.zone.now.to_s,
156+
"publishing_organisation" => publishing_organisation,
157+
"unique_pageviews" => unique_pageviews,
158+
"host_content_id" => SecureRandom.uuid,
159+
"host_locale" => "en",
160+
"instances" => 1,
161+
)
162+
end
163+
164+
it "Does not render a link" do
165+
render_inline(
166+
described_class.new(
167+
caption:,
168+
host_content_items:,
169+
edition:,
170+
),
171+
)
172+
173+
assert_selector "tbody" do |tbody|
174+
tbody.assert_no_selector ".govuk-link", text: "#{host_content_item.title} (opens in new tab)"
175+
end
176+
end
177+
end
178+
147179
describe "sorting headers" do
148180
it "adds the table header as an anchor tag to each header" do
149181
render_inline(

0 commit comments

Comments
 (0)