aboutsummaryrefslogtreecommitdiff
path: root/test/content/presenters/Hint.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/Hint.test.ts
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
parent75abd90ecb8201ad845b266f96220d8adfe19b2d (diff)
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'test/content/presenters/Hint.test.ts')
-rw-r--r--test/content/presenters/Hint.test.ts134
1 files changed, 72 insertions, 62 deletions
diff --git a/test/content/presenters/Hint.test.ts b/test/content/presenters/Hint.test.ts
index 7daa63d..f961f88 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 = `<a id='test-link' href='#'>link</a>`;
});
- 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 = `
<a id='test-link1' href='https://google.com/'>link</a>
@@ -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('<input>', () => {
+describe("InputHint", () => {
+ describe("#activate()", () => {
+ context("<input>", () => {
beforeEach(() => {
document.body.innerHTML = `<input id='test-input'></input>`;
});
- 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 = `<input type="checkbox" id='test-input'></input>`;
});
- 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('<textarea>', () => {
+ context("<textarea>", () => {
beforeEach(() => {
document.body.innerHTML = `<textarea id='test-textarea'></textarea>`;
});
- 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('<button>', () => {
+ context("<button>", () => {
beforeEach(() => {
document.body.innerHTML = `<button id='test-button'></button>`;
});
- 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();
});
});