import * as navigates from 'content/navigates'; const testRel = (done, rel, html) => { const method = rel === 'prev' ? 'linkPrev' : 'linkNext'; document.body.innerHTML = html; navigates[method](window); setTimeout(() => { expect(document.location.hash).to.equal(`#${rel}`); done(); }, 0); }; const testPrev = html => done => testRel(done, 'prev', html); const testNext = html => done => testRel(done, 'next', html); describe('navigates module', () => { 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' )); }); 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; }); }); });