ANW-2199: fixes issues with CSV export.#3710
Conversation
Pull Request Test Coverage Report for Build 17953658890Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
@brianzelip this is ready for a review. |
brianzelip
left a comment
There was a problem hiding this comment.
Thanks @cpapazoglou. The new exported CSV looks good, so do the unit tests.
Some I18n keys are called that don't exist. This should be fixed by adding appropriate new keys for 7 languages (German, English, Spanish, French, Italian, Japanese, Ukrainian) - I prefer using a llm for this, but google translate is a fallback.
There are also some very minor comments that could be removed since they seem to duplicate the nearby method names or expectations, etc.
The above two points remind me of llm agent output. If any of us are going to review llm-assisted PRs, let's all do ourselves a favor by heavily interrogating and shaping the llm output before a review! :)
Also, please add a feature test for this. There doesn't seem to be any feature specs for exporting a CSV from a search listing page, so you can start by adding to the end of frontend/spec/features/search_listing_spec.rb, ie:
context 'CSV export' do
describe 'Top Containers' do
# login
# visit '/search'
# click 'Top Containers'
# click_on 'Download CSV'
end
endThe spec should compare the column headers and row data from the web page to that of the CSV file. See frontend/spec/features/resources_spec.rb for an example of parsing and analyzing a CSV file.
Feel free to reach out with any questions!
| def self.header_mappings | ||
| @header_mappings ||= begin | ||
| { | ||
| 'context' => (I18n.t('search_results.filter.top_container.context', :default => 'Resource/Accession') rescue 'Resource/Accession'), |
There was a problem hiding this comment.
search_results.filter doesn't exist, so all of these translations fall back to English. Smells like llm?
There was a problem hiding this comment.
Yeah, missed the part of checking that keys actually exist 🤦
Fixed in 15476ee
|
Thanks for the review @brianzelip. I have addressed your feedback. Regarding the CSV export, I am testing that it works and data are present not the actual header mapping that happens in the helper and it's tested separately. |
There was a problem hiding this comment.
[UPDATE - see my comment after this comment]
# Verify headers match between web page and CSV
# Note: CSV may have different header names due to I18n translation
expect(csv_headers).to include('Type')
expect(csv_headers).to include('Indicator')
expect(csv_headers).to include('Barcode')
# Find rows containing our test data
container_1_row = csv_data.find { |row| row.include?(@top_container_1.indicator) }
container_2_row = csv_data.find { |row| row.include?(@top_container_2.indicator) }
expect(container_1_row).to include(@top_container_1.barcode)
expect(container_1_row).to include(@top_container_1.type)
expect(container_2_row).to include(@top_container_2.barcode)
expect(container_2_row).to include(@top_container_2.type)The above expectations don't test for all of the available headings (missing "Title","Resource/Accession", "Container Profile", "Location"), nor their order. Let's please test for both all headings and their correct order. [UPDATE]
Here is an example of getting all of the headings in order from the web page, not including the final "Actions" column:
web_page_headings = all('#tabledSearchResults > thead th').map(&:text).reject { |th| th == 'Actions' }Let's compare [UPDATE]web_page_headings with csv_headers to make sure they match.
Please also make sure that at least one Top Container: [UPDATE]
- includes a Container Profile
- includes a Location
- includes a Resource/Accession.
Then please test the CSV for the presence of all data in the same order as the web page. Arrays make for nice comparisons! [UPDATE]
Also, small nitpick that relates to our budding efforts to enforce a style guide, the following comments are examples of explicitly duplicating the information conveyed by its code. I know that there are many of these kinds of comments in the codebase, including the CSV parsing pattern that I referenced earlier in this PR. This is something we're working to remove, slowly but surely!
# Click download CSV
click_on 'Download CSV'
# Find the downloaded CSV file
files = Dir.glob(File.join(Dir.tmpdir, '*.csv'))
expect(files.length).to be >= 1
# Parse the CSV file
csv_file = File.read(files.last)
csv_data = CSV.parse(csv_file)
csv_headers = csv_data[0]
# Verify headers match between web page and CSV
# Note: CSV may have different header names due to I18n translation
expect(csv_headers).to include('Type')
expect(csv_headers).to include('Indicator')
expect(csv_headers).to include('Barcode')My approach to writing code in this regard includes:
- making variable and method names as self-evident as possible, as you have here
- asking myself, "is the comment merely duplicating the information conveyed by its code?" If so, I try to edit the comment or remove it.
Lastly regarding this comment:
# Note: CSV may have different header names due to I18n translationActually, the headers should be exactly the same. Is this comment from a llm agent? Regardless, please ensure the comment's meaning is not accurate! (and remove the comment)
Ahh! Sorry I missed this before adding my review remarks just now. Let's not worry then about adding extra testing to the feature spec. But please address the |
We are aligned on this, sometimes I mistakenly think that they might be useful. I just left one which is explaining the "why". |
Description
Fixes:
Resource/Accession\Related JIRA Ticket or GitHub Issue
https://archivesspace.atlassian.net/browse/ANW-2199
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: