/**
* @jest-environment jsdom
*/
import { NavigationPresenterImpl } from "../../../src/content/presenters/NavigationPresenter";
describe("NavigationPresenterImpl", () => {
let sut: NavigationPresenterImpl;
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(() => {
expect(document.location.hash).toEqual(`#${rel}`);
done();
}, 0);
};
const testPrev = (html: string) => (done: () => void) =>
testRel(done, "prev", html);
const testNext = (html: string) => (done: () => void) =>
testRel(done, "next", html);
beforeEach(() => {
sut = new NavigationPresenterImpl();
});
describe("#linkPrev", () => {
it(
'navigates to elements whose rel attribute is "prev"',
testPrev('')
);
it(
'navigates to elements whose rel attribute starts with "prev"',
testPrev('')
);
it(
'navigates to elements whose rel attribute ends with "prev"',
testPrev('')
);
it(
'navigates to elements whose rel attribute contains "prev"',
testPrev('')
);
it(
'navigates to elements whose rel attribute is "prev"',
testPrev('click me')
);
it(
'navigates to elements whose rel attribute starts with "prev"',
testPrev('click me')
);
it(
'navigates to elements whose rel attribute ends with "prev"',
testPrev('click me')
);
it(
'navigates to elements whose rel attribute contains "prev"',
testPrev('click me')
);
it(
'navigates to elements whose text matches "prev"',
testPrev('previewgo to prev')
);
it(
'navigates to elements whose text matches "previous"',
testPrev(
'previouslyprevious page'
)
);
it(
'navigates to elements whose decoded text matches "<<"',
testPrev('click me<<')
);
it(
"navigates to matching elements by clicking",
testPrev(
`go to prev`
)
);
it(
"prefers link[rel~=prev] to a[rel~=prev]",
testPrev(
'click me'
)
);
it(
"prefers a[rel~=prev] to a::text(pattern)",
testPrev(
'go to prevclick me'
)
);
});
describe("#linkNext", () => {
it(
'navigates to elements whose rel attribute is "next"',
testNext('')
);
it(
'navigates to elements whose rel attribute starts with "next"',
testNext('')
);
it(
'navigates to elements whose rel attribute ends with "next"',
testNext('')
);
it(
'navigates to elements whose rel attribute contains "next"',
testNext('')
);
it(
'navigates to elements whose rel attribute is "next"',
testNext('click me')
);
it(
'navigates to elements whose rel attribute starts with "next"',
testNext('click me')
);
it(
'navigates to elements whose rel attribute ends with "next"',
testNext('click me')
);
it(
'navigates to elements whose rel attribute contains "next"',
testNext('click me')
);
it(
'navigates to elements whose text matches "next"',
testNext(
'inextricablego to next'
)
);
it(
'navigates to elements whose decoded text matches ">>"',
testNext('click me>>')
);
it(
"navigates to matching elements by clicking",
testNext(
`go to next`
)
);
it(
"prefers link[rel~=next] to a[rel~=next]",
testNext(
'click me'
)
);
it(
"prefers a[rel~=next] to a::text(pattern)",
testNext(
'next pageclick me'
)
);
});
});