Skip to content

Commit f85e33b

Browse files
committed
Render titles with source links for TIMDEX records
Why these changes are being introduced: In TIMDEX UI, titles linked to full record views. That feature is not currently implemented in USE UI. Relevant ticket(s): * [USE-99](https://mitlibraries.atlassian.net/browse/USE-99) How this addresses that need: This updates TIMDEX title links to use the `source_link` field. Side effects of this change: When developing TIMDEX UI, we decided not to test any view logic. I've moved the logic in this change to the Search Helper in order to test it, but we may want to discuss whether to revisit integration testing in USE UI.
1 parent 22eb852 commit f85e33b

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

app/helpers/search_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ def format_highlight_label(field_name)
1414
field_name.underscore.humanize
1515
end
1616

17+
def link_to_result(result)
18+
if result['source_link'].present?
19+
link_to(result['title'], result['source_link'])
20+
else
21+
result['title']
22+
end
23+
end
24+
1725
def view_online(result)
1826
return unless result['source_link'].present?
1927

app/views/search/_result.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<li class="result">
22
<div class="result-content">
33
<h3 class="record-title">
4-
<span class="sr">Title: </span><%= link_to(result['title'], record_path(result['identifier'])) %>
4+
<span class="sr">Title: </span>
5+
<%= link_to_result(result) %>
56
</h3>
67

78
<p class="pub-info">

test/helpers/search_helper_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,36 @@ def setup
171171
}
172172
assert_equal ['Authors: person, sample'], applied_advanced_terms(query)
173173
end
174+
175+
test 'link_to_result returns link when source_link is present' do
176+
result = {
177+
'title' => 'Sample Document Title',
178+
'source_link' => 'https://example.com/document'
179+
}
180+
expected_link = '<a href="https://example.com/document">Sample Document Title</a>'
181+
assert_equal expected_link, link_to_result(result)
182+
end
183+
184+
test 'link_to_result returns plain title when source_link is nil' do
185+
result = {
186+
'title' => 'Sample Document Title',
187+
'source_link' => nil
188+
}
189+
assert_equal 'Sample Document Title', link_to_result(result)
190+
end
191+
192+
test 'link_to_result returns plain title when source_link is empty string' do
193+
result = {
194+
'title' => 'Sample Document Title',
195+
'source_link' => ''
196+
}
197+
assert_equal 'Sample Document Title', link_to_result(result)
198+
end
199+
200+
test 'link_to_result returns plain title when source_link key is absent' do
201+
result = {
202+
'title' => 'Sample Document Title'
203+
}
204+
assert_equal 'Sample Document Title', link_to_result(result)
205+
end
174206
end

0 commit comments

Comments
 (0)