-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: Loosing data if XML was downloaded and uploaded again #1054
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e409ea3
Add XML round-trip data loss tests
McNamara84 cbf9219
Refactor XML tests to use jsdom and real jQuery
McNamara84 ac991c3
Export descriptions, relatedWorks and funders
McNamara84 f1fb58b
Add XML round-trip data loss tests
McNamara84 fa0b9d5
Revise import tests for contact persons & XPath
McNamara84 6de4455
Auto-add author rows; fix funder id parsing
McNamara84 3a63cde
Use XPath resolver for namespaced XML parsing
McNamara84 b9b62e7
Add XPath fallback; guard author-row creation
McNamara84 60bd70f
Support non-namespaced XML for geo/funders
McNamara84 dfb7fa0
Fallback for non-namespaced dates; export STC
McNamara84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,9 +42,29 @@ describe('processContactPersons (ISO)', () => { | |
| <input type="text" name="cpOnlineResource[]" value="" /> | ||
| </div> | ||
| </div> | ||
| <button type="button" id="button-author-add"></button> | ||
| </div> | ||
| `; | ||
|
|
||
| // Wire up click handler to simulate adding a new author row | ||
| $('#button-author-add').on('click', function () { | ||
| const $newRow = $(` | ||
| <div class="row" data-creator-row> | ||
| <input type="checkbox" name="contacts[]" /> | ||
| <input type="text" name="familynames[]" value="" /> | ||
| <input type="text" name="givennames[]" value="" /> | ||
| <input type="text" name="orcids[]" value="" /> | ||
| <div class="contact-person-input" style="display: none;"> | ||
| <input type="email" name="cpEmail[]" value="" /> | ||
| </div> | ||
| <div class="contact-person-input" style="display: none;"> | ||
| <input type="text" name="cpOnlineResource[]" value="" /> | ||
| </div> | ||
| </div> | ||
| `); | ||
| $('#group-author').append($newRow); | ||
| }); | ||
|
|
||
| global.Tagify = jest.fn().mockImplementation(() => ({ | ||
| addTags: jest.fn(), | ||
| settings: { whitelist: [] }, | ||
|
|
@@ -175,7 +195,7 @@ describe('processContactPersons (ISO)', () => { | |
| expect($firstRow.find('input[name="contacts[]"]').prop('checked')).toBe(true); | ||
| }); | ||
|
|
||
| test('does not match when names differ completely', () => { | ||
| test('creates new author row when names differ completely', () => { | ||
| const xmlDoc = makeIsoXml({ | ||
| familyName: 'Unknown', | ||
| givenName: 'Person', | ||
|
|
@@ -184,10 +204,20 @@ describe('processContactPersons (ISO)', () => { | |
|
|
||
| mappingModule.processContactPersons(xmlDoc); | ||
|
|
||
| // Neither row should be marked as CP | ||
| $('div[data-creator-row]').each(function () { | ||
| expect($(this).find('input[name="contacts[]"]').prop('checked')).toBe(false); | ||
| }); | ||
| // A third author row should have been created | ||
| const $rows = $('div[data-creator-row]'); | ||
| expect($rows.length).toBe(3); | ||
|
|
||
| // Original rows should not be marked as CP | ||
| expect($rows.eq(0).find('input[name="contacts[]"]').prop('checked')).toBe(false); | ||
| expect($rows.eq(1).find('input[name="contacts[]"]').prop('checked')).toBe(false); | ||
|
|
||
| // New row should be marked as CP with correct data | ||
| const $newRow = $rows.eq(2); | ||
| expect($newRow.find('input[name="contacts[]"]').prop('checked')).toBe(true); | ||
| expect($newRow.find('input[name="familynames[]"]').val()).toBe('Unknown'); | ||
| expect($newRow.find('input[name="givennames[]"]').val()).toBe('Person'); | ||
| expect($newRow.find('input[name="cpEmail[]"]').val()).toBe('[email protected]'); | ||
| }); | ||
|
|
||
| test('handles XML with no pointOfContact gracefully', () => { | ||
|
|
@@ -309,9 +339,28 @@ describe('processContactPersonsFromDataCite (fallback)', () => { | |
| <input type="text" name="cpOnlineResource[]" value="" /> | ||
| </div> | ||
| </div> | ||
| <button type="button" id="button-author-add"></button> | ||
| </div> | ||
| `; | ||
|
|
||
| // Wire up click handler to simulate adding a new author row | ||
| $('#button-author-add').on('click', function () { | ||
| const $newRow = $(` | ||
| <div class="row" data-creator-row> | ||
| <input type="checkbox" name="contacts[]" /> | ||
| <input type="text" name="familynames[]" value="" /> | ||
| <input type="text" name="givennames[]" value="" /> | ||
| <div class="contact-person-input" style="display: none;"> | ||
| <input type="email" name="cpEmail[]" value="" /> | ||
| </div> | ||
| <div class="contact-person-input" style="display: none;"> | ||
| <input type="text" name="cpOnlineResource[]" value="" /> | ||
| </div> | ||
| </div> | ||
| `); | ||
| $('#group-author').append($newRow); | ||
| }); | ||
|
|
||
| global.Tagify = jest.fn().mockImplementation(() => ({ | ||
| addTags: jest.fn(), | ||
| settings: { whitelist: [] }, | ||
|
|
@@ -407,17 +456,26 @@ describe('processContactPersonsFromDataCite (fallback)', () => { | |
| expect($firstRow.find('input[name="contacts[]"]').prop('checked')).toBe(true); | ||
| }); | ||
|
|
||
| test('does nothing when no matching author found in DataCite fallback', () => { | ||
| test('creates new author row when no matching author found in DataCite fallback', () => { | ||
| const xmlDoc = makeDataCiteXml({ | ||
| familyName: 'Unknown', | ||
| givenName: 'Person', | ||
| }); | ||
|
|
||
| expect(() => mappingModule.processContactPersonsFromDataCite(xmlDoc)).not.toThrow(); | ||
|
|
||
| $('div[data-creator-row]').each(function () { | ||
| expect($(this).find('input[name="contacts[]"]').prop('checked')).toBe(false); | ||
| }); | ||
| // A second author row should have been created | ||
| const $rows = $('div[data-creator-row]'); | ||
| expect($rows.length).toBe(2); | ||
|
|
||
| // Original row should not be marked as CP | ||
| expect($rows.eq(0).find('input[name="contacts[]"]').prop('checked')).toBe(false); | ||
|
|
||
| // New row should be marked as CP with correct data | ||
| const $newRow = $rows.eq(1); | ||
| expect($newRow.find('input[name="contacts[]"]').prop('checked')).toBe(true); | ||
| expect($newRow.find('input[name="familynames[]"]').val()).toBe('Unknown'); | ||
| expect($newRow.find('input[name="givennames[]"]').val()).toBe('Person'); | ||
| }); | ||
|
|
||
| test('does nothing when DataCite XML has no ContactPerson contributor', () => { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.