aboutsummaryrefslogtreecommitdiff
path: root/test/content/presenters/NavigationPresenter.test.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-05-02 17:25:56 +0900
committerGitHub <noreply@github.com>2020-05-02 17:25:56 +0900
commit5df0537bcf65a341e79852b1b30379c73318529c (patch)
treeaee5efe52412855f620cb514a13a2c14373f27b7 /test/content/presenters/NavigationPresenter.test.ts
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
parent75abd90ecb8201ad845b266f96220d8adfe19b2d (diff)
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'test/content/presenters/NavigationPresenter.test.ts')
-rw-r--r--test/content/presenters/NavigationPresenter.test.ts276
1 files changed, 161 insertions, 115 deletions
diff --git a/test/content/presenters/NavigationPresenter.test.ts b/test/content/presenters/NavigationPresenter.test.ts
index 6aa057b..af3b487 100644
--- a/test/content/presenters/NavigationPresenter.test.ts
+++ b/test/content/presenters/NavigationPresenter.test.ts
@@ -1,11 +1,12 @@
-import { NavigationPresenterImpl } from '../../../src/content/presenters/NavigationPresenter';
-import { expect } from 'chai';
+import { NavigationPresenterImpl } from "../../../src/content/presenters/NavigationPresenter";
+import { expect } from "chai";
-describe('NavigationPresenterImpl', () => {
+describe("NavigationPresenterImpl", () => {
let sut: NavigationPresenterImpl;
- const testRel = (done, rel, html) => {
- const method = rel === 'prev' ? sut.openLinkPrev.bind(sut) : sut.openLinkNext.bind(sut);
+ const testRel = (done: () => void, rel: string, html: string) => {
+ const method =
+ rel === "prev" ? sut.openLinkPrev.bind(sut) : sut.openLinkNext.bind(sut);
document.body.innerHTML = html;
method();
setTimeout(() => {
@@ -13,122 +14,167 @@ describe('NavigationPresenterImpl', () => {
done();
}, 0);
};
- const testPrev = html => done => testRel(done, 'prev', html);
- const testNext = html => done => testRel(done, 'next', html);
+ const testPrev = (html: string) => (done: () => void) =>
+ testRel(done, "prev", html);
+ const testNext = (html: string) => (done: () => void) =>
+ testRel(done, "next", html);
before(() => {
sut = new NavigationPresenterImpl();
});
- describe('#linkPrev', () => {
- it('navigates to <link> elements whose rel attribute is "prev"', testPrev(
- '<link rel="prev" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute starts with "prev"', testPrev(
- '<link rel="prev bar" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute ends with "prev"', testPrev(
- '<link rel="foo prev" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute contains "prev"', testPrev(
- '<link rel="foo prev bar" href="#prev" />'
- ));
-
- it('navigates to <a> elements whose rel attribute is "prev"', testPrev(
- '<a rel="prev" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute starts with "prev"', testPrev(
- '<a rel="prev bar" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute ends with "prev"', testPrev(
- '<a rel="foo prev" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute contains "prev"', testPrev(
- '<a rel="foo prev bar" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose text matches "prev"', testPrev(
- '<a href="#dummy">preview</a><a href="#prev">go to prev</a>'
- ));
-
- it('navigates to <a> elements whose text matches "previous"', testPrev(
- '<a href="#dummy">previously</a><a href="#prev">previous page</a>'
- ));
-
- it('navigates to <a> elements whose decoded text matches "<<"', testPrev(
- '<a href="#dummy">click me</a><a href="#prev">&lt;&lt;</a>'
- ));
-
- it('navigates to matching <a> elements by clicking', testPrev(
- `<a rel="prev" href="#dummy" onclick="return location = '#prev', false">go to prev</a>`
- ));
-
- it('prefers link[rel~=prev] to a[rel~=prev]', testPrev(
- '<a rel="prev" href="#dummy">click me</a><link rel="prev" href="#prev" />'
- ));
-
- it('prefers a[rel~=prev] to a::text(pattern)', testPrev(
- '<a href="#dummy">go to prev</a><a rel="prev" href="#prev">click me</a>'
- ));
+ describe("#linkPrev", () => {
+ it(
+ 'navigates to <link> elements whose rel attribute is "prev"',
+ testPrev('<link rel="prev" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute starts with "prev"',
+ testPrev('<link rel="prev bar" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute ends with "prev"',
+ testPrev('<link rel="foo prev" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute contains "prev"',
+ testPrev('<link rel="foo prev bar" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute is "prev"',
+ testPrev('<a rel="prev" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute starts with "prev"',
+ testPrev('<a rel="prev bar" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute ends with "prev"',
+ testPrev('<a rel="foo prev" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute contains "prev"',
+ testPrev('<a rel="foo prev bar" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "prev"',
+ testPrev('<a href="#dummy">preview</a><a href="#prev">go to prev</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "previous"',
+ testPrev(
+ '<a href="#dummy">previously</a><a href="#prev">previous page</a>'
+ )
+ );
+
+ it(
+ 'navigates to <a> elements whose decoded text matches "<<"',
+ testPrev('<a href="#dummy">click me</a><a href="#prev">&lt;&lt;</a>')
+ );
+
+ it(
+ "navigates to matching <a> elements by clicking",
+ testPrev(
+ `<a rel="prev" href="#dummy" onclick="return location = '#prev', false">go to prev</a>`
+ )
+ );
+
+ it(
+ "prefers link[rel~=prev] to a[rel~=prev]",
+ testPrev(
+ '<a rel="prev" href="#dummy">click me</a><link rel="prev" href="#prev" />'
+ )
+ );
+
+ it(
+ "prefers a[rel~=prev] to a::text(pattern)",
+ testPrev(
+ '<a href="#dummy">go to prev</a><a rel="prev" href="#prev">click me</a>'
+ )
+ );
});
- describe('#linkNext', () => {
- it('navigates to <link> elements whose rel attribute is "next"', testNext(
- '<link rel="next" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute starts with "next"', testNext(
- '<link rel="next bar" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute ends with "next"', testNext(
- '<link rel="foo next" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute contains "next"', testNext(
- '<link rel="foo next bar" href="#next" />'
- ));
-
- it('navigates to <a> elements whose rel attribute is "next"', testNext(
- '<a rel="next" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute starts with "next"', testNext(
- '<a rel="next bar" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute ends with "next"', testNext(
- '<a rel="foo next" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute contains "next"', testNext(
- '<a rel="foo next bar" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose text matches "next"', testNext(
- '<a href="#dummy">inextricable</a><a href="#next">go to next</a>'
- ));
-
- it('navigates to <a> elements whose decoded text matches ">>"', testNext(
- '<a href="#dummy">click me</a><a href="#next">&gt;&gt;</a>'
- ));
-
- it('navigates to matching <a> elements by clicking', testNext(
- `<a rel="next" href="#dummy" onclick="return location = '#next', false">go to next</a>`
- ));
-
- it('prefers link[rel~=next] to a[rel~=next]', testNext(
- '<a rel="next" href="#dummy">click me</a><link rel="next" href="#next" />'
- ));
-
- it('prefers a[rel~=next] to a::text(pattern)', testNext(
- '<a href="#dummy">next page</a><a rel="next" href="#next">click me</a>'
- ));
+ describe("#linkNext", () => {
+ it(
+ 'navigates to <link> elements whose rel attribute is "next"',
+ testNext('<link rel="next" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute starts with "next"',
+ testNext('<link rel="next bar" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute ends with "next"',
+ testNext('<link rel="foo next" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute contains "next"',
+ testNext('<link rel="foo next bar" href="#next" />')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute is "next"',
+ testNext('<a rel="next" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute starts with "next"',
+ testNext('<a rel="next bar" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute ends with "next"',
+ testNext('<a rel="foo next" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute contains "next"',
+ testNext('<a rel="foo next bar" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "next"',
+ testNext(
+ '<a href="#dummy">inextricable</a><a href="#next">go to next</a>'
+ )
+ );
+
+ it(
+ 'navigates to <a> elements whose decoded text matches ">>"',
+ testNext('<a href="#dummy">click me</a><a href="#next">&gt;&gt;</a>')
+ );
+
+ it(
+ "navigates to matching <a> elements by clicking",
+ testNext(
+ `<a rel="next" href="#dummy" onclick="return location = '#next', false">go to next</a>`
+ )
+ );
+
+ it(
+ "prefers link[rel~=next] to a[rel~=next]",
+ testNext(
+ '<a rel="next" href="#dummy">click me</a><link rel="next" href="#next" />'
+ )
+ );
+
+ it(
+ "prefers a[rel~=next] to a::text(pattern)",
+ testNext(
+ '<a href="#dummy">next page</a><a rel="next" href="#next">click me</a>'
+ )
+ );
});
});