Commit 42abc767 authored by Maxime Chaillet's avatar Maxime Chaillet

Fixing console.log bug with karma.

parent bb200e4d
......@@ -4,6 +4,7 @@
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
......@@ -56,11 +57,24 @@ module.exports = function (config) {
colors: true,
client: {
captureConsole: true
},
browserConsoleLogOptions: {
level: 'log',
format: '%b %T: %m',
terminal: true
},
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
......
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
function DoiData(title, doi, dataciteLink, publisher, creator, publication_year) {
this.title = title;
function DoiData(doi, dataciteLink, publisher, creator, publication_year) {
this.doi = doi;
this.dataciteLink = dataciteLink;
this.publisher = publisher;
......
......@@ -27,66 +27,86 @@ function DOIController(view) {
* executed. Reloading the page is treated by .fail as it should be.
*/
DOIController.prototype.isValidDOIData = function (doiData) {
if (_.keysIn(doiData).length > 3) {
return _.find(_.keysIn(doiData), function (value) {
return value === "title";
}).length > 0;
}
return false;
// console.log(doiData)
// if (_.keysIn(doiData).length > 3) {
// return _.find(_.keysIn(doiData), function (value) {
// return value === "title";
// }).length > 0;
// }
// return false;
return true;
};
DOIController.prototype.render = function (doi, data) {
var _this = this;
// Test abnormal length of the json object
if (!_this.isValidDOIData(data)) {
_this.view.renderError("Not Found", _this.origin);
} else {
// Extract data and fill doiData with it
var doiData = new DoiData(data.title, data.doi.toUpperCase(), _this.doiServer + doi, data.publisher, data.creator, data.publication_year);
var jsonExtractor = new JsonExtractor();
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.getInvestigationId(data);
doiData.mintingYear = jsonExtractor.getMintingYear(data);
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
doiData.resourceType = jsonExtractor.getResourceType(data);
doiData.resourceTypeGeneral = jsonExtractor.getResourceTypeGeneral(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data);
var proposalNames = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
var beamlines = jsonExtractor.getFieldFromSubject(data.subject, "Instrument");
_this.experimentalReportController.requestFilenameList(proposalNames[0]);
doiData.accessibility = doiData.getAccessibilityStatus(doiData.resourceType, doiData.sessionDate, doiData.publiclyAccessibleYear);
doiData.accessMessage = _this.view.setDataAccessMessage(doiData);
doiData.citation = _this.createCitation(data);
if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, data.date_collected, doiData.resourceType);
}
// Test abnormal length of the json object
if (!_this.isValidDOIData(data)) {
_this.view.renderError("Not Found", _this.origin);
} else {
// Extract data and fill doiData with it
if (doiData.resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, data.publication_year, doiData.resourceType);
}
// Create a table containing unique tuples [proposal, beamline, beamlineUrl]
doiData.mergedProposalBeamlines = jsonExtractor.getMergedProposalAndBeamline(proposalNames, beamlines, doiData.beamlineUrls);
// send to dust render
_this.view.renderDOIData(doiData);
}
//var doiData = new doiData();
var doiData = new DoiData(data.doi.toUpperCase(), _this.doiServer + doi, data.publisher, data.creator, data.publication_year);
var jsonExtractor = new JsonExtractor();
doiData.title = jsonExtractor.getTitle(data);
doiData.doi = jsonExtractor.getDOI(data);
doiData.dataciteLink = _this.doiServer + doi;
doiData.publisher = jsonExtractor.getPublisher(data);
doiData.creators = jsonExtractor.getCreators(data);
// var jsonExtractor = new JsonExtractor();
// doiData.abstract = jsonExtractor.getAbstract(data);
// doiData.investigationId = jsonExtractor.getInvestigationId(data);
// doiData.mintingYear = jsonExtractor.getMintingYear(data);
// doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
// doiData.resourceType = jsonExtractor.getResourceType(data);
// doiData.resourceTypeGeneral = jsonExtractor.getResourceTypeGeneral(data);
// doiData.sessionDate = jsonExtractor.getSessionDate(data);
// var proposalNames = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
// var beamlines = jsonExtractor.getFieldFromSubject(data.subject, "Instrument");
// _this.experimentalReportController.requestFilenameList(proposalNames[0]);
// doiData.accessibility = doiData.getAccessibilityStatus(doiData.resourceType, doiData.sessionDate, doiData.publiclyAccessibleYear);
// doiData.accessMessage = _this.view.setDataAccessMessage(doiData);
// doiData.citation = _this.createCitation(data);
// if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
// doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, data.date_collected, doiData.resourceType);
// }
// if (doiData.resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
// doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, data.publication_year, doiData.resourceType);
// }
// Create a table containing unique tuples [proposal, beamline, beamlineUrl]
doiData.mergedProposalBeamlines = jsonExtractor.getMergedProposalAndBeamline(proposalNames, beamlines, doiData.beamlineUrls);
// send to dust render
_this.view.renderDOIData(doiData);
}
};
DOIController.prototype.getData = function (doi) {
var _this = this;
this.view.setDOIInTopBanner(doi);
if (doi.toUpperCase() == "10.15151/ESRF-DC-142893590"){
if (doi.toUpperCase() == "10.15151/ESRF-DC-142893590") {
this.render(doi, ESRF_DC_142893590);
return;
}
if (doi.toUpperCase() == "10.15151/ESRF-DC-142915526"){
if (doi.toUpperCase() == "10.15151/ESRF-DC-142915526") {
this.render(doi, ESRF_DC_142915526);
return;
}
......@@ -110,7 +130,7 @@ DOIController.prototype.getData = function (doi) {
.done(function (data) {
if (data) {
_this.render(doi, data);
_this.render(doi, data);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
_this.view.renderError(jqXHR, errorThrown, _this.origin);
......@@ -179,7 +199,7 @@ DOIController.prototype.getBeamlineUrl = function (beamlines, date, resourceType
if (resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
date = moment(date, "YYYY");
}
var foundUrl = "";
for (var i = 0; i < BEAMLINEURL.length; i++) {
var startDate = moment(BEAMLINEURL[i].startDate);
......
function JsonExtractor(json) {
/**
* This is the json extractor. It tries to extract from the json datacite object the required fields to render the DOI
* landing page.
*/
function JsonExtractor() {
}
/**
* Extract the DOI title from the datacite's JSON response.
* @param {string} data The data object provided by datacite
* @return {string} doi title. Null if it does not exist
*/
JsonExtractor.prototype.getTitle = function (data) {
if (data) {
if (data.titles) {
if (data.titles.length > 0) {
if (data.titles[0].title) {
return data.titles[0].title;
}
}
}
}
return null;
}
/**
* Extract the DOI number from the datacite's JSON response.
* @param {string} data The data object provided by datacite
* @return {string} doi number. Null if it does not exist.
*/
JsonExtractor.prototype.getDOI = function (data) {
if (data) {
if (data.doi) {
return data.doi.toUpperCase();
}
}
return null;
}
/**
* Extract the DOI publisher from the datacite's JSON response.
* @param {string} data The data object provided by datacite
* @return {string} doi publisher. Null if it does not exist.
*/
JsonExtractor.prototype.getPublisher = function (data) {
if (data) {
if (data.publisher) {
return data.publisher;
}
}
return null;
}
/**
* Extract the DOI authors/creators from the datacite's JSON response.
* @param {string} data The data object provided by datacite
* @return {array} doi creators. Null if it does not exist. When creators details are not available, it returns
* a null item within the table.
*/
JsonExtractor.prototype.getCreators = function (data) {
console.log('salut')
if (data) {
if (data.creators) {
var test = _.map(data.creators, (item) => {
if ((item.givenName && item.familyName) || item.name) {
return item;
} else {
return null;
}
})
console.log(test)
return {
creators: test
}
}
}
return null;
}
/**
......@@ -9,8 +85,8 @@ function JsonExtractor(json) {
*/
JsonExtractor.prototype.getInvestigationId = function (data) {
var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);
if (regExp.exec( data.doi )){
return regExp.exec( data.doi )[1];
if (regExp.exec(data.doi)) {
return regExp.exec(data.doi)[1];
}
return null;
};
......
......@@ -151,6 +151,110 @@ describe("jsonExtractor", () => {
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getInvestigationId(actualDOIdata)).toEqual(expectedInvestigationId);
})
})
describe("GetTitle", () => {
it('returns the title for an experimental session doi', () => {
let actualDOIdata = {
"titles": [
{
"title": "Kmapping of Ge microdisks"
}
],
};
let expectedDOITitle = "Kmapping of Ge microdisks";
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getTitle(actualDOIdata)).toEqual(expectedDOITitle);
})
it('returns null when titles is empty', () => {
let actualDOIdata = {
"titles": [
],
};
let expectedDOITitle = null;
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getTitle(actualDOIdata)).toBeNull();
})
it('returns null when title is empty', () => {
let actualDOIdata = {
"titles": [
{
"title": null
}
],
};
let expectedDOITitle = null;
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getTitle(actualDOIdata)).toBeNull();
})
})
describe("GetDOI", () => {
it('returns the DOI for an experimental session doi', () => {
let actualDOIdata = {
"doi": "10.15151/esrf-es-90632078",
};
let expectedDOINumber = "10.15151/ESRF-ES-90632078";
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getDOI(actualDOIdata)).toEqual(expectedDOINumber);
})
it('returns null when doi is empty', () => {
let actualDOIdata = {
"doi": null,
};
let expectedDOINumber = null;
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getDOI(actualDOIdata)).toBeNull();
})
})
describe("GetPublisher", () => {
it('returns the publisher for an experimental session doi', () => {
let actualDOIdata = {
"publisher": "European Synchrotron Radiation Facility",
};
let expectedPublisher = "European Synchrotron Radiation Facility";
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getPublisher(actualDOIdata)).toEqual(expectedPublisher);
})
it('returns null when the publisher is not set', () => {
let actualDOIdata = {
"publisher": null,
};
let expectedPublisher = null;
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getPublisher(actualDOIdata)).toEqual(expectedPublisher);
})
})
describe("GetCreators", () => {
it('returns the creators for an experimental session doi', () => {
let actualDOIdata = {
"creators": [
{
"nameType": "Personal",
"name": "LEAKE, Steven",
"givenName": "Steven",
"familyName": "LEAKE"
},
{
"nameType": "Personal",
"name": "ZATTERIN, Edoardo",
"givenName": "Edoardo",
"familyName": "ZATTERIN"
}
]
};
let expectedCreators = actualDOIdata;
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getPublisher(actualDOIdata)).toEqual(expectedCreators);
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment