From e1dac618a8b8929f601c7ec8aca3842c5ebf9d03 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 13 Apr 2020 20:37:36 +0900 Subject: Use plugin:prettier/recommended --- test/content/presenters/Hint.test.ts | 134 +++++----- .../content/presenters/NavigationPresenter.test.ts | 272 ++++++++++++--------- 2 files changed, 230 insertions(+), 176 deletions(-) (limited to 'test/content/presenters') diff --git a/test/content/presenters/Hint.test.ts b/test/content/presenters/Hint.test.ts index 7daa63d..e64c39f 100644 --- a/test/content/presenters/Hint.test.ts +++ b/test/content/presenters/Hint.test.ts @@ -1,53 +1,55 @@ -import AbstractHint, { LinkHint, InputHint } from '../../../src/content/presenters/Hint'; -import { expect } from 'chai'; +import AbstractHint, { + LinkHint, + InputHint, +} from "../../../src/content/presenters/Hint"; +import { expect } from "chai"; -class Hint extends AbstractHint { -} +class Hint extends AbstractHint {} -describe('Hint', () => { +describe("Hint", () => { beforeEach(() => { document.body.innerHTML = `link`; }); - describe('#constructor', () => { - it('creates a hint element with tag name', () => { - const link = document.getElementById('test-link'); - new Hint(link, 'abc'); + describe("#constructor", () => { + it("creates a hint element with tag name", () => { + const link = document.getElementById("test-link"); + new Hint(link, "abc"); - const elem = document.querySelector('.vimvixen-hint'); - expect(elem.textContent.trim()).to.be.equal('abc'); + const elem = document.querySelector(".vimvixen-hint"); + expect(elem.textContent.trim()).to.be.equal("abc"); }); }); - describe('#show', () => { - it('shows an element', () => { - const link = document.getElementById('test-link'); - const hint = new Hint(link, 'abc'); + describe("#show", () => { + it("shows an element", () => { + const link = document.getElementById("test-link"); + const hint = new Hint(link, "abc"); hint.hide(); hint.show(); - const elem = document.querySelector('.vimvixen-hint') as HTMLElement; - expect(elem.style.display).to.not.equal('none'); + const elem = document.querySelector(".vimvixen-hint") as HTMLElement; + expect(elem.style.display).to.not.equal("none"); }); }); - describe('#hide', () => { - it('hides an element', () => { - const link = document.getElementById('test-link') as HTMLElement; - const hint = new Hint(link, 'abc'); + describe("#hide", () => { + it("hides an element", () => { + const link = document.getElementById("test-link") as HTMLElement; + const hint = new Hint(link, "abc"); hint.hide(); - const elem = document.querySelector('.vimvixen-hint') as HTMLElement; - expect(elem.style.display).to.equal('none'); + const elem = document.querySelector(".vimvixen-hint") as HTMLElement; + expect(elem.style.display).to.equal("none"); }); }); - describe('#remove', () => { - it('removes an element', () => { - const link = document.getElementById('test-link'); - const hint = new Hint(link, 'abc'); + describe("#remove", () => { + it("removes an element", () => { + const link = document.getElementById("test-link"); + const hint = new Hint(link, "abc"); - const elem = document.querySelector('.vimvixen-hint'); + const elem = document.querySelector(".vimvixen-hint"); expect(elem.parentElement).to.not.be.null; hint.remove(); expect(elem.parentElement).to.be.null; @@ -55,7 +57,7 @@ describe('Hint', () => { }); }); -describe('LinkHint', () => { +describe("LinkHint", () => { beforeEach(() => { document.body.innerHTML = ` link @@ -64,50 +66,52 @@ describe('LinkHint', () => { `; }); - describe('#getLink()', () => { + describe("#getLink()", () => { it('returns value of "href" attribute', () => { - const link = document.getElementById('test-link1') as HTMLAnchorElement; - const hint = new LinkHint(link, 'abc'); + const link = document.getElementById("test-link1") as HTMLAnchorElement; + const hint = new LinkHint(link, "abc"); - expect(hint.getLink()).to.equal('https://google.com/'); + expect(hint.getLink()).to.equal("https://google.com/"); }); }); - describe('#getLinkTarget()', () => { + describe("#getLinkTarget()", () => { it('returns value of "target" attribute', () => { - let link = document.getElementById('test-link1') as HTMLAnchorElement; - let hint = new LinkHint(link, 'abc'); + let link = document.getElementById("test-link1") as HTMLAnchorElement; + let hint = new LinkHint(link, "abc"); expect(hint.getLinkTarget()).to.be.null; - link = document.getElementById('test-link2') as HTMLAnchorElement; - hint = new LinkHint(link, 'abc'); + link = document.getElementById("test-link2") as HTMLAnchorElement; + hint = new LinkHint(link, "abc"); - expect(hint.getLinkTarget()).to.equal('_blank'); + expect(hint.getLinkTarget()).to.equal("_blank"); }); }); - describe('#click()', () => { - it('clicks a element', (done) => { - const link = document.getElementById('test-link3') as HTMLAnchorElement; - const hint = new LinkHint(link, 'abc'); - link.onclick = () => { done() }; + describe("#click()", () => { + it("clicks a element", (done) => { + const link = document.getElementById("test-link3") as HTMLAnchorElement; + const hint = new LinkHint(link, "abc"); + link.onclick = () => { + done(); + }; hint.click(); }); }); }); -describe('InputHint', () => { - describe('#activate()', () => { - context('', () => { +describe("InputHint", () => { + describe("#activate()", () => { + context("", () => { beforeEach(() => { document.body.innerHTML = ``; }); - it('focuses to the input', () => { - const input = document.getElementById('test-input') as HTMLInputElement; - const hint = new InputHint(input, 'abc'); + it("focuses to the input", () => { + const input = document.getElementById("test-input") as HTMLInputElement; + const hint = new InputHint(input, "abc"); hint.activate(); expect(document.activeElement).to.equal(input); @@ -119,38 +123,44 @@ describe('InputHint', () => { document.body.innerHTML = ``; }); - it('checks and focuses to the input', () => { - const input = document.getElementById('test-input') as HTMLInputElement; - const hint = new InputHint(input, 'abc'); + it("checks and focuses to the input", () => { + const input = document.getElementById("test-input") as HTMLInputElement; + const hint = new InputHint(input, "abc"); hint.activate(); expect(input.checked).to.be.true; }); }); - context('`; }); - it('focuses to the textarea', () => { - const textarea = document.getElementById('test-textarea') as HTMLTextAreaElement; - const hint = new InputHint(textarea, 'abc'); + it("focuses to the textarea", () => { + const textarea = document.getElementById( + "test-textarea" + ) as HTMLTextAreaElement; + const hint = new InputHint(textarea, "abc"); hint.activate(); expect(document.activeElement).to.equal(textarea); }); }); - context('`; }); - it('clicks the button', (done) => { - const button = document.getElementById('test-button') as HTMLButtonElement; - button.onclick = () => { done() }; + it("clicks the button", (done) => { + const button = document.getElementById( + "test-button" + ) as HTMLButtonElement; + button.onclick = () => { + done(); + }; - const hint = new InputHint(button, 'abc'); + const hint = new InputHint(button, "abc"); hint.activate(); }); }); diff --git a/test/content/presenters/NavigationPresenter.test.ts b/test/content/presenters/NavigationPresenter.test.ts index 6aa057b..b362d8d 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 method = + rel === "prev" ? sut.openLinkPrev.bind(sut) : sut.openLinkNext.bind(sut); document.body.innerHTML = html; method(); setTimeout(() => { @@ -13,122 +14,165 @@ describe('NavigationPresenterImpl', () => { done(); }, 0); }; - const testPrev = html => done => testRel(done, 'prev', html); - const testNext = html => done => testRel(done, 'next', html); + const testPrev = (html) => (done) => testRel(done, "prev", html); + const testNext = (html) => (done) => 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("#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("#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' + ) + ); }); }); -- cgit v1.2.3