Skip to content

Commit

Permalink
so many changes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
respinos committed Mar 16, 2018
1 parent 39a468b commit 0e7e092
Show file tree
Hide file tree
Showing 11 changed files with 1,713 additions and 311 deletions.
1,595 changes: 1,424 additions & 171 deletions dist/cozy-sun-bear.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cozy-sun-bear.js.map

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ var buble = require('rollup-plugin-buble'); // ES6 to ES5 transpiler
var commonjs = require('rollup-plugin-commonjs');
var nodeResolve = require('rollup-plugin-node-resolve');

function getSpecs(specList) {
if (specList) {
return specList.split(',')
} else {
return ['spec/**/*Spec.js'] // whatever your default glob is
}
}

// Karma configuration
module.exports = function (config) {
var files = [
Expand All @@ -11,8 +19,8 @@ module.exports = function (config) {
"node_modules/expect.js/index.js",
"node_modules/happen/happen.js",
"node_modules/prosthetic-hand/dist/prosthetic-hand.js",
"spec/SpecHelper.js",
"spec/**/*Spec.js"
"spec/SpecHelper.js" //,
// "spec/**/*Spec.js"
];

var exclude = [
Expand All @@ -39,7 +47,7 @@ module.exports = function (config) {
frameworks: ['mocha'],

// list of files / patterns to load in the browser
files: files,
files: files.concat(getSpecs(process.env.KARMA_SPECS)),

// list of files / patterns to exclude from invoking
exclude: exclude,
Expand All @@ -61,7 +69,7 @@ module.exports = function (config) {
},

// test results reporter(s) to use possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['dots', 'coverage', 'coveralls'],
reporters: ['dots', 'coverage', 'coveralls', 'progress'],
coverageReporter: {
type: 'lcov',
dir: 'coverage/'
Expand All @@ -72,7 +80,8 @@ module.exports = function (config) {

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_WARN,
logLevel: config.LOG_INFO,
// logLevel: config.LOG_DEBUG,

// enable / disable colors in the output (reporters and logs)
colors: true,
Expand Down Expand Up @@ -110,6 +119,13 @@ module.exports = function (config) {
terminal: true
},

client: {
captureConsole: true,
mocha: {
bail: true
}
},

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 5000,

Expand Down
144 changes: 116 additions & 28 deletions spec/control/Control.BibliographicInformationSpec.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,123 @@
describe("Control.BibliographicInformation", function () {
var reader;
var reader; var control;
var options = { region: 'top.toolbar.left' };

beforeEach(function() {
reader = cozy.reader(document.createElement('div'), {
engine: 'mock',
href: 'mock.epub',
metadata: {
doi: 'https://doi.org/10.0000/cozy.0000'
}
});
});

it("can be added to an unloaded reader", function () {
new cozy.Control.BibliographicInformation(options).addTo(reader);
});

it("can be added and use the default metadata via modal", function () {
var control = new cozy.Control.BibliographicInformation(options).addTo(reader);
reader.start(function() {
happen.click(control._control);
var selector = function(key) {
return "dd.cozy-bib-info-value-" + key;
};

var container = control._modal._container;
var keys = [ 'title', 'creator', 'doi' ];
keys.forEach(function(key) {
var expr = "dd.cozy-bib-info-value-" + key;
var node = container.querySelector(expr);
expect(node).not.to.be(null);
expect(node.innerHTML).to.be(reader.metadata[key]);
})
describe("it can work as expected", function() {
beforeEach(function() {
reader = cozy.reader(document.createElement('div'), {
engine: 'mock',
href: 'mock.epub',
metadata: {
doi: 'https://doi.org/10.0000/cozy.0000'
}
});
control = new cozy.Control.BibliographicInformation(options).addTo(reader);
reader.start(function() {
happen.click(control._control);
});
});
});

it("title should be title", function() {
var container = control._modal._container;
var key; var expr; var node;

key = 'title';
expr = selector(key);
node = container.querySelector(expr);
expect(node).to.not.be(null);
expect(node.innerText).to.eql(reader.metadata[key]);
})

it("creator should be creator", function() {
var container = control._modal._container;
var key; var expr; var node;

key = 'creator';
expr = selector(key);
node = container.querySelector(expr);
expect(node).to.not.be(null);
expect(node.innerText).to.eql(reader.metadata[key]);
})

it("doi should be doi", function() {
var container = control._modal._container;
var key; var expr; var node;

key = 'doi';
expr = selector(key);
node = container.querySelector(expr);
expect(node).to.not.be(null);
expect(node.innerText).to.eql(reader.metadata[key]);
})

it("pubdate should be abbreviated", function() {

var container = control._modal._container;
var key; var expr; var node;

key = 'pubdate';
expr = selector(key);
node = container.querySelector(expr);
expect(node).to.not.be(null);
expect(node.innerText).to.not.eql(reader.metadata[key]);
expect(node.innerText).to.eql("2017");
})
})


describe("more date fun", function() {
it("it can deal with MM-DD-YYYY", function() {
reader = cozy.reader(document.createElement('div'), {
engine: 'mock',
href: 'mock.epub',
metadata: {
doi: 'https://doi.org/10.0000/cozy.0000',
pubdate: '01-01-2015'
}
});
control = new cozy.Control.BibliographicInformation(options).addTo(reader);
reader.start(function() {
happen.click(control._control);
});

var container = control._modal._container;
var key; var expr; var node;

key = 'pubdate';
expr = selector(key);
node = container.querySelector(expr);
expect(node).to.not.be(null);
expect(node.innerText).to.eql("2015");
})

it("it can deal with YYYY", function() {
reader = cozy.reader(document.createElement('div'), {
engine: 'mock',
href: 'mock.epub',
metadata: {
doi: 'https://doi.org/10.0000/cozy.0000',
pubdate: '1998'
}
});
control = new cozy.Control.BibliographicInformation(options).addTo(reader);
reader.start(function() {
happen.click(control._control);
});

var container = control._modal._container;
var key; var expr; var node;

key = 'pubdate';
expr = selector(key);
node = container.querySelector(expr);
expect(node).to.not.be(null);
expect(node.innerText).to.eql("1998");
})
})

});

59 changes: 36 additions & 23 deletions spec/control/Control.CitationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,47 @@ describe("Control.Citation", function () {
{ format: 'Chicago', text: "Mock, Alex. <em>The Mock Life</em>. Ann Arbor, MI: University Press, 2017." }
]
}
});
});
});

it("can be added to an unloaded reader", function () {
new cozy.Control.Citation(options).addTo(reader);
});

it("can be added and use the default metadata via modal", function () {
var control = new cozy.Control.Citation(options).addTo(reader);
reader.start(function() {
happen.click(control._control);

var possibles =
[
[ 'MLA', "Mock, Alex. <em>The Mock Life</em>. University Press, 2017." ],
[ 'APA', "Mock, A. (2017). <em>The Mock Life</em>. Ann Arbor, MI: University Press." ],
[ 'Chicago', "Mock, Alex. <em>The Mock Life</em>. Ann Arbor, MI: University Press, 2017." ]
];

for(var i in possibles) {
var value = possibles[i][0];
var test = possibles[i][1];

var formatted = control._formatCitation(value);
expect(formatted).to.be(test);
}
});

});
describe("use the default metadata via modal", function() {
beforeEach(function() {
control = new cozy.Control.Citation(options).addTo(reader);
reader.start(function() {
happen.click(control._control);
});
})

var format; var test; var formatted;
var possibles = {
'MLA': "Mock, Alex. <em>The Mock Life</em>. University Press, 2017.",
'APA': "Mock, A. (2017). <em>The Mock Life</em>. Ann Arbor, MI: University Press.",
'Chicago': "Mock, Alex. <em>The Mock Life</em>. Ann Arbor, MI: University Press, 2017."
};

it("should format MLA", function() {
format = 'MLA';
formatted = control._formatCitation(format);
expect(formatted).to.eql(possibles[format]);
})

it("should format APA", function() {
format = 'APA';
formatted = control._formatCitation(format);
expect(formatted).to.eql(possibles[format]);
})

it("should format Chicago", function() {
format = 'Chicago';
formatted = control._formatCitation(format);
expect(formatted).to.eql(possibles[format]);
})


})
});

74 changes: 41 additions & 33 deletions spec/control/Control.ContentsSpec.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,58 @@
describe("Control.Contents", function () {
var reader;
var reader; var control;
var options = { region: 'top.toolbar.left' };

beforeEach(function() {
reader = cozy.reader(document.createElement('div'), {
engine: 'mock',
href: 'mock.epub',
describe("no skip link", function() {
beforeEach(function() {
reader = cozy.reader(document.createElement('div'), {
engine: 'mock',
href: 'mock.epub',
});

control = new cozy.Control.Contents(options).addTo(reader);
reader.start(function() {
happen.click(control._control);
});
});
});

it("can be added to an unloaded reader", function () {
new cozy.Control.Contents(options).addTo(reader);
});

it("contents panel will be constructed", function () {
var control = new cozy.Control.Contents(options).addTo(reader);

reader.start(function() {
happen.click(control._control);

it("contents panel will be constructed", function () {
var div = control._modal._container;
var n = div.querySelectorAll("a");
expect(node).not.to.be(0);
var node = div.querySelectorAll("a");
expect(node.length).not.to.eql(0);
});

it("skip link WILL NOT be created", function () {
// expect(document.getElementById(control._id)).to.be(null);
var link = document.querySelector("a[href='#action-" + control._id + "']");
expect(link).to.be(null);
});
});
})

it("skip link WILL NOT be created", function () {
var control = new cozy.Control.Contents(options).addTo(reader);
describe("skip link", function() {
var skip_div;

reader.start(function() {
expect(document.getElementById(control._id)).to.be(null);
});
});
beforeEach(function() {
var skip_div = document.createElement('div');
skip_div.setAttribute('class', 'skip');
document.body.appendChild(skip_div);

it("skip link WILL be created", function () {
var skip_div = document.createElement('div');
skip_div.setAttribute('class', 'skip');
document.body.appendChild(skip_div);
reader = cozy.reader(document.createElement('div'), {
engine: 'mock',
href: 'mock.epub',
});

var control = new cozy.Control.Contents({ region: options.region, skipLink: '.skip'}).addTo(reader);
control = new cozy.Control.Contents({ region: options.region, skipLink: '.skip'}).addTo(reader);
reader.start(function() {
happen.click(control._control);
});
});

reader.start(function() {
expect(document.getElementById(control._id)).not.to.be(null);
it("skip link WILL be created", function () {
var link = document.querySelector("a[href='#action-" + control._id + "']");
expect(link).not.to.be(null);
});
});

})

});

0 comments on commit 0e7e092

Please sign in to comment.