-
Notifications
You must be signed in to change notification settings - Fork 0
Adds additional tabs for timdex sources #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5ec92fb
77d32fc
e8394a5
01ebb5c
37f4498
cfc54a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,34 @@ | ||
| module ResultsHelper | ||
| # Descriptions for each tab. HTML entries use raw anchor tags (all URLs are | ||
| # hardcoded external links, so no XSS risk) and must be marked html_safe. | ||
| TAB_DESCRIPTIONS = { | ||
| 'all' => 'All MIT Libraries sources', | ||
| 'cdi' => 'Journal and newspaper articles, book reviews, book chapters, and more', | ||
| 'alma' => 'Books, e-books, journals, streaming and physical media, and more', | ||
| 'timdex_alma' => 'Books, e-books, journals, streaming and physical media, and more', | ||
| 'primo' => 'Articles, books, chapters, streaming and physical media, and more', | ||
| 'aspace' => 'Archives, manuscripts, and other unique materials related to MIT', | ||
| 'timdex' => 'Digital collections, images, documents, and more from MIT Libraries', | ||
| 'website' => 'Information about the library: events, news, services, and more', | ||
| 'dspace' => '<a href="https://dspace.mit.edu">DSpace@MIT</a> ' \ | ||
| "is a digital repository for MIT's research, including peer-reviewed articles, " \ | ||
| 'technical reports, working papers, theses, and more.'.html_safe, | ||
| 'geodata' => "Geospatial datasets and maps from MIT Libraries' " \ | ||
| '<a href="https://geodata.libraries.mit.edu">GeoData</a> collections; ' \ | ||
| 'includes <a href="https://opengeometadata.org">Open Geospatial Consortium (OGC)</a> data.'.html_safe, | ||
| 'databases' => '<a href="https://libguides.mit.edu/az/databases">Research Databases</a> ' \ | ||
| 'covering a wide range of subjects and formats'.html_safe | ||
| }.freeze | ||
|
|
||
| def results_summary(hits) | ||
| hits.to_i >= 10_000 ? '10,000+ results' : "#{number_with_delimiter(hits)} results" | ||
| end | ||
|
|
||
| # Provides a description for the current tab in search results. | ||
| def tab_description | ||
| case params[:tab] | ||
| when 'all' | ||
| 'All MIT Libraries sources' | ||
| when 'cdi' | ||
| 'Journal and newspaper articles, book reviews, book chapters, and more' | ||
| when 'alma', 'timdex_alma' | ||
| 'Books, e-books, journals, streaming and physical media, and more' | ||
| when 'primo' | ||
| 'Articles, books, chapters, streaming and physical media, and more' | ||
| when 'aspace' | ||
| 'Archives, manuscripts, and other unique materials related to MIT' | ||
| when 'timdex' | ||
| 'Digital collections, images, documents, and more from MIT Libraries' | ||
| when 'website' | ||
| 'Information about the library: events, news, services, and more' | ||
| else | ||
| TAB_DESCRIPTIONS.fetch(params[:tab]) do | ||
| Rails.logger.error "Unknown tab parameter in `tab_description` helper: #{params[:tab]}" | ||
| '' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making sure I understand - this is the default value in case
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. Previous to this we were inadvertently returning |
||
| end | ||
|
JPrevost marked this conversation as resolved.
JPrevost marked this conversation as resolved.
|
||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,37 +21,10 @@ class ResultsHelperTest < ActionView::TestCase | |
| end | ||
|
|
||
| test 'result helper handles tab descriptions for tabs based on params hash' do | ||
| params[:tab] = 'all' | ||
| description = 'All MIT Libraries sources' | ||
| assert_equal description, tab_description | ||
|
|
||
| params[:tab] = 'cdi' | ||
| description = 'Journal and newspaper articles, book reviews, book chapters, and more' | ||
| assert_equal description, tab_description | ||
|
|
||
| params[:tab] = 'alma' | ||
| description = 'Books, e-books, journals, streaming and physical media, and more' | ||
| assert_equal description, tab_description | ||
|
|
||
| params[:tab] = 'timdex_alma' | ||
| description = 'Books, e-books, journals, streaming and physical media, and more' | ||
| assert_equal description, tab_description | ||
|
|
||
| params[:tab] = 'primo' | ||
| description = 'Articles, books, chapters, streaming and physical media, and more' | ||
| assert_equal description, tab_description | ||
|
|
||
| params[:tab] = 'aspace' | ||
| description = 'Archives, manuscripts, and other unique materials related to MIT' | ||
| assert_equal description, tab_description | ||
|
|
||
| params[:tab] = 'timdex' | ||
| description = 'Digital collections, images, documents, and more from MIT Libraries' | ||
| assert_equal description, tab_description | ||
|
|
||
| params[:tab] = 'website' | ||
| description = 'Information about the library: events, news, services, and more' | ||
| assert_equal description, tab_description | ||
| ResultsHelper::TAB_DESCRIPTIONS.each do |tab, expected| | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the efficiency of this test, but I wonder whether we should have a test for the behavior when a value outside that More theoretically, I get that this test makes things more robust because we don't need to manually keep the list of test values in sync with the content of the helper method. This feels like a win - but I'm not sure where the line is where we just end up testing that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely agree we should confirm something outside of the expected list returns blank. I'll confirm that test exists or add one. |
||
| params[:tab] = tab | ||
| assert_equal expected, tab_description, "Expected description for tab '#{tab}' to match TAB_DESCRIPTIONS" | ||
| end | ||
| end | ||
|
|
||
| test 'search_primo_link includes encoded search query and correct path' do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change in pattern a lot. 🍻