Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def format_highlight_label(field_name)
field_name.underscore.humanize
end

def link_to_result(result)
if result['source_link'].present?
link_to(result['title'], result['source_link'])
else
result['title']
end
end

def view_online(result)
return unless result['source_link'].present?

Expand Down
3 changes: 2 additions & 1 deletion app/views/search/_result.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<li class="result">
<div class="result-content">
<h3 class="record-title">
<span class="sr">Title: </span><%= link_to(result['title'], record_path(result['identifier'])) %>
<span class="sr">Title: </span>
<%= link_to_result(result) %>
</h3>

<p class="pub-info">
Expand Down
32 changes: 32 additions & 0 deletions test/helpers/search_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,36 @@ def setup
}
assert_equal ['Authors: person, sample'], applied_advanced_terms(query)
end

test 'link_to_result returns link when source_link is present' do
result = {
'title' => 'Sample Document Title',
'source_link' => 'https://example.com/document'
}
expected_link = '<a href="https://example.com/document">Sample Document Title</a>'
assert_equal expected_link, link_to_result(result)
end

test 'link_to_result returns plain title when source_link is nil' do
result = {
'title' => 'Sample Document Title',
'source_link' => nil
}
assert_equal 'Sample Document Title', link_to_result(result)
end

test 'link_to_result returns plain title when source_link is empty string' do
result = {
'title' => 'Sample Document Title',
'source_link' => ''
}
assert_equal 'Sample Document Title', link_to_result(result)
end

test 'link_to_result returns plain title when source_link key is absent' do
result = {
'title' => 'Sample Document Title'
}
assert_equal 'Sample Document Title', link_to_result(result)
end
end
Loading