Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions src/js/widgets/abstract/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,9 @@ define([
const ps = this.getPubSub();
const query = this.getCurrentQuery().clone();
query.unlock();
const {
bibcode,
author,
orcid_pub,
orcid_user,
orcid_other,
} = currentData;
const { bibcode, } = currentData;
query.set('q', `identifier:${bibcode}`);
query.set('fl', ['author', 'aff', 'orcid_pub', 'orcid_user', 'orcid_other']);
query.set('fl', this.defaultQueryArguments.fl);
query.set('rows', 1);
ps.publish(
ps.EXECUTE_REQUEST,
Expand All @@ -577,13 +571,7 @@ define([
resp.response.docs.length > 0
) {
const freshDoc = resp.response.docs[0];
const newEntries = this.model.parse({
author: freshDoc.author || author,
orcid_pub: freshDoc.orcid_pub || orcid_pub,
orcid_user: freshDoc.orcid_user || orcid_user,
orcid_other: freshDoc.orcid_other || orcid_other,
aff: freshDoc.aff,
});
const newEntries = this.model.parse(freshDoc);
this._docs[bibcode] = {
...this._docs[bibcode],
...newEntries,
Expand Down
68 changes: 68 additions & 0 deletions test/mocha/js/widgets/abstract_widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,74 @@ define(['backbone', 'marionette', 'jquery', 'js/widgets/abstract/widget',
expect($("article").text().trim().replace(/\s{2}/gi, "")).to.eql("Loading...")
});

it("should preserve DOI during fetchAffiliations hydration", function(done){
// Test for SCIX-670: DOI disappearing after loading an abstract
var aw = new AbstractWidget();
aw.activate(minsub.beehive.getHardenedInstance());

// Set up initial document with DOI but no affiliations
aw._docs['test-bibcode'] = {
bibcode: 'test-bibcode',
doi: [{ doi: '10.1086/test123', href: 'https://doi.org/10.1086/test123' }],
author: ['Author, A.', 'Author, B.'],
aff: [],
title: 'Test Document',
abstract: 'Test abstract'
};

// Set current document in model
aw.model.set(aw._docs['test-bibcode']);
aw._current = 'test-bibcode';

// Verify DOI exists before hydration
expect(aw._docs['test-bibcode'].doi).to.exist;
expect(aw._docs['test-bibcode'].doi[0].doi).to.equal("10.1086/test123");

// Mock the PubSub to handle the EXECUTE_REQUEST
var pubsub = aw.getPubSub();
var originalPublish = pubsub.publish;
pubsub.publish = function(signal, request) {
if (signal === pubsub.EXECUTE_REQUEST) {
// Simulate the API response with DOI preserved
setTimeout(function() {
request.get('options').done({
"responseHeader": { "status": 0, "QTime": 10 },
"response": {
"numFound": 1, "start": 0,
"docs": [{
"bibcode": "test-bibcode",
"doi": ["10.1086/test123"], // DOI preserved in hydration response
"author": ["Author, A.", "Author, B."],
"aff": ["Affiliation A", "Affiliation B"],
"title": ["Test Document"],
"abstract": "Test abstract"
}]
}
});
}, 10);
} else {
return originalPublish.apply(this, arguments);
}
};

// Test fetchAffiliations
aw.fetchAffiliations(function(err) {
expect(err).to.be.undefined;

// After hydration, DOI should still be preserved (this was the bug)
expect(aw._docs['test-bibcode'].doi).to.exist;
expect(aw._docs['test-bibcode'].doi[0].doi).to.equal("10.1086/test123");
expect(aw._docs['test-bibcode'].doi[0].href).to.contain("10.1086/test123");

// And affiliations should now be populated
expect(aw._docs['test-bibcode'].aff).to.eql(["Affiliation A", "Affiliation B"]);

// Restore original publish function
pubsub.publish = originalPublish;
done();
});
});

it("should have a model that takes raw solr data and parses it to template-ready condition", function(){
var aw = new AbstractWidget();

Expand Down