Skip to content
Snippets Groups Projects
Commit 007e48a7 authored by Chaillet Maxime's avatar Chaillet Maxime
Browse files

Fix old tests. It fixes #85

parent 31c344f3
No related branches found
No related tags found
No related merge requests found
Pipeline #37608 passed
// Karma configuration // Karma configuration
// Generated on Thu Oct 11 2018 23:09:22 GMT+0200 (CEST) // Generated on Thu Oct 11 2018 23:09:22 GMT+0200 (CEST)
module.exports = function(config) { module.exports = function (config) {
config.set({ config.set({
// base path that will be used to resolve all patterns (eg. files, exclude) // base path that will be used to resolve all patterns (eg. files, exclude)
basePath: "", basePath: "",
// frameworks to use // frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ["jasmine", "browserify", "jquery-3.4.0"], frameworks: ["jasmine", "browserify", "jquery-3.4.0"],
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ files: [
"bower_components/dustjs-linkedin/dist/dust-full.js", "bower_components/dustjs-linkedin/dist/dust-full.js",
"bower_components/lodash/lodash.js", "bower_components/lodash/lodash.js",
"bower_components/moment/moment.js", "bower_components/moment/moment.js",
"src/*.js", "src/*.js",
"templates/welcome_tpl.js", "templates/welcome_tpl.js",
"tests/*js" "tests/*js"
], ],
// list of files / patterns to exclude // list of files / patterns to exclude
exclude: [], exclude: [],
// preprocess matching files before serving them to the browser // preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: { preprocessors: {
"tests/jsonExtractor.test.js": ["browserify"], "tests/jsonExtractor.test.js": ["browserify"],
"tests/googleMetadataObject.test.js": ["browserify"], "tests/googleMetadataObject.test.js": ["browserify"],
"tests/welcomeTemplate.test.js": ["browserify"], "tests/welcomeTemplate.test.js": ["browserify"],
"templates/welcome_tpl.js": ["html2js"] "templates/welcome_tpl.js": ["html2js"]
}, },
// test results reporter to use // test results reporter to use
// possible values: 'dots', 'progress' // possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter // available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ["progress"], reporters: ["mocha"],
// web server port // web server port
port: 9876, port: 9876,
// enable / disable colors in the output (reporters and logs) // enable / disable colors in the output (reporters and logs)
colors: true, colors: true,
// level of logging // level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO, logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes // enable / disable watching file and executing tests whenever any file changes
autoWatch: true, autoWatch: true,
// start these browsers // start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
//browsers: ['Firefox', 'Chrome'], //browsers: ['Firefox', 'Chrome'],
browsers: ["Firefox"], browsers: ["Firefox"],
// Continuous Integration mode // Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits // if true, Karma captures browsers, runs the tests and exits
singleRun: false, singleRun: false,
// Concurrency level // Concurrency level
// how many browser should be started simultaneous // how many browser should be started simultaneous
concurrency: Infinity concurrency: Infinity
}); });
}; };
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
"karma-html2js-preprocessor": "^1.1.0", "karma-html2js-preprocessor": "^1.1.0",
"karma-jasmine": "^1.1.2", "karma-jasmine": "^1.1.2",
"karma-jquery": "^0.2.4", "karma-jquery": "^0.2.4",
"karma-mocha-reporter": "^2.2.5",
"watchify": "^3.11.0" "watchify": "^3.11.0"
}, },
"scripts": { "scripts": {
......
function DoiData() { function DoiData() { }
}
/** /**
* Get the accessibility status * Get the accessibility status
* @param {string} resourceType the resource type for this DOI * @param {string} resourceType the resource type for this DOI
* @param {string} sessionDate The timeStamp the experiment was started * @param {string} sessionDate The timeStamp the experiment was started
* @param {string} publiclyAccessibleYear The year the data will be publicly accesssible. * @param {string} publiclyAccessibleYear The year the data will be publicly accesssible.
* @return {string} * @return {string}
* "Open access" : the data is publicly accessible * "Open access" : the data is publicly accessible
* "Restricted access" : the data is still under embargo. Only accessible to experimental team members * "Restricted access" : the data is still under embargo. Only accessible to experimental team members
* *
* */ * */
DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate, publiclyAccessibleYear) { DoiData.prototype.getAccessibilityStatus = function (
resourceType,
sessionDate,
publiclyAccessibleYear
) {
if (resourceType) { if (resourceType) {
if (resourceType === CONSTANTS.ES_RESOURCE_TYPE) { if (resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
if (publiclyAccessibleYear && sessionDate) { if (publiclyAccessibleYear && sessionDate) {
// take day and month of sessionDate and year of publiclyAccessibleYear // take day and month of sessionDate and year of publiclyAccessibleYear
var publiclyAvailableDate = moment(sessionDate).year(parseInt(publiclyAccessibleYear)); var publiclyAvailableDate = moment(sessionDate).year(
parseInt(publiclyAccessibleYear)
);
var now = moment(); var now = moment();
if (now > publiclyAvailableDate) { if (now > publiclyAvailableDate) {
...@@ -32,4 +37,3 @@ DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate, ...@@ -32,4 +37,3 @@ DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate,
console.log("Failed to determine whether the accessibility of the DOI."); console.log("Failed to determine whether the accessibility of the DOI.");
return "Accessibility status could not be determined"; return "Accessibility status could not be determined";
}; };
describe("citation", () => { describe("citation", () => {
describe("getDOIRegistrationYear", () => { describe("getDOIRegistrationYear", () => {
it("Returns the year for experimental session", () => { it("Returns the year for experimental session", () => {
let actualDoiData = { let actualDoiData = {
resourceType: "experimental session resource type", resourceType: "experimental session resource type",
sessionDate: "2017-12-31", sessionDate: "2017-12-31",
publiclyAccessibleYear: "2018" publiclyAccessibleYear: "2018"
}; };
let expectedYear = 2017; let expectedYear = 2017;
let myCitation = new Citation(); let myCitation = new Citation();
expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual( expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual(
expectedYear expectedYear
); );
}); });
it("Returns the year for datacollection session", () => { it("Returns the year for datacollection session", () => {
// thre is no sessionDate for this kind of DOI // thre is no sessionDate for this kind of DOI
let actualDoiData = { let actualDoiData = {
resourceType: "dataset collection resource type", resourceType: "dataset collection resource type",
publiclyAccessibleYear: "2018" publiclyAccessibleYear: "2018"
}; };
let expectedYear = 2018; let expectedYear = "2018";
let myCitation = new Citation(); let myCitation = new Citation();
expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual( expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual(
expectedYear expectedYear
); );
}); });
it("Returns an empty string when sessionDate is not provided", () => { it("Returns an empty string when sessionDate is not provided", () => {
let actualDoiData = {}; let actualDoiData = {};
let expectedYear = ""; let expectedYear = "";
let myCitation = new Citation(); let myCitation = new Citation();
expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual( expect(myCitation.getDOIRegistrationYear(actualDoiData)).toEqual(
expectedYear expectedYear
); );
});
}); });
});
}); });
describe('DoiData', () => { describe("DoiData", () => {
describe('getAccessibilityStatus', () => { describe("getAccessibilityStatus", () => {
it('Returns open access when today is after publication date', () => { it("Returns open access when today is after publication date", () => {
let doiData = new DoiData(); let doiData = new DoiData();
let actualReourceType = CONSTANTS.ES_RESOURCE_TYPE; let actualReourceType = CONSTANTS.ES_RESOURCE_TYPE;
let actualSessionDate = "2017-01-01" let actualSessionDate = "2017-01-01";
let actualPubliclyAccessibleYear = "2018" let actualPubliclyAccessibleYear = "2018";
expect(doiData.getAccessibilityStatus(actualReourceType, actualSessionDate, actualPubliclyAccessibleYear)).toEqual("Open access"); expect(
}) doiData.getAccessibilityStatus(
actualReourceType,
actualSessionDate,
actualPubliclyAccessibleYear
)
).toEqual("Open access");
});
it('Returns Restricted access when today is before publication date', () => { it("Returns Restricted access when today is before publication date", () => {
let doiData = new DoiData(); let doiData = new DoiData();
let actualReourceType = CONSTANTS.ES_RESOURCE_TYPE; let actualReourceType = CONSTANTS.ES_RESOURCE_TYPE;
let actualSessionDate = "2017-01-01" let actualSessionDate = "2017-01-01";
let actualPubliclyAccessibleYear = "2020" let actualPubliclyAccessibleYear = "2100";
expect(doiData.getAccessibilityStatus(actualReourceType, actualSessionDate, actualPubliclyAccessibleYear)).toEqual("Restricted access"); expect(
}) doiData.getAccessibilityStatus(
actualReourceType,
actualSessionDate,
}) actualPubliclyAccessibleYear
)
}) ).toEqual("Restricted access");
\ No newline at end of file });
});
});
describe("WelcomeTemplate", () => { describe("WelcomeTemplate", () => {
it("Link to all ESRF DOIs", () => { it("Link to all ESRF DOIs", () => {
dust.renderSource( dust.renderSource(
window.__html__["templates/welcome_tpl.js"], window.__html__["templates/welcome_tpl.js"],
{}, {},
(err, out) => { (err, out) => {
$("body").append(out); $("body").append(out);
let a = $("a:contains('List all ESRF DOIs')")[0]; let a = $("a:contains('List all ESRF DOIs')")[0];
expect(a.href).toEqual( expect(a.href).toEqual(
"https://search.datacite.org/works?query=10.15151%2F*" "https://search.datacite.org/works?query=10.15151%2F*"
);
}
); );
} });
);
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment