Skip to content

Commit

Permalink
Merge pull request #140 from thirdiron/feature/BZ-9424-Fix-ejp-duplic…
Browse files Browse the repository at this point in the history
…ate-links

BZ-9424 SerSol 360 Handles Duplicate ISSNs
  • Loading branch information
Evroble authored Dec 17, 2024
2 parents ccdcfba + 05fcb32 commit 3f5c179
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 49 deletions.
32 changes: 15 additions & 17 deletions src/360-core/browzine-360-core-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ browzine.serSol360Core = (function() {

function getIssn(title) {
if (title.identifiers) {
var issnIdentifier = title.identifiers.filter(function(identifier) {
var issnIdentifierArray = title.identifiers.filter(function(identifier) {
if (identifier.type && identifier.value) {
return identifier.type.toLowerCase() === "issn" && identifier.value.length > 0;
}
}).pop();
});

if (issnIdentifier) {
return encodeURIComponent(issnIdentifier.value);
}
if (issnIdentifierArray[0]) {
return encodeURIComponent(issnIdentifierArray[0].value);
};

var eissnIdentifier = title.identifiers.filter(function(identifier) {
if (identifier.type && identifier.value) {
Expand All @@ -55,15 +55,14 @@ browzine.serSol360Core = (function() {
return (title && title.title) ? title.title : '';
};

function getTarget(title) {
var issn = getIssn(title).toLowerCase().trim();

var element = $(".results-identifier").filter(function() {
return $.trim($(this).text()).toLowerCase().indexOf(issn) > -1 && issn.length > 0;
}).closest(".results-title-row");

var target = element.length > 0 ? element[0] : undefined;
function getTarget(index) {
var elements = $(".results-identifier").closest(".results-title-row");

if (index >= elements.length) {
var target = undefined;
} else {
var target = elements[index];
}
return target;
};

Expand All @@ -80,10 +79,9 @@ browzine.serSol360Core = (function() {

function addTargets(titles) {
var titlesToEnhance = [];

titles.forEach(function(title) {
titles.forEach(function(title, index) {
var issn = getIssn(title);
title.target = getTarget(title);
title.target = getTarget(index);
title.endpoint = getEndpoint(issn);
title.shouldEnhance = shouldEnhance(issn);

Expand Down Expand Up @@ -220,7 +218,7 @@ browzine.serSol360Core = (function() {
var title = titles.shift();

if (title) {
$.getJSON(title.endpoint, function(response) {
$.getJSON(title.endpoint, function (response) {
var data = getData(response);
var browzineWebLink = getBrowZineWebLink(data);
var coverImageUrl = getCoverImageUrl(data);
Expand Down
128 changes: 123 additions & 5 deletions tests/acceptance/browzine-360-core-adapter-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe("BrowZine SerSol 360 Core Adapter >", function() {
describe("BrowZine SerSol 360 Core Adapter >", function () {
var serSol360Core = {}, searchResults = {};
var results = "<div ui-view='searchResults'><div class='results-title-data'><div class='results-title-row'><div class='results-title-image-div'></div><div class='results-title-details'><div class='results-title'>The New England journal of medicine</div><div class='results-identifier'>ISSN: 0028-4793</div></div></div></div></div>";
results = "<div ui-view='searchResultsForCoreAdapterTest'><div class='results-title-data'><div class='results-title-row'><div class='results-title-image-div'></div><div class='results-title-details'><div class='results-title'>The New England journal of medicine</div><div class='results-identifier'>ISSN: 0028-4793</div></div></div></div></div>";

$("body").append(results);

Expand All @@ -11,7 +11,7 @@ describe("BrowZine SerSol 360 Core Adapter >", function() {
browzine.journalCoverImagesEnabled = false;
browzine.journalBrowZineWebLinkTextEnabled = false;

searchResults = $("div[ui-view='searchResults']");
searchResults = $("div[ui-view='searchResultsForCoreAdapterTest']");

inject(function ($compile, $rootScope) {
$scope = $rootScope.$new();
Expand Down Expand Up @@ -68,10 +68,10 @@ describe("BrowZine SerSol 360 Core Adapter >", function() {
});

describe("search results journal with browzine web link >", function() {
beforeEach(function() {
beforeEach(function () {
serSol360Core = browzine.serSol360Core;

searchResults = $("div[ui-view='searchResults']");
searchResults = $("div[ui-view='searchResultsForCoreAdapterTest']");

inject(function ($compile, $rootScope) {
$scope = $rootScope.$new();
Expand Down Expand Up @@ -144,5 +144,123 @@ describe("BrowZine SerSol 360 Core Adapter >", function() {
expect(window.open).toHaveBeenCalledWith("https://browzine.com/libraries/XXX/journals/10292", "_blank");
});
});

xdescribe("multiple search results for journals with the same issn with browzine web links >", function () {
var serSol360Core = {}, searchResultsSameIssn = {};
beforeEach(function () {

const testData =
`<div ui-view="searchResultsMultipleJournalsSameIssnTest">
<div class="results-title-data">
<div class="results-title-row">
<div class="results-title-image-div"></div>
<div class="results-title-details">
<div class="results-title">The New England Journal of Medicine (NEJM)</div>
<div class="results-identifier">ISSN: 0028-4793</div>
</div>
</div>
<div class="results-title-row">
<div class="results-title-image-div"></div>
<div class="results-title-details">
<div class="results-title">The New England Journal of Medicine - international ED</div>
<div class="results-identifier">ISSN: 0028-4793</div>
</div>
</div>
<div class="results-title-row">
<div class="results-title-image-div"></div>
<div class="results-title-details">
<div class="results-title">The New England Journal of Medicine in Espanol</div>
<div class="results-identifier">ISSN: 0028-4793</div>
</div>
</div>
</div>
</div>`

var multipleResultsSameIssn = testData;
$("body").append(multipleResultsSameIssn);

serSol360Core = browzine.serSol360Core;

searchResultsSameIssn = $("div[ui-view='searchResultsMultipleJournalsSameIssnTest']");


inject(function ($compile, $rootScope) {
$scope = $rootScope.$new();

$scope.searchResultsCtrl = {
titleData: {
titles: [
{
title: "New England Journal of Medicine (NEJM)",
syndeticsImageUrl: "https://secure.syndetics.com/index.aspx?isbn=/mc.gif&issn=0028-4793&client=mistatesum",
identifiers: [{type: "ISSN", value: "0028-4793"}, {type: "eISSN", value: ""}]
},
{
title: "The New England Journal of Medicine - international ED",
syndeticsImageUrl: "https://secure.syndetics.com/index.aspx?isbn=/mc.gif&issn=0028-4793&client=mistatesum",
identifiers: [{type: "ISSN", value: "0028-4793"}, {type: "eISSN", value: ""}]
},
{
title: "The New England Journal of Medicine in Espanol",
syndeticsImageUrl: "https://secure.syndetics.com/index.aspx?isbn=/mc.gif&issn=0028-4793&client=mistatesum",
identifiers: [{type: "ISSN", value: "0028-4793"}, {type: "eISSN", value: ""}]
}
]
}
};

searchResultsSameIssn = $compile(searchResultsSameIssn)($scope);
});

$.getJSON = function (endpoint, callback) {
//this getJSON and the callback correspond to our searchTitles function's getJSON. This is essentially our mocked response
//The problem is our function is looping through and only expecting one piece of data, and if there is more, it is only taking the first piece.
return callback({
"data": [{
"id": 10292,
"type": "journals",
"title": "New England Journal of Medicine (NEJM)",
"issn": "00284793",
"sjrValue": 14.619,
"coverImageUrl": "https://assets.thirdiron.com/images/covers/0028-4793.png",
"browzineEnabled": true,
"browzineWebLink": "https://browzine.com/libraries/XXX/journals/10292"
},
{
"id": 10293,
"type": "journals",
"title": "The New England Journal of Medicine - international ED",
"issn": "00284793",
"sjrValue": 14.619,
"coverImageUrl": "https://assets.thirdiron.com/images/covers/0028-4793.png",
"browzineEnabled": true,
"browzineWebLink": "https://browzine.com/libraries/XXX/journals/10293"
},
{
"id": 10294,
"type": "journals",
"title": "The New England Journal of Medicine in Espanol",
"issn": "00284793",
"sjrValue": 14.619,
"coverImageUrl": "https://assets.thirdiron.com/images/covers/0028-4793.png",
"browzineEnabled": true,
"browzineWebLink": "https://browzine.com/libraries/XXX/journals/10294"
}
]
});
};

serSol360Core.adapter(searchResultsSameIssn);
});

it("should have enhanced view journal in browzine options for each result", function() {
var template = searchResultsSameIssn.find(".browzine");
console.log(template, 'our template in our new tests');
expect(template).toBeDefined();

expect(template.text().trim()).toEqual("View Journal in BrowZine");
expect((template.text().trim().match(/View Journal in BrowZine/g) || []).length).toEqual(3);
});
})
});
});
37 changes: 10 additions & 27 deletions tests/unit/models/360-core.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
describe("SerSol 360 Core Model >", function() {
var serSol360Core = {}, journalResponse = {}, scope = {}, titles = [], searchResults = {};
var results = "<div ui-view='searchResults'><div class='results-title-data'><div class='results-title-row'><div class='results-title-image-div'><img src='' ng-src='' class='results-title-image'/></div><div class='results-title-details'><div class='results-title'>The Base Journal</div><div class='results-identifier'>ISSN: 0028-4793</div></div></div></div></div>";
var results = "<div ui-view='searchResultsForCoreModelTest'><div class='results-title-data'><div class='results-title-row'><div class='results-title-image-div'><img src='' ng-src='' class='results-title-image'/></div><div class='results-title-details'><div class='results-title'>The Base Journal: A Test!</div><div class='results-identifier'>ISSN: 0028-4793</div></div></div></div></div>";

$("body").append(results);

beforeEach(function() {
serSol360Core = browzine.serSol360Core;

searchResults = $("div[ui-view='searchResults']");
searchResults = $("div[ui-view='searchResultsForCoreModelTest']");

inject(function ($compile, $rootScope) {
$scope = $rootScope.$new();
Expand Down Expand Up @@ -311,22 +311,22 @@ describe("SerSol 360 Core Model >", function() {

describe("serSol360Core model getTarget method >", function() {
it("should retrieve target element for a journal search result", function() {
var title = titles[0];
var target = serSol360Core.getTarget(title);
var index = 0;
var target = serSol360Core.getTarget(index);
expect(target).toBeDefined();
expect(target.innerHTML).toContain("The New England journal of medicine");
});

it("should return undefined for a journal search result with no journal issn", function() {
var title = titles[0];
delete title.identifiers;
var target = serSol360Core.getTarget(title);
it("should return undefined for a journal search result when there are more titles than elements on the page", function() {
expect(titles.length).toEqual(4);
var index = 4
var target = serSol360Core.getTarget(index);
expect(target).toBeUndefined();
});

it("should retrieve target element when the results identifier element contains the journal issn", function() {
var title = titles[0];
var target = serSol360Core.getTarget(title);
var index = 0
var target = serSol360Core.getTarget(index);

expect(target).toBeDefined();
expect(target.innerHTML).toContain("The New England journal of medicine");
Expand All @@ -351,23 +351,6 @@ describe("SerSol 360 Core Model >", function() {
});
});

describe("serSol360Core model getEndpoint method >", function() {
it("should build a journal endpoint for a journal search result", function() {
var title = titles[0];
expect(title.endpoint).toContain("search?issns=00284793");
});

it("should select the issn over the eissn when a journal search result includes both", function() {
var title = titles[0];
expect(title.endpoint).toContain("search?issns=00284793");
});

it("should select the eissn when the journal search result has no issn", function() {
var title = titles[1];
expect(title.endpoint).toContain("search?issns=2163307X");
});
});

describe("serSol360Core model getBrowZineWebLink method >", function() {
it("should include a browzineWebLink in the BrowZine API response for a journal", function() {
var data = serSol360Core.getData(journalResponse);
Expand Down

0 comments on commit 3f5c179

Please sign in to comment.