aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-17 13:27:35 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-17 13:27:35 +0900
commit78233b25b76df55d519f1d9082267aba876b4835 (patch)
tree05cea028a87f067a83d02638f187b92b3ec6ecd9 /test
parentae317113e76b593949385102e6bea16e50c16ce5 (diff)
parentac8f7e65dc90327e05fb30fd5b20d56c3799f3d8 (diff)
Merge branch 'pagenation-and-navigation'
Diffstat (limited to 'test')
-rw-r--r--test/content/navigates.test.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/content/navigates.test.js b/test/content/navigates.test.js
new file mode 100644
index 0000000..cf20435
--- /dev/null
+++ b/test/content/navigates.test.js
@@ -0,0 +1,56 @@
+import { expect } from "chai";
+import * as navigates from '../../src/content/navigates';
+
+describe('navigates module', () => {
+ describe('#linkPrev', () => {
+ it('clicks prev link by text content', (done) => {
+ document.body.innerHTML = '<a href="#dummy">xprevx</a> <a href="#prev">go to prev</a>';
+ navigates.linkPrev(window);
+ setTimeout(() => {
+ expect(document.location.hash).to.equal('#prev');
+ done();
+ }, 0);
+ });
+
+ it('clicks a[rel=prev] element preferentially', (done) => {
+ document.body.innerHTML = '<a href="#dummy">prev</a> <a rel="prev" href="#prev">rel</a>';
+ navigates.linkPrev(window);
+ setTimeout(() => {
+ expect(document.location.hash).to.equal('#prev');
+ done();
+ }, 0);
+ });
+ });
+
+
+ describe('#linkNext', () => {
+ it('clicks next link by text content', (done) => {
+ document.body.innerHTML = '<a href="#dummy">xnextx</a> <a href="#next">go to next</a>';
+ navigates.linkNext(window);
+ setTimeout(() => {
+ expect(document.location.hash).to.equal('#next');
+ done();
+ }, 0);
+ });
+
+ it('clicks a[rel=next] element preferentially', (done) => {
+ document.body.innerHTML = '<a href="#dummy">next</a> <a rel="next" href="#next">rel</a>';
+ navigates.linkNext(window);
+ setTimeout(() => {
+ expect(document.location.hash).to.equal('#next');
+ done();
+ }, 0);
+ });
+ });
+
+ describe('#parent', () => {
+ // NOTE: not able to test location
+ it('removes hash', () => {
+ window.location.hash = "#section-1";
+ navigates.parent(window);
+ expect(document.location.hash).to.be.empty;
+ });
+ });
+});
+
+