import { NavigationPresenterImpl } from "../../../src/content/presenters/NavigationPresenter"; import { expect } from "chai"; describe("NavigationPresenterImpl", function () { this.timeout(5000); 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).to.equal(`#${rel}`); done(); }, 0); }; 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 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('') ); 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( `` ) ); it( "prefers link[rel~=prev] to a[rel~=prev]", testPrev( '' ) ); it( "prefers a[rel~=prev] to a::text(pattern)", testPrev( 'go to prev' ) ); }); 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('') ); 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( `` ) ); it( "prefers link[rel~=next] to a[rel~=next]", testNext( '' ) ); it( "prefers a[rel~=next] to a::text(pattern)", testNext( 'next page' ) ); }); });