From f85e33b570901561c1547ea9bbc22c547917fb75 Mon Sep 17 00:00:00 2001 From: jazairi <16103405+jazairi@users.noreply.github.com> Date: Mon, 20 Oct 2025 15:34:35 -0400 Subject: [PATCH] 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. --- app/helpers/search_helper.rb | 8 ++++++++ app/views/search/_result.html.erb | 3 ++- test/helpers/search_helper_test.rb | 32 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 335aec27..ca04667c 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -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? diff --git a/app/views/search/_result.html.erb b/app/views/search/_result.html.erb index fad44d90..42f20d0d 100644 --- a/app/views/search/_result.html.erb +++ b/app/views/search/_result.html.erb @@ -1,7 +1,8 @@
  • - Title: <%= link_to(result['title'], record_path(result['identifier'])) %> + Title: + <%= link_to_result(result) %>

    diff --git a/test/helpers/search_helper_test.rb b/test/helpers/search_helper_test.rb index 0ab09dd9..9e79b2a5 100644 --- a/test/helpers/search_helper_test.rb +++ b/test/helpers/search_helper_test.rb @@ -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 = 'Sample Document Title' + 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