aboutsummaryrefslogtreecommitdiff
path: root/test/content
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
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
parent75abd90ecb8201ad845b266f96220d8adfe19b2d (diff)
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'test/content')
-rw-r--r--test/content/InputDriver.test.ts163
-rw-r--r--test/content/domains/KeySequence.test.ts209
-rw-r--r--test/content/mock/MockConsoleClient.ts6
-rw-r--r--test/content/mock/MockScrollPresenter.ts7
-rw-r--r--test/content/presenters/Hint.test.ts134
-rw-r--r--test/content/presenters/NavigationPresenter.test.ts276
-rw-r--r--test/content/repositories/AddonEnabledRepository.test.ts9
-rw-r--r--test/content/repositories/FindRepository.test.ts13
-rw-r--r--test/content/repositories/FollowKeyRepository.test.ts26
-rw-r--r--test/content/repositories/FollowMasterRepository.test.ts39
-rw-r--r--test/content/repositories/FollowSlaveRepository.test.ts14
-rw-r--r--test/content/repositories/KeymapRepository.test.ts39
-rw-r--r--test/content/repositories/MarkKeyRepository.test.ts20
-rw-r--r--test/content/repositories/MarkRepository.test.ts15
-rw-r--r--test/content/repositories/SettingRepository.test.ts24
-rw-r--r--test/content/usecases/AddonEnabledUseCase.test.ts28
-rw-r--r--test/content/usecases/ClipboardUseCase.test.ts84
-rw-r--r--test/content/usecases/FindUseCase.test.ts87
-rw-r--r--test/content/usecases/HintKeyProducer.test.ts38
-rw-r--r--test/content/usecases/KeymapUseCase.test.ts274
-rw-r--r--test/content/usecases/MarkUseCase.test.ts75
-rw-r--r--test/content/usecases/SettingUseCaase.test.ts38
22 files changed, 890 insertions, 728 deletions
diff --git a/test/content/InputDriver.test.ts b/test/content/InputDriver.test.ts
index d3a55dd..f464dac 100644
--- a/test/content/InputDriver.test.ts
+++ b/test/content/InputDriver.test.ts
@@ -1,26 +1,26 @@
-import InputDriver, {keyFromKeyboardEvent} from '../../src/content/InputDriver';
-import { expect } from 'chai';
-import Key from '../../src/shared/settings/Key';
+import InputDriver, {
+ keyFromKeyboardEvent,
+} from "../../src/content/InputDriver";
+import { expect } from "chai";
+import Key from "../../src/shared/settings/Key";
-describe('InputDriver', () => {
+describe("InputDriver", () => {
let target: HTMLElement;
let driver: InputDriver;
beforeEach(() => {
- target = document.createElement('div');
+ target = document.createElement("div");
document.body.appendChild(target);
driver = new InputDriver(target);
});
afterEach(() => {
target.remove();
- target = null;
- driver = null;
});
- it('register callbacks', (done) => {
+ it("register callbacks", (done) => {
driver.onKey((key: Key): boolean => {
- expect(key.key).to.equal('a');
+ expect(key.key).to.equal("a");
expect(key.ctrl).to.be.true;
expect(key.shift).to.be.false;
expect(key.alt).to.be.false;
@@ -29,34 +29,37 @@ describe('InputDriver', () => {
return true;
});
- target.dispatchEvent(new KeyboardEvent('keydown', {
- key: 'a',
- ctrlKey: true,
- shiftKey: false,
- altKey: false,
- metaKey: false,
- }));
+ target.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: "a",
+ ctrlKey: true,
+ shiftKey: false,
+ altKey: false,
+ metaKey: false,
+ })
+ );
});
- it('invoke callback once', () => {
- let a = 0, b = 0;
+ it("invoke callback once", () => {
+ let a = 0,
+ b = 0;
driver.onKey((key: Key): boolean => {
- if (key.key == 'a') {
+ if (key.key == "a") {
++a;
} else {
- key.key == 'b'
+ key.key == "b";
++b;
}
return true;
});
const events = [
- new KeyboardEvent('keydown', { key: 'a' }),
- new KeyboardEvent('keydown', { key: 'b' }),
- new KeyboardEvent('keypress', { key: 'a' }),
- new KeyboardEvent('keyup', { key: 'a' }),
- new KeyboardEvent('keypress', { key: 'b' }),
- new KeyboardEvent('keyup', { key: 'b' }),
+ new KeyboardEvent("keydown", { key: "a" }),
+ new KeyboardEvent("keydown", { key: "b" }),
+ new KeyboardEvent("keypress", { key: "a" }),
+ new KeyboardEvent("keyup", { key: "a" }),
+ new KeyboardEvent("keypress", { key: "b" }),
+ new KeyboardEvent("keyup", { key: "b" }),
];
for (const e of events) {
target.dispatchEvent(e);
@@ -64,10 +67,12 @@ describe('InputDriver', () => {
expect(a).to.equal(1);
expect(b).to.equal(1);
- })
+ });
- it('propagates and stop handler chain', () => {
- let a = 0, b = 0, c = 0;
+ it("propagates and stop handler chain", () => {
+ let a = 0,
+ b = 0,
+ c = 0;
driver.onKey((_key: Key): boolean => {
a++;
return false;
@@ -81,93 +86,117 @@ describe('InputDriver', () => {
return true;
});
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'b' }));
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "b" }));
expect(a).to.equal(1);
expect(b).to.equal(1);
expect(c).to.equal(0);
- })
+ });
- it('does not invoke only meta keys', () => {
- driver.onKey((_key: Key): boolean=> {
+ it("does not invoke only meta keys", () => {
+ driver.onKey((_key: Key): boolean => {
expect.fail();
return false;
});
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift' }));
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Control' }));
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Alt' }));
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'OS' }));
- })
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "Shift" }));
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "Control" }));
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "Alt" }));
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "OS" }));
+ });
- it('ignores events from input elements', () => {
- ['input', 'textarea', 'select'].forEach((name) => {
+ it("ignores events from input elements", () => {
+ ["input", "textarea", "select"].forEach((name) => {
const input = window.document.createElement(name);
const driver = new InputDriver(input);
driver.onKey((_key: Key): boolean => {
expect.fail();
return false;
});
- input.dispatchEvent(new KeyboardEvent('keydown', { key: 'x' }));
+ input.dispatchEvent(new KeyboardEvent("keydown", { key: "x" }));
});
});
- it('ignores events from contenteditable elements', () => {
- const div = window.document.createElement('div');
+ it("ignores events from contenteditable elements", () => {
+ const div = window.document.createElement("div");
const driver = new InputDriver(div);
driver.onKey((_key: Key): boolean => {
expect.fail();
return false;
});
- div.setAttribute('contenteditable', '');
- div.dispatchEvent(new KeyboardEvent('keydown', { key: 'x' }));
+ div.setAttribute("contenteditable", "");
+ div.dispatchEvent(new KeyboardEvent("keydown", { key: "x" }));
- div.setAttribute('contenteditable', 'true');
- div.dispatchEvent(new KeyboardEvent('keydown', { key: 'x' }));
+ div.setAttribute("contenteditable", "true");
+ div.dispatchEvent(new KeyboardEvent("keydown", { key: "x" }));
});
});
describe("#keyFromKeyboardEvent", () => {
- it('returns from keyboard input Ctrl+X', () => {
- const k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
- key: 'x', shiftKey: false, ctrlKey: true, altKey: false, metaKey: true,
- }));
- expect(k.key).to.equal('x');
+ it("returns from keyboard input Ctrl+X", () => {
+ const k = keyFromKeyboardEvent(
+ new KeyboardEvent("keydown", {
+ key: "x",
+ shiftKey: false,
+ ctrlKey: true,
+ altKey: false,
+ metaKey: true,
+ })
+ );
+ expect(k.key).to.equal("x");
expect(k.shift).to.be.false;
expect(k.ctrl).to.be.true;
expect(k.alt).to.be.false;
expect(k.meta).to.be.true;
});
- it('returns from keyboard input Shift+Esc', () => {
- const k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
- key: 'Escape', shiftKey: true, ctrlKey: false, altKey: false, metaKey: true
- }));
- expect(k.key).to.equal('Esc');
+ it("returns from keyboard input Shift+Esc", () => {
+ const k = keyFromKeyboardEvent(
+ new KeyboardEvent("keydown", {
+ key: "Escape",
+ shiftKey: true,
+ ctrlKey: false,
+ altKey: false,
+ metaKey: true,
+ })
+ );
+ expect(k.key).to.equal("Esc");
expect(k.shift).to.be.true;
expect(k.ctrl).to.be.false;
expect(k.alt).to.be.false;
expect(k.meta).to.be.true;
});
- it('returns from keyboard input Ctrl+$', () => {
+ it("returns from keyboard input Ctrl+$", () => {
// $ required shift pressing on most keyboards
- const k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
- key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false
- }));
- expect(k.key).to.equal('$');
+ const k = keyFromKeyboardEvent(
+ new KeyboardEvent("keydown", {
+ key: "$",
+ shiftKey: true,
+ ctrlKey: true,
+ altKey: false,
+ metaKey: false,
+ })
+ );
+ expect(k.key).to.equal("$");
expect(k.shift).to.be.false;
expect(k.ctrl).to.be.true;
expect(k.alt).to.be.false;
expect(k.meta).to.be.false;
});
- it('returns from keyboard input Crtl+Space', () => {
- const k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
- key: ' ', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false
- }));
- expect(k.key).to.equal('Space');
+ it("returns from keyboard input Crtl+Space", () => {
+ const k = keyFromKeyboardEvent(
+ new KeyboardEvent("keydown", {
+ key: " ",
+ shiftKey: false,
+ ctrlKey: true,
+ altKey: false,
+ metaKey: false,
+ })
+ );
+ expect(k.key).to.equal("Space");
expect(k.shift).to.be.false;
expect(k.ctrl).to.be.true;
expect(k.alt).to.be.false;
diff --git a/test/content/domains/KeySequence.test.ts b/test/content/domains/KeySequence.test.ts
index 5df5217..1d1debe 100644
--- a/test/content/domains/KeySequence.test.ts
+++ b/test/content/domains/KeySequence.test.ts
@@ -1,166 +1,179 @@
-import KeySequence from '../../../src/content/domains/KeySequence';
-import { expect } from 'chai'
+import KeySequence from "../../../src/content/domains/KeySequence";
+import { expect } from "chai";
import Key from "../../../src/shared/settings/Key";
describe("KeySequence", () => {
- describe('#push', () => {
- it('append a key to the sequence', () => {
+ describe("#push", () => {
+ it("append a key to the sequence", () => {
const seq = new KeySequence([]);
- seq.push(Key.fromMapKey('g'));
- seq.push(Key.fromMapKey('<S-U>'));
+ seq.push(Key.fromMapKey("g"));
+ seq.push(Key.fromMapKey("<S-U>"));
- expect(seq.keys[0].key).to.equal('g');
- expect(seq.keys[1].key).to.equal('U');
+ expect(seq.keys[0].key).to.equal("g");
+ expect(seq.keys[1].key).to.equal("U");
expect(seq.keys[1].shift).to.be.true;
- })
+ });
});
- describe('#startsWith', () => {
- it('returns true if the key sequence starts with param', () => {
+ describe("#startsWith", () => {
+ it("returns true if the key sequence starts with param", () => {
const seq = new KeySequence([
- Key.fromMapKey('g'),
- Key.fromMapKey('<S-U>'),
+ Key.fromMapKey("g"),
+ Key.fromMapKey("<S-U>"),
]);
- expect(seq.startsWith(new KeySequence([
- ]))).to.be.true;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('g'),
- ]))).to.be.true;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('g'), Key.fromMapKey('<S-U>'),
- ]))).to.be.true;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('g'), Key.fromMapKey('<S-U>'), Key.fromMapKey('x'),
- ]))).to.be.false;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('h'),
- ]))).to.be.false;
+ expect(seq.startsWith(new KeySequence([]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([Key.fromMapKey("g")]))).to.be.true;
+ expect(
+ seq.startsWith(
+ new KeySequence([Key.fromMapKey("g"), Key.fromMapKey("<S-U>")])
+ )
+ ).to.be.true;
+ expect(
+ seq.startsWith(
+ new KeySequence([
+ Key.fromMapKey("g"),
+ Key.fromMapKey("<S-U>"),
+ Key.fromMapKey("x"),
+ ])
+ )
+ ).to.be.false;
+ expect(seq.startsWith(new KeySequence([Key.fromMapKey("h")]))).to.be
+ .false;
});
- it('returns true if the empty sequence starts with an empty sequence', () => {
+ it("returns true if the empty sequence starts with an empty sequence", () => {
const seq = new KeySequence([]);
expect(seq.startsWith(new KeySequence([]))).to.be.true;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('h'),
- ]))).to.be.false;
- })
+ expect(seq.startsWith(new KeySequence([Key.fromMapKey("h")]))).to.be
+ .false;
+ });
});
- describe('#isDigitOnly', () => {
- it('returns true the keys are only digits', () => {
- expect(new KeySequence([
- new Key({ key: '4' }),
- new Key({ key: '0' }),
- ]).isDigitOnly()).to.be.true;
- expect(new KeySequence([
- new Key({ key: '4' }),
- new Key({ key: '0' }),
- new Key({ key: 'z' }),
- ]).isDigitOnly()).to.be.false;
- })
+ describe("#isDigitOnly", () => {
+ it("returns true the keys are only digits", () => {
+ expect(
+ new KeySequence([
+ new Key({ key: "4" }),
+ new Key({ key: "0" }),
+ ]).isDigitOnly()
+ ).to.be.true;
+ expect(
+ new KeySequence([
+ new Key({ key: "4" }),
+ new Key({ key: "0" }),
+ new Key({ key: "z" }),
+ ]).isDigitOnly()
+ ).to.be.false;
+ });
});
- describe('#repeatCount', () => {
- it('returns repeat count with a numeric prefix', () => {
+ describe("#repeatCount", () => {
+ it("returns repeat count with a numeric prefix", () => {
let seq = new KeySequence([
- new Key({ key: '1' }), new Key({ key: '0' }) ,
- new Key({ key: 'g' }), new Key({ key: 'g' }) ,
+ new Key({ key: "1" }),
+ new Key({ key: "0" }),
+ new Key({ key: "g" }),
+ new Key({ key: "g" }),
]);
expect(seq.repeatCount()).to.equal(10);
seq = new KeySequence([
- new Key({ key: '0' }), new Key({ key: '5' }) ,
- new Key({ key: 'g' }), new Key({ key: 'g' }) ,
+ new Key({ key: "0" }),
+ new Key({ key: "5" }),
+ new Key({ key: "g" }),
+ new Key({ key: "g" }),
]);
expect(seq.repeatCount()).to.equal(5);
});
- it('returns 1 if no numeric prefix', () => {
- let seq = new KeySequence([
- new Key({ key: 'g' }), new Key({ key: 'g' }) ,
- ]);
+ it("returns 1 if no numeric prefix", () => {
+ let seq = new KeySequence([new Key({ key: "g" }), new Key({ key: "g" })]);
expect(seq.repeatCount()).to.equal(1);
seq = new KeySequence([]);
expect(seq.repeatCount()).to.equal(1);
});
- it('returns whole keys if digits only sequence', () => {
- let seq = new KeySequence([
- new Key({ key: '1' }), new Key({ key: '0' }) ,
- ]);
+ it("returns whole keys if digits only sequence", () => {
+ let seq = new KeySequence([new Key({ key: "1" }), new Key({ key: "0" })]);
expect(seq.repeatCount()).to.equal(10);
- seq = new KeySequence([
- new Key({ key: '0' }), new Key({ key: '5' }) ,
- ]);
+ seq = new KeySequence([new Key({ key: "0" }), new Key({ key: "5" })]);
expect(seq.repeatCount()).to.equal(5);
});
});
- describe('#trimNumericPrefix', () => {
- it('removes numeric prefix', () => {
+ describe("#trimNumericPrefix", () => {
+ it("removes numeric prefix", () => {
const seq = new KeySequence([
- new Key({ key: '1' }), new Key({ key: '0' }) ,
- new Key({ key: 'g' }), new Key({ key: 'g' }) , new Key({ key: '3' }) ,
+ new Key({ key: "1" }),
+ new Key({ key: "0" }),
+ new Key({ key: "g" }),
+ new Key({ key: "g" }),
+ new Key({ key: "3" }),
]).trimNumericPrefix();
- expect(seq.keys.map(key => key.key)).to.deep.equal(['g', 'g', '3']);
+ expect(seq.keys.map((key) => key.key)).to.deep.equal(["g", "g", "3"]);
});
- it('returns empty if keys contains only digis', () => {
+ it("returns empty if keys contains only digis", () => {
const seq = new KeySequence([
- new Key({ key: '1' }), new Key({ key: '0' }) ,
+ new Key({ key: "1" }),
+ new Key({ key: "0" }),
]).trimNumericPrefix();
expect(seq.trimNumericPrefix().keys).to.be.empty;
});
- it('returns itself if no numeric prefix', () => {
+ it("returns itself if no numeric prefix", () => {
const seq = new KeySequence([
- new Key({ key: 'g' }), new Key({ key: 'g' }) , new Key({ key: '3' }) ,
+ new Key({ key: "g" }),
+ new Key({ key: "g" }),
+ new Key({ key: "3" }),
]).trimNumericPrefix();
- expect(seq.keys.map(key => key.key)).to.deep.equal(['g', 'g', '3']);
+ expect(seq.keys.map((key) => key.key)).to.deep.equal(["g", "g", "3"]);
});
});
- describe('#splitNumericPrefix', () => {
- it('splits numeric prefix', () => {
- expect(KeySequence.fromMapKeys('10gg').splitNumericPrefix()).to.deep.equal([
- KeySequence.fromMapKeys('10'),
- KeySequence.fromMapKeys('gg'),
- ]);
- expect(KeySequence.fromMapKeys('10').splitNumericPrefix()).to.deep.equal([
- KeySequence.fromMapKeys('10'),
- new KeySequence([]),
- ]);
- expect(KeySequence.fromMapKeys('gg').splitNumericPrefix()).to.deep.equal([
- new KeySequence([]),
- KeySequence.fromMapKeys('gg'),
- ]);
- });
+ describe("#splitNumericPrefix", () => {
+ it("splits numeric prefix", () => {
+ expect(
+ KeySequence.fromMapKeys("10gg").splitNumericPrefix()
+ ).to.deep.equal([
+ KeySequence.fromMapKeys("10"),
+ KeySequence.fromMapKeys("gg"),
+ ]);
+ expect(KeySequence.fromMapKeys("10").splitNumericPrefix()).to.deep.equal([
+ KeySequence.fromMapKeys("10"),
+ new KeySequence([]),
+ ]);
+ expect(KeySequence.fromMapKeys("gg").splitNumericPrefix()).to.deep.equal([
+ new KeySequence([]),
+ KeySequence.fromMapKeys("gg"),
+ ]);
+ });
});
- describe('#fromMapKeys', () => {
- it('returns mapped keys for Shift+Esc', () => {
- const keys = KeySequence.fromMapKeys('<S-Esc>').keys;
+ describe("#fromMapKeys", () => {
+ it("returns mapped keys for Shift+Esc", () => {
+ const keys = KeySequence.fromMapKeys("<S-Esc>").keys;
expect(keys).to.have.lengthOf(1);
- expect(keys[0].key).to.equal('Esc');
+ expect(keys[0].key).to.equal("Esc");
expect(keys[0].shift).to.be.true;
});
- it('returns mapped keys for a<C-B><A-C>d<M-e>', () => {
- const keys = KeySequence.fromMapKeys('a<C-B><A-C>d<M-e>').keys;
+ it("returns mapped keys for a<C-B><A-C>d<M-e>", () => {
+ const keys = KeySequence.fromMapKeys("a<C-B><A-C>d<M-e>").keys;
expect(keys).to.have.lengthOf(5);
- expect(keys[0].key).to.equal('a');
+ expect(keys[0].key).to.equal("a");
expect(keys[1].ctrl).to.be.true;
- expect(keys[1].key).to.equal('b');
+ expect(keys[1].key).to.equal("b");
expect(keys[2].alt).to.be.true;
- expect(keys[2].key).to.equal('c');
- expect(keys[3].key).to.equal('d');
+ expect(keys[2].key).to.equal("c");
+ expect(keys[3].key).to.equal("d");
expect(keys[4].meta).to.be.true;
- expect(keys[4].key).to.equal('e');
+ expect(keys[4].key).to.equal("e");
});
- })
+ });
});
diff --git a/test/content/mock/MockConsoleClient.ts b/test/content/mock/MockConsoleClient.ts
index 8de2d83..849c00d 100644
--- a/test/content/mock/MockConsoleClient.ts
+++ b/test/content/mock/MockConsoleClient.ts
@@ -1,4 +1,4 @@
-import ConsoleClient from '../../../src/content/client/ConsoleClient';
+import ConsoleClient from "../../../src/content/client/ConsoleClient";
export default class MockConsoleClient implements ConsoleClient {
public isError: boolean;
@@ -7,7 +7,7 @@ export default class MockConsoleClient implements ConsoleClient {
constructor() {
this.isError = false;
- this.text = '';
+ this.text = "";
}
info(text: string): Promise<void> {
@@ -22,5 +22,3 @@ export default class MockConsoleClient implements ConsoleClient {
return Promise.resolve();
}
}
-
-
diff --git a/test/content/mock/MockScrollPresenter.ts b/test/content/mock/MockScrollPresenter.ts
index 819569a..c802227 100644
--- a/test/content/mock/MockScrollPresenter.ts
+++ b/test/content/mock/MockScrollPresenter.ts
@@ -1,8 +1,10 @@
-import ScrollPresenter, { Point } from '../../../src/content/presenters/ScrollPresenter';
+import ScrollPresenter, {
+ Point,
+} from "../../../src/content/presenters/ScrollPresenter";
export default class MockScrollPresenter implements ScrollPresenter {
private pos: Point;
-
+
constructor() {
this.pos = { x: 0, y: 0 };
}
@@ -44,4 +46,3 @@ export default class MockScrollPresenter implements ScrollPresenter {
this.pos.x = Infinity;
}
}
-
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();
});
});
diff --git a/test/content/presenters/NavigationPresenter.test.ts b/test/content/presenters/NavigationPresenter.test.ts
index 6aa057b..af3b487 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 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(() => {
@@ -13,122 +14,167 @@ describe('NavigationPresenterImpl', () => {
done();
}, 0);
};
- const testPrev = html => done => testRel(done, 'prev', html);
- const testNext = html => done => testRel(done, 'next', html);
+ 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 <link> elements whose rel attribute is "prev"', testPrev(
- '<link rel="prev" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute starts with "prev"', testPrev(
- '<link rel="prev bar" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute ends with "prev"', testPrev(
- '<link rel="foo prev" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute contains "prev"', testPrev(
- '<link rel="foo prev bar" href="#prev" />'
- ));
-
- it('navigates to <a> elements whose rel attribute is "prev"', testPrev(
- '<a rel="prev" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute starts with "prev"', testPrev(
- '<a rel="prev bar" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute ends with "prev"', testPrev(
- '<a rel="foo prev" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute contains "prev"', testPrev(
- '<a rel="foo prev bar" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose text matches "prev"', testPrev(
- '<a href="#dummy">preview</a><a href="#prev">go to prev</a>'
- ));
-
- it('navigates to <a> elements whose text matches "previous"', testPrev(
- '<a href="#dummy">previously</a><a href="#prev">previous page</a>'
- ));
-
- it('navigates to <a> elements whose decoded text matches "<<"', testPrev(
- '<a href="#dummy">click me</a><a href="#prev">&lt;&lt;</a>'
- ));
-
- it('navigates to matching <a> elements by clicking', testPrev(
- `<a rel="prev" href="#dummy" onclick="return location = '#prev', false">go to prev</a>`
- ));
-
- it('prefers link[rel~=prev] to a[rel~=prev]', testPrev(
- '<a rel="prev" href="#dummy">click me</a><link rel="prev" href="#prev" />'
- ));
-
- it('prefers a[rel~=prev] to a::text(pattern)', testPrev(
- '<a href="#dummy">go to prev</a><a rel="prev" href="#prev">click me</a>'
- ));
+ describe("#linkPrev", () => {
+ it(
+ 'navigates to <link> elements whose rel attribute is "prev"',
+ testPrev('<link rel="prev" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute starts with "prev"',
+ testPrev('<link rel="prev bar" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute ends with "prev"',
+ testPrev('<link rel="foo prev" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute contains "prev"',
+ testPrev('<link rel="foo prev bar" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute is "prev"',
+ testPrev('<a rel="prev" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute starts with "prev"',
+ testPrev('<a rel="prev bar" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute ends with "prev"',
+ testPrev('<a rel="foo prev" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute contains "prev"',
+ testPrev('<a rel="foo prev bar" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "prev"',
+ testPrev('<a href="#dummy">preview</a><a href="#prev">go to prev</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "previous"',
+ testPrev(
+ '<a href="#dummy">previously</a><a href="#prev">previous page</a>'
+ )
+ );
+
+ it(
+ 'navigates to <a> elements whose decoded text matches "<<"',
+ testPrev('<a href="#dummy">click me</a><a href="#prev">&lt;&lt;</a>')
+ );
+
+ it(
+ "navigates to matching <a> elements by clicking",
+ testPrev(
+ `<a rel="prev" href="#dummy" onclick="return location = '#prev', false">go to prev</a>`
+ )
+ );
+
+ it(
+ "prefers link[rel~=prev] to a[rel~=prev]",
+ testPrev(
+ '<a rel="prev" href="#dummy">click me</a><link rel="prev" href="#prev" />'
+ )
+ );
+
+ it(
+ "prefers a[rel~=prev] to a::text(pattern)",
+ testPrev(
+ '<a href="#dummy">go to prev</a><a rel="prev" href="#prev">click me</a>'
+ )
+ );
});
- describe('#linkNext', () => {
- it('navigates to <link> elements whose rel attribute is "next"', testNext(
- '<link rel="next" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute starts with "next"', testNext(
- '<link rel="next bar" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute ends with "next"', testNext(
- '<link rel="foo next" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute contains "next"', testNext(
- '<link rel="foo next bar" href="#next" />'
- ));
-
- it('navigates to <a> elements whose rel attribute is "next"', testNext(
- '<a rel="next" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute starts with "next"', testNext(
- '<a rel="next bar" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute ends with "next"', testNext(
- '<a rel="foo next" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute contains "next"', testNext(
- '<a rel="foo next bar" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose text matches "next"', testNext(
- '<a href="#dummy">inextricable</a><a href="#next">go to next</a>'
- ));
-
- it('navigates to <a> elements whose decoded text matches ">>"', testNext(
- '<a href="#dummy">click me</a><a href="#next">&gt;&gt;</a>'
- ));
-
- it('navigates to matching <a> elements by clicking', testNext(
- `<a rel="next" href="#dummy" onclick="return location = '#next', false">go to next</a>`
- ));
-
- it('prefers link[rel~=next] to a[rel~=next]', testNext(
- '<a rel="next" href="#dummy">click me</a><link rel="next" href="#next" />'
- ));
-
- it('prefers a[rel~=next] to a::text(pattern)', testNext(
- '<a href="#dummy">next page</a><a rel="next" href="#next">click me</a>'
- ));
+ describe("#linkNext", () => {
+ it(
+ 'navigates to <link> elements whose rel attribute is "next"',
+ testNext('<link rel="next" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute starts with "next"',
+ testNext('<link rel="next bar" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute ends with "next"',
+ testNext('<link rel="foo next" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute contains "next"',
+ testNext('<link rel="foo next bar" href="#next" />')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute is "next"',
+ testNext('<a rel="next" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute starts with "next"',
+ testNext('<a rel="next bar" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute ends with "next"',
+ testNext('<a rel="foo next" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute contains "next"',
+ testNext('<a rel="foo next bar" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "next"',
+ testNext(
+ '<a href="#dummy">inextricable</a><a href="#next">go to next</a>'
+ )
+ );
+
+ it(
+ 'navigates to <a> elements whose decoded text matches ">>"',
+ testNext('<a href="#dummy">click me</a><a href="#next">&gt;&gt;</a>')
+ );
+
+ it(
+ "navigates to matching <a> elements by clicking",
+ testNext(
+ `<a rel="next" href="#dummy" onclick="return location = '#next', false">go to next</a>`
+ )
+ );
+
+ it(
+ "prefers link[rel~=next] to a[rel~=next]",
+ testNext(
+ '<a rel="next" href="#dummy">click me</a><link rel="next" href="#next" />'
+ )
+ );
+
+ it(
+ "prefers a[rel~=next] to a::text(pattern)",
+ testNext(
+ '<a href="#dummy">next page</a><a rel="next" href="#next">click me</a>'
+ )
+ );
});
});
diff --git a/test/content/repositories/AddonEnabledRepository.test.ts b/test/content/repositories/AddonEnabledRepository.test.ts
index 7edd50e..13dff76 100644
--- a/test/content/repositories/AddonEnabledRepository.test.ts
+++ b/test/content/repositories/AddonEnabledRepository.test.ts
@@ -1,8 +1,8 @@
-import { AddonEnabledRepositoryImpl } from '../../../src/content/repositories/AddonEnabledRepository';
-import { expect } from 'chai';
+import { AddonEnabledRepositoryImpl } from "../../../src/content/repositories/AddonEnabledRepository";
+import { expect } from "chai";
-describe('AddonEnabledRepositoryImpl', () => {
- it('updates and gets current value', () => {
+describe("AddonEnabledRepositoryImpl", () => {
+ it("updates and gets current value", () => {
const sut = new AddonEnabledRepositoryImpl();
sut.set(true);
@@ -12,4 +12,3 @@ describe('AddonEnabledRepositoryImpl', () => {
expect(sut.get()).to.be.false;
});
});
-
diff --git a/test/content/repositories/FindRepository.test.ts b/test/content/repositories/FindRepository.test.ts
index 0e50b0a..e0abb9d 100644
--- a/test/content/repositories/FindRepository.test.ts
+++ b/test/content/repositories/FindRepository.test.ts
@@ -1,15 +1,14 @@
-import { FindRepositoryImpl } from '../../../src/content/repositories/FindRepository';
-import { expect } from 'chai';
+import { FindRepositoryImpl } from "../../../src/content/repositories/FindRepository";
+import { expect } from "chai";
-describe('FindRepositoryImpl', () => {
- it('updates and gets last keyword', () => {
+describe("FindRepositoryImpl", () => {
+ it("updates and gets last keyword", () => {
const sut = new FindRepositoryImpl();
expect(sut.getLastKeyword()).to.be.null;
- sut.setLastKeyword('monkey');
+ sut.setLastKeyword("monkey");
- expect(sut.getLastKeyword()).to.equal('monkey');
+ expect(sut.getLastKeyword()).to.equal("monkey");
});
});
-
diff --git a/test/content/repositories/FollowKeyRepository.test.ts b/test/content/repositories/FollowKeyRepository.test.ts
index eae58b9..6608662 100644
--- a/test/content/repositories/FollowKeyRepository.test.ts
+++ b/test/content/repositories/FollowKeyRepository.test.ts
@@ -1,31 +1,29 @@
-import FollowKeyRepository, { FollowKeyRepositoryImpl }
- from '../../../src/content/repositories/FollowKeyRepository';
-import { expect } from 'chai';
+import FollowKeyRepository, {
+ FollowKeyRepositoryImpl,
+} from "../../../src/content/repositories/FollowKeyRepository";
+import { expect } from "chai";
-describe('FollowKeyRepositoryImpl', () => {
+describe("FollowKeyRepositoryImpl", () => {
let sut: FollowKeyRepository;
before(() => {
sut = new FollowKeyRepositoryImpl();
});
- describe('#getKeys()/#pushKey()/#popKey()', () => {
- it('enqueues keys', () => {
+ describe("#getKeys()/#pushKey()/#popKey()", () => {
+ it("enqueues keys", () => {
expect(sut.getKeys()).to.be.empty;
- sut.pushKey('a');
- sut.pushKey('b');
- sut.pushKey('c');
- expect(sut.getKeys()).to.deep.equal(['a', 'b', 'c']);
+ sut.pushKey("a");
+ sut.pushKey("b");
+ sut.pushKey("c");
+ expect(sut.getKeys()).to.deep.equal(["a", "b", "c"]);
sut.popKey();
- expect(sut.getKeys()).to.deep.equal(['a', 'b']);
+ expect(sut.getKeys()).to.deep.equal(["a", "b"]);
sut.clearKeys();
expect(sut.getKeys()).to.be.empty;
});
});
});
-
-
-
diff --git a/test/content/repositories/FollowMasterRepository.test.ts b/test/content/repositories/FollowMasterRepository.test.ts
index 3eb172f..9b5e151 100644
--- a/test/content/repositories/FollowMasterRepository.test.ts
+++ b/test/content/repositories/FollowMasterRepository.test.ts
@@ -1,42 +1,43 @@
-import FollowMasterRepository, { FollowMasterRepositoryImpl }
- from '../../../src/content/repositories/FollowMasterRepository';
-import { expect } from 'chai';
+import FollowMasterRepository, {
+ FollowMasterRepositoryImpl,
+} from "../../../src/content/repositories/FollowMasterRepository";
+import { expect } from "chai";
-describe('FollowMasterRepositoryImpl', () => {
+describe("FollowMasterRepositoryImpl", () => {
let sut: FollowMasterRepository;
before(() => {
sut = new FollowMasterRepositoryImpl();
});
- describe('#getTags()/#addTag()/#clearTags()', () => {
- it('gets, adds and clears tags', () => {
+ describe("#getTags()/#addTag()/#clearTags()", () => {
+ it("gets, adds and clears tags", () => {
expect(sut.getTags()).to.be.empty;
- sut.addTag('a');
- sut.addTag('b');
- sut.addTag('c');
- expect(sut.getTags()).to.deep.equal(['a', 'b', 'c']);
+ sut.addTag("a");
+ sut.addTag("b");
+ sut.addTag("c");
+ expect(sut.getTags()).to.deep.equal(["a", "b", "c"]);
sut.clearTags();
expect(sut.getTags()).to.be.empty;
});
});
- describe('#getTagsByPrefix', () => {
- it('gets tags matched by prefix', () => {
- for (const tag of ['a', 'aa', 'ab', 'b', 'ba', 'bb']) {
+ describe("#getTagsByPrefix", () => {
+ it("gets tags matched by prefix", () => {
+ for (const tag of ["a", "aa", "ab", "b", "ba", "bb"]) {
sut.addTag(tag);
}
- expect(sut.getTagsByPrefix('a')).to.deep.equal(['a', 'aa', 'ab']);
- expect(sut.getTagsByPrefix('aa')).to.deep.equal(['aa']);
- expect(sut.getTagsByPrefix('b')).to.deep.equal(['b', 'ba', 'bb']);
- expect(sut.getTagsByPrefix('c')).to.be.empty;
+ expect(sut.getTagsByPrefix("a")).to.deep.equal(["a", "aa", "ab"]);
+ expect(sut.getTagsByPrefix("aa")).to.deep.equal(["aa"]);
+ expect(sut.getTagsByPrefix("b")).to.deep.equal(["b", "ba", "bb"]);
+ expect(sut.getTagsByPrefix("c")).to.be.empty;
});
});
- describe('#setCurrentFollowMode()/#getCurrentNewTabMode()/#getCurrentBackgroundMode', () => {
- it('updates and gets follow mode', () => {
+ describe("#setCurrentFollowMode()/#getCurrentNewTabMode()/#getCurrentBackgroundMode", () => {
+ it("updates and gets follow mode", () => {
sut.setCurrentFollowMode(false, true);
expect(sut.getCurrentNewTabMode()).to.be.false;
expect(sut.getCurrentBackgroundMode()).to.be.true;
diff --git a/test/content/repositories/FollowSlaveRepository.test.ts b/test/content/repositories/FollowSlaveRepository.test.ts
index 10cf094..0f829b2 100644
--- a/test/content/repositories/FollowSlaveRepository.test.ts
+++ b/test/content/repositories/FollowSlaveRepository.test.ts
@@ -1,16 +1,17 @@
-import FollowSlaveRepository, { FollowSlaveRepositoryImpl }
- from '../../../src/content/repositories/FollowSlaveRepository';
-import { expect } from 'chai';
+import FollowSlaveRepository, {
+ FollowSlaveRepositoryImpl,
+} from "../../../src/content/repositories/FollowSlaveRepository";
+import { expect } from "chai";
-describe('FollowSlaveRepository', () => {
+describe("FollowSlaveRepository", () => {
let sut: FollowSlaveRepository;
before(() => {
sut = new FollowSlaveRepositoryImpl();
});
- describe('#isFollowMode()/#enableFollowMode()/#disableFollowMode()', () => {
- it('gets, adds updates follow mode', () => {
+ describe("#isFollowMode()/#enableFollowMode()/#disableFollowMode()", () => {
+ it("gets, adds updates follow mode", () => {
expect(sut.isFollowMode()).to.be.false;
sut.enableFollowMode();
@@ -21,4 +22,3 @@ describe('FollowSlaveRepository', () => {
});
});
});
-
diff --git a/test/content/repositories/KeymapRepository.test.ts b/test/content/repositories/KeymapRepository.test.ts
index 68f515c..0e01a73 100644
--- a/test/content/repositories/KeymapRepository.test.ts
+++ b/test/content/repositories/KeymapRepository.test.ts
@@ -1,39 +1,38 @@
-import KeymapRepository, { KeymapRepositoryImpl }
- from '../../../src/content/repositories/KeymapRepository';
-import { expect } from 'chai';
+import KeymapRepository, {
+ KeymapRepositoryImpl,
+} from "../../../src/content/repositories/KeymapRepository";
+import { expect } from "chai";
import Key from "../../../src/shared/settings/Key";
-describe('KeymapRepositoryImpl', () => {
+describe("KeymapRepositoryImpl", () => {
let sut: KeymapRepository;
before(() => {
sut = new KeymapRepositoryImpl();
});
- describe('#enqueueKey()', () => {
- it('enqueues keys', () => {
- sut.enqueueKey(Key.fromMapKey('a'));
- sut.enqueueKey(Key.fromMapKey('b'));
- const sequence = sut.enqueueKey(Key.fromMapKey('c'));
+ describe("#enqueueKey()", () => {
+ it("enqueues keys", () => {
+ sut.enqueueKey(Key.fromMapKey("a"));
+ sut.enqueueKey(Key.fromMapKey("b"));
+ const sequence = sut.enqueueKey(Key.fromMapKey("c"));
const keys = sequence.keys;
- expect(keys[0].equals(Key.fromMapKey('a'))).to.be.true;
- expect(keys[1].equals(Key.fromMapKey('b'))).to.be.true;
- expect(keys[2].equals(Key.fromMapKey('c'))).to.be.true;
+ expect(keys[0].equals(Key.fromMapKey("a"))).to.be.true;
+ expect(keys[1].equals(Key.fromMapKey("b"))).to.be.true;
+ expect(keys[2].equals(Key.fromMapKey("c"))).to.be.true;
});
});
- describe('#clear()', () => {
- it('clears keys', () => {
- sut.enqueueKey(Key.fromMapKey('a'));
- sut.enqueueKey(Key.fromMapKey('b'));
- sut.enqueueKey(Key.fromMapKey('c'));
+ describe("#clear()", () => {
+ it("clears keys", () => {
+ sut.enqueueKey(Key.fromMapKey("a"));
+ sut.enqueueKey(Key.fromMapKey("b"));
+ sut.enqueueKey(Key.fromMapKey("c"));
sut.clear();
- const sequence = sut.enqueueKey(Key.fromMapKey('a'));
+ const sequence = sut.enqueueKey(Key.fromMapKey("a"));
expect(sequence.length()).to.equal(1);
});
});
});
-
-
diff --git a/test/content/repositories/MarkKeyRepository.test.ts b/test/content/repositories/MarkKeyRepository.test.ts
index 8592332..473b4dc 100644
--- a/test/content/repositories/MarkKeyRepository.test.ts
+++ b/test/content/repositories/MarkKeyRepository.test.ts
@@ -1,16 +1,17 @@
-import MarkRepository, { MarkKeyRepositoryImpl }
- from '../../../src/content/repositories/MarkKeyRepository';
-import { expect } from 'chai';
+import MarkRepository, {
+ MarkKeyRepositoryImpl,
+} from "../../../src/content/repositories/MarkKeyRepository";
+import { expect } from "chai";
-describe('MarkKeyRepositoryImpl', () => {
+describe("MarkKeyRepositoryImpl", () => {
let sut: MarkRepository;
before(() => {
sut = new MarkKeyRepositoryImpl();
- })
+ });
- describe('#isSetMode/#enableSetMode/#disabeSetMode', () => {
- it('enables and disables set mode', () => {
+ describe("#isSetMode/#enableSetMode/#disabeSetMode", () => {
+ it("enables and disables set mode", () => {
expect(sut.isSetMode()).to.be.false;
sut.enableSetMode();
@@ -21,8 +22,8 @@ describe('MarkKeyRepositoryImpl', () => {
});
});
- describe('#isJumpMode/#enableJumpMode/#disabeJumpMode', () => {
- it('enables and disables jump mode', () => {
+ describe("#isJumpMode/#enableJumpMode/#disabeJumpMode", () => {
+ it("enables and disables jump mode", () => {
expect(sut.isJumpMode()).to.be.false;
sut.enableJumpMode();
@@ -33,4 +34,3 @@ describe('MarkKeyRepositoryImpl', () => {
});
});
});
-
diff --git a/test/content/repositories/MarkRepository.test.ts b/test/content/repositories/MarkRepository.test.ts
index 6ddd38d..f2a7326 100644
--- a/test/content/repositories/MarkRepository.test.ts
+++ b/test/content/repositories/MarkRepository.test.ts
@@ -1,13 +1,12 @@
-import { MarkRepositoryImpl } from '../../../src/content/repositories/MarkRepository';
-import { expect } from 'chai';
+import { MarkRepositoryImpl } from "../../../src/content/repositories/MarkRepository";
+import { expect } from "chai";
-describe('MarkRepositoryImpl', () => {
- it('save and load marks', () => {
+describe("MarkRepositoryImpl", () => {
+ it("save and load marks", () => {
const sut = new MarkRepositoryImpl();
- sut.set('a', { x: 10, y: 20 });
- expect(sut.get('a')).to.deep.equal({ x: 10, y: 20 });
- expect(sut.get('b')).to.be.null;
+ sut.set("a", { x: 10, y: 20 });
+ expect(sut.get("a")).to.deep.equal({ x: 10, y: 20 });
+ expect(sut.get("b")).to.be.null;
});
});
-
diff --git a/test/content/repositories/SettingRepository.test.ts b/test/content/repositories/SettingRepository.test.ts
index e45d7c4..99247a9 100644
--- a/test/content/repositories/SettingRepository.test.ts
+++ b/test/content/repositories/SettingRepository.test.ts
@@ -1,23 +1,23 @@
-import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
-import { expect } from 'chai';
-import Settings from '../../../src/shared/settings/Settings';
+import { SettingRepositoryImpl } from "../../../src/content/repositories/SettingRepository";
+import { expect } from "chai";
+import Settings from "../../../src/shared/settings/Settings";
-describe('SettingRepositoryImpl', () => {
- it('updates and gets current value', () => {
+describe("SettingRepositoryImpl", () => {
+ it("updates and gets current value", () => {
const sut = new SettingRepositoryImpl();
const settings = Settings.fromJSON({
keymaps: {},
- search:{
- default: 'google',
+ search: {
+ default: "google",
engines: {
- google: 'https://google.com/?q={}',
- }
+ google: "https://google.com/?q={}",
+ },
},
properties: {
- hintchars: 'abcd1234',
+ hintchars: "abcd1234",
smoothscroll: false,
- complete: 'sbh',
+ complete: "sbh",
},
blacklist: [],
});
@@ -25,6 +25,6 @@ describe('SettingRepositoryImpl', () => {
sut.set(settings);
const actual = sut.get();
- expect(actual.properties.hintchars).to.equal('abcd1234');
+ expect(actual.properties.hintchars).to.equal("abcd1234");
});
});
diff --git a/test/content/usecases/AddonEnabledUseCase.test.ts b/test/content/usecases/AddonEnabledUseCase.test.ts
index 8c15099..885da83 100644
--- a/test/content/usecases/AddonEnabledUseCase.test.ts
+++ b/test/content/usecases/AddonEnabledUseCase.test.ts
@@ -1,7 +1,7 @@
-import AddonEnabledRepository from '../../../src/content/repositories/AddonEnabledRepository';
-import AddonEnabledUseCase from '../../../src/content/usecases/AddonEnabledUseCase';
-import AddonIndicatorClient from '../../../src/content/client/AddonIndicatorClient';
-import { expect } from 'chai';
+import AddonEnabledRepository from "../../../src/content/repositories/AddonEnabledRepository";
+import AddonEnabledUseCase from "../../../src/content/usecases/AddonEnabledUseCase";
+import AddonIndicatorClient from "../../../src/content/client/AddonIndicatorClient";
+import { expect } from "chai";
class MockAddonEnabledRepository implements AddonEnabledRepository {
private enabled: boolean;
@@ -28,11 +28,11 @@ class MockAddonIndicatorClient implements AddonIndicatorClient {
async setEnabled(enabled: boolean): Promise<void> {
this.enabled = enabled;
- return
+ return;
}
}
-describe('AddonEnabledUseCase', () => {
+describe("AddonEnabledUseCase", () => {
let repository: MockAddonEnabledRepository;
let indicator: MockAddonIndicatorClient;
let sut: AddonEnabledUseCase;
@@ -43,8 +43,8 @@ describe('AddonEnabledUseCase', () => {
sut = new AddonEnabledUseCase(indicator, repository);
});
- describe('#enable', () => {
- it('store and indicate as enabled', async() => {
+ describe("#enable", () => {
+ it("store and indicate as enabled", async () => {
await sut.enable();
expect(repository.get()).to.be.true;
@@ -52,8 +52,8 @@ describe('AddonEnabledUseCase', () => {
});
});
- describe('#disable', async() => {
- it('store and indicate as disabled', async() => {
+ describe("#disable", async () => {
+ it("store and indicate as disabled", async () => {
await sut.disable();
expect(repository.get()).to.be.false;
@@ -61,8 +61,8 @@ describe('AddonEnabledUseCase', () => {
});
});
- describe('#toggle', () => {
- it('toggled enabled and disabled', async() => {
+ describe("#toggle", () => {
+ it("toggled enabled and disabled", async () => {
repository.set(true);
await sut.toggle();
@@ -78,8 +78,8 @@ describe('AddonEnabledUseCase', () => {
});
});
- describe('#getEnabled', () => {
- it('returns current addon enabled', () => {
+ describe("#getEnabled", () => {
+ it("returns current addon enabled", () => {
repository.set(true);
expect(sut.getEnabled()).to.be.true;
diff --git a/test/content/usecases/ClipboardUseCase.test.ts b/test/content/usecases/ClipboardUseCase.test.ts
index 3cc82fe..5de3e69 100644
--- a/test/content/usecases/ClipboardUseCase.test.ts
+++ b/test/content/usecases/ClipboardUseCase.test.ts
@@ -1,14 +1,14 @@
-import ClipboardRepository from '../../../src/content/repositories/ClipboardRepository';
-import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
-import ClipboardUseCase from '../../../src/content/usecases/ClipboardUseCase';
-import OperationClient from '../../../src/content/client/OperationClient';
-import ConsoleClient from '../../../src/content/client/ConsoleClient';
+import ClipboardRepository from "../../../src/content/repositories/ClipboardRepository";
+import { SettingRepositoryImpl } from "../../../src/content/repositories/SettingRepository";
+import ClipboardUseCase from "../../../src/content/usecases/ClipboardUseCase";
+import OperationClient from "../../../src/content/client/OperationClient";
+import ConsoleClient from "../../../src/content/client/ConsoleClient";
-import * as sinon from 'sinon';
-import { expect } from 'chai';
-import {Operation} from "../../../src/shared/operations";
+import * as sinon from "sinon";
+import { expect } from "chai";
+import { Operation } from "../../../src/shared/operations";
-describe('ClipboardUseCase', () => {
+describe("ClipboardUseCase", () => {
let clipboardRepository: ClipboardRepository;
let operationClient: OperationClient;
@@ -18,34 +18,48 @@ describe('ClipboardUseCase', () => {
let sut: ClipboardUseCase;
beforeEach(() => {
- clipboardRepository = new class implements ClipboardRepository {
- read(): string { return ""; }
+ clipboardRepository = new (class implements ClipboardRepository {
+ read(): string {
+ return "";
+ }
write(_text: string) {}
- };
- operationClient = new class implements OperationClient {
- execBackgroundOp(_repeat: number, _op: Operation): Promise<void> { return Promise.resolve() }
- internalOpenUrl(_url: string, _newTab?: boolean, _background?: boolean): Promise<void> { return Promise.resolve() }
- };
- consoleClient = new class implements ConsoleClient {
- error(_text: string): Promise<void> { return Promise.resolve() }
- info(_text: string): Promise<void> { return Promise.resolve() }
- };
+ })();
+ operationClient = new (class implements OperationClient {
+ execBackgroundOp(_repeat: number, _op: Operation): Promise<void> {
+ return Promise.resolve();
+ }
+ internalOpenUrl(
+ _url: string,
+ _newTab?: boolean,
+ _background?: boolean
+ ): Promise<void> {
+ return Promise.resolve();
+ }
+ })();
+ consoleClient = new (class implements ConsoleClient {
+ error(_text: string): Promise<void> {
+ return Promise.resolve();
+ }
+ info(_text: string): Promise<void> {
+ return Promise.resolve();
+ }
+ })();
sut = new ClipboardUseCase(
clipboardRepository,
new SettingRepositoryImpl(),
consoleClient,
- operationClient,
- );
+ operationClient
+ );
});
- describe('#yankCurrentURL', () => {
- it('yanks current url', async () => {
+ describe("#yankCurrentURL", () => {
+ it("yanks current url", async () => {
const href = window.location.href;
const mockRepository = sinon.mock(clipboardRepository);
- mockRepository.expects('write').withArgs(href);
+ mockRepository.expects("write").withArgs(href);
const mockConsoleClient = sinon.mock(consoleClient);
- mockConsoleClient.expects('info').withArgs('Yanked ' + href);
+ mockConsoleClient.expects("info").withArgs("Yanked " + href);
const yanked = await sut.yankCurrentURL();
@@ -55,23 +69,23 @@ describe('ClipboardUseCase', () => {
});
});
- describe('#openOrSearch', () => {
- it('opens url from the clipboard', async () => {
- const url = 'https://github.com/ueokande/vim-vixen'
- sinon.stub(clipboardRepository, 'read').returns(url);
+ describe("#openOrSearch", () => {
+ it("opens url from the clipboard", async () => {
+ const url = "https://github.com/ueokande/vim-vixen";
+ sinon.stub(clipboardRepository, "read").returns(url);
const mockOperationClient = sinon.mock(operationClient);
- mockOperationClient.expects('internalOpenUrl').withArgs(url, true);
+ mockOperationClient.expects("internalOpenUrl").withArgs(url, true);
await sut.openOrSearch(true);
mockOperationClient.verify();
});
- it('opens search results from the clipboard', async () => {
- const url = 'https://google.com/search?q=banana';
- sinon.stub(clipboardRepository, 'read').returns('banana');
+ it("opens search results from the clipboard", async () => {
+ const url = "https://google.com/search?q=banana";
+ sinon.stub(clipboardRepository, "read").returns("banana");
const mockOperationClient = sinon.mock(operationClient);
- mockOperationClient.expects('internalOpenUrl').withArgs(url, true);
+ mockOperationClient.expects("internalOpenUrl").withArgs(url, true);
await sut.openOrSearch(true);
diff --git a/test/content/usecases/FindUseCase.test.ts b/test/content/usecases/FindUseCase.test.ts
index 3978dbc..b53ef74 100644
--- a/test/content/usecases/FindUseCase.test.ts
+++ b/test/content/usecases/FindUseCase.test.ts
@@ -1,9 +1,9 @@
-import FindRepository from '../../../src/content/repositories/FindRepository';
-import FindPresenter from '../../../src/content/presenters/FindPresenter';
-import FindClient from '../../../src/content/client/FindClient';
-import FindUseCase from '../../../src/content/usecases/FindUseCase';
-import MockConsoleClient from '../mock/MockConsoleClient';
-import { expect } from 'chai';
+import FindRepository from "../../../src/content/repositories/FindRepository";
+import FindPresenter from "../../../src/content/presenters/FindPresenter";
+import FindClient from "../../../src/content/client/FindClient";
+import FindUseCase from "../../../src/content/usecases/FindUseCase";
+import MockConsoleClient from "../mock/MockConsoleClient";
+import { expect } from "chai";
class MockFindRepository implements FindRepository {
public keyword: string | null;
@@ -27,7 +27,7 @@ class MockFindPresenter implements FindPresenter {
public highlighted: boolean;
constructor() {
- this.document = '';
+ this.document = "";
this.highlighted = false;
}
@@ -59,7 +59,7 @@ class MockFindClient implements FindClient {
}
}
-describe('FindUseCase', () => {
+describe("FindUseCase", () => {
let repository: MockFindRepository;
let presenter: MockFindPresenter;
let client: MockFindClient;
@@ -74,88 +74,87 @@ describe('FindUseCase', () => {
sut = new FindUseCase(presenter, repository, client, consoleClient);
});
- describe('#startFind', () => {
- it('find next by ketword', async() => {
- presenter.document = 'monkey punch';
+ describe("#startFind", () => {
+ it("find next by ketword", async () => {
+ presenter.document = "monkey punch";
- await sut.startFind('monkey');
+ await sut.startFind("monkey");
expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal('Pattern found: monkey');
- expect(await repository.getLastKeyword()).to.equal('monkey');
- expect(await client.getGlobalLastKeyword()).to.equal('monkey');
+ expect(await consoleClient.text).to.equal("Pattern found: monkey");
+ expect(await repository.getLastKeyword()).to.equal("monkey");
+ expect(await client.getGlobalLastKeyword()).to.equal("monkey");
});
- it('find next by last keyword', async() => {
- presenter.document = 'gorilla kick';
- repository.keyword = 'gorilla';
+ it("find next by last keyword", async () => {
+ presenter.document = "gorilla kick";
+ repository.keyword = "gorilla";
await sut.startFind(undefined);
expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal('Pattern found: gorilla');
- expect(await repository.getLastKeyword()).to.equal('gorilla');
- expect(await client.getGlobalLastKeyword()).to.equal('gorilla');
+ expect(await consoleClient.text).to.equal("Pattern found: gorilla");
+ expect(await repository.getLastKeyword()).to.equal("gorilla");
+ expect(await client.getGlobalLastKeyword()).to.equal("gorilla");
});
- it('find next by global last keyword', async() => {
- presenter.document = 'chimpanzee typing';
+ it("find next by global last keyword", async () => {
+ presenter.document = "chimpanzee typing";
repository.keyword = null;
- client.keyword = 'chimpanzee';
+ client.keyword = "chimpanzee";
await sut.startFind(undefined);
expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal('Pattern found: chimpanzee');
- expect(await repository.getLastKeyword()).to.equal('chimpanzee');
- expect(await client.getGlobalLastKeyword()).to.equal('chimpanzee');
+ expect(await consoleClient.text).to.equal("Pattern found: chimpanzee");
+ expect(await repository.getLastKeyword()).to.equal("chimpanzee");
+ expect(await client.getGlobalLastKeyword()).to.equal("chimpanzee");
});
- it('find not found error', async() => {
- presenter.document = 'zoo';
+ it("find not found error", async () => {
+ presenter.document = "zoo";
- await sut.startFind('giraffe');
+ await sut.startFind("giraffe");
expect(await presenter.highlighted).to.be.false;
- expect(await consoleClient.text).to.equal('Pattern not found: giraffe');
- expect(await repository.getLastKeyword()).to.equal('giraffe');
- expect(await client.getGlobalLastKeyword()).to.equal('giraffe');
+ expect(await consoleClient.text).to.equal("Pattern not found: giraffe");
+ expect(await repository.getLastKeyword()).to.equal("giraffe");
+ expect(await client.getGlobalLastKeyword()).to.equal("giraffe");
});
- it('show errors when no last keywords', async() => {
+ it("show errors when no last keywords", async () => {
repository.keyword = null;
client.keyword = null;
await sut.startFind(undefined);
- expect(await consoleClient.text).to.equal('No previous search keywords');
+ expect(await consoleClient.text).to.equal("No previous search keywords");
expect(await consoleClient.isError).to.be.true;
});
});
- describe('#findNext', () => {
- it('finds by last keyword', async() => {
- presenter.document = 'monkey punch';
- repository.keyword = 'monkey';
+ describe("#findNext", () => {
+ it("finds by last keyword", async () => {
+ presenter.document = "monkey punch";
+ repository.keyword = "monkey";
await sut.findNext();
expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal('Pattern found: monkey');
+ expect(await consoleClient.text).to.equal("Pattern found: monkey");
});
- it('show errors when no last keywords', async() => {
+ it("show errors when no last keywords", async () => {
repository.keyword = null;
client.keyword = null;
await sut.findNext();
- expect(await consoleClient.text).to.equal('No previous search keywords');
+ expect(await consoleClient.text).to.equal("No previous search keywords");
expect(await consoleClient.isError).to.be.true;
});
});
- describe('#findPrev', () => {
- });
+ describe("#findPrev", () => {});
});
diff --git a/test/content/usecases/HintKeyProducer.test.ts b/test/content/usecases/HintKeyProducer.test.ts
index 5841ae9..f7e02ea 100644
--- a/test/content/usecases/HintKeyProducer.test.ts
+++ b/test/content/usecases/HintKeyProducer.test.ts
@@ -1,20 +1,34 @@
-import HintKeyProducer from '../../../src/content/usecases/HintKeyProducer';
-import { expect } from 'chai';
+import HintKeyProducer from "../../../src/content/usecases/HintKeyProducer";
+import { expect } from "chai";
-describe('HintKeyProducer class', () => {
- describe('#constructor', () => {
- it('throws an exception on empty charset', () => {
- expect(() => new HintKeyProducer('')).to.throw(TypeError);
+describe("HintKeyProducer class", () => {
+ describe("#constructor", () => {
+ it("throws an exception on empty charset", () => {
+ expect(() => new HintKeyProducer("")).to.throw(TypeError);
});
});
- describe('#produce', () => {
- it('produce incremented keys', () => {
- const charset = 'abc';
+ describe("#produce", () => {
+ it("produce incremented keys", () => {
+ const charset = "abc";
const sequences = [
- 'a', 'b', 'c',
- 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc',
- 'aaa', 'aab', 'aac', 'aba']
+ "a",
+ "b",
+ "c",
+ "aa",
+ "ab",
+ "ac",
+ "ba",
+ "bb",
+ "bc",
+ "ca",
+ "cb",
+ "cc",
+ "aaa",
+ "aab",
+ "aac",
+ "aba",
+ ];
const producer = new HintKeyProducer(charset);
for (let i = 0; i < sequences.length; ++i) {
diff --git a/test/content/usecases/KeymapUseCase.test.ts b/test/content/usecases/KeymapUseCase.test.ts
index 032d4fc..24ac6d8 100644
--- a/test/content/usecases/KeymapUseCase.test.ts
+++ b/test/content/usecases/KeymapUseCase.test.ts
@@ -1,62 +1,52 @@
import "reflect-metadata";
-import KeymapUseCase from '../../../src/content/usecases/KeymapUseCase';
-import {expect} from 'chai';
+import KeymapUseCase from "../../../src/content/usecases/KeymapUseCase";
+import { expect } from "chai";
import SettingRepository from "../../../src/content/repositories/SettingRepository";
import Settings from "../../../src/shared/settings/Settings";
import AddonEnabledRepository from "../../../src/content/repositories/AddonEnabledRepository";
-import {KeymapRepositoryImpl} from "../../../src/content/repositories/KeymapRepository";
+import { KeymapRepositoryImpl } from "../../../src/content/repositories/KeymapRepository";
import Key from "../../../src/shared/settings/Key";
import AddressRepository from "../../../src/content/repositories/AddressRepository";
class MockSettingRepository implements SettingRepository {
- constructor(
- private readonly settings: Settings,
- ) {
- }
+ constructor(private readonly settings: Settings) {}
get(): Settings {
return this.settings;
}
set(_setting: Settings): void {
- throw new Error('TODO');
+ throw new Error("TODO");
}
}
class MockAddonEnabledRepository implements AddonEnabledRepository {
- constructor(
- private readonly enabled: boolean,
- ) {
- }
+ constructor(private readonly enabled: boolean) {}
get(): boolean {
return this.enabled;
}
set(_on: boolean): void {
- throw new Error('TODO');
+ throw new Error("TODO");
}
}
class MockAddressRepository implements AddressRepository {
- constructor(
- private url: URL,
- ) {
- }
+ constructor(private url: URL) {}
getCurrentURL(): URL {
return this.url;
}
}
-
-describe('KeymapUseCase', () => {
- context('with no-digis keymaps', () => {
+describe("KeymapUseCase", () => {
+ context("with no-digis keymaps", () => {
const settings = Settings.fromJSON({
keymaps: {
- k: {type: 'scroll.vertically', count: -1},
- j: {type: 'scroll.vertically', count: 1},
- gg: {type: 'scroll.top'},
+ k: { type: "scroll.vertically", count: -1 },
+ j: { type: "scroll.vertically", count: 1 },
+ gg: { type: "scroll.top" },
},
});
@@ -64,34 +54,46 @@ describe('KeymapUseCase', () => {
before(() => {
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.com"))
);
});
- it('returns matched operation', () => {
- expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.vertically', count: -1}});
- expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.vertically', count: 1}});
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.top'}});
- expect(sut.nextOps(Key.fromMapKey('z'))).to.be.null;
+ it("returns matched operation", () => {
+ expect(sut.nextOps(Key.fromMapKey("k"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.vertically", count: -1 },
+ });
+ expect(sut.nextOps(Key.fromMapKey("j"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.vertically", count: 1 },
+ });
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.top" },
+ });
+ expect(sut.nextOps(Key.fromMapKey("z"))).to.be.null;
});
- it('repeats n-times by numeric prefix and multiple key operations', () => {
- expect(sut.nextOps(Key.fromMapKey('1'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 10, op: {type: "scroll.top"}});
+ it("repeats n-times by numeric prefix and multiple key operations", () => {
+ expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 10,
+ op: { type: "scroll.top" },
+ });
});
});
- context('when keymaps containing numeric mappings', () => {
+ context("when keymaps containing numeric mappings", () => {
const settings = Settings.fromJSON({
keymaps: {
- 20: {type: "scroll.top"},
- g5: {type: 'scroll.bottom'},
+ 20: { type: "scroll.top" },
+ g5: { type: "scroll.bottom" },
},
});
@@ -99,43 +101,55 @@ describe('KeymapUseCase', () => {
before(() => {
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.com"))
);
});
- it('returns the matched operation ends with digit', () => {
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal({ repeat: 1, op: { type: 'scroll.bottom'}});
+ it("returns the matched operation ends with digit", () => {
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.bottom" },
+ });
});
- it('returns an operation matched the operation with digit keymaps', () => {
- expect(sut.nextOps(Key.fromMapKey('2'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.deep.equal({ repeat: 1, op: { type: 'scroll.top'}});
+ it("returns an operation matched the operation with digit keymaps", () => {
+ expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.top" },
+ });
});
- it('returns operations repeated by numeric prefix', () => {
- expect(sut.nextOps(Key.fromMapKey('2'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal({ repeat: 2, op: { type: 'scroll.bottom'}});
+ it("returns operations repeated by numeric prefix", () => {
+ expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({
+ repeat: 2,
+ op: { type: "scroll.bottom" },
+ });
});
- it('does not matches with digit operation with numeric prefix', () => {
- expect(sut.nextOps(Key.fromMapKey('3'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('2'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal({ repeat: 320, op: { type: 'scroll.bottom'}});
+ it("does not matches with digit operation with numeric prefix", () => {
+ expect(sut.nextOps(Key.fromMapKey("3"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({
+ repeat: 320,
+ op: { type: "scroll.bottom" },
+ });
});
});
- context('when the keys are mismatched with the operations', () => {
+ context("when the keys are mismatched with the operations", () => {
const settings = Settings.fromJSON({
keymaps: {
- gg: {type: "scroll.top"},
- G: {type: "scroll.bottom"},
+ gg: { type: "scroll.top" },
+ G: { type: "scroll.bottom" },
},
});
@@ -143,38 +157,44 @@ describe('KeymapUseCase', () => {
before(() => {
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.com"))
);
});
- it('clears input keys with no-matched operations', () => {
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('x'))).to.be.null; // clear
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({repeat: 1, op: {type: "scroll.top"}});
+ it("clears input keys with no-matched operations", () => {
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("x"))).to.be.null; // clear
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.top" },
+ });
});
- it('clears input keys and the prefix with no-matched operations', () => {
- expect(sut.nextOps(Key.fromMapKey('1'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('x'))).to.be.null; // clear
- expect(sut.nextOps(Key.fromMapKey('1'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 10, op: {type: "scroll.top"}});
+ it("clears input keys and the prefix with no-matched operations", () => {
+ expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("x"))).to.be.null; // clear
+ expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 10,
+ op: { type: "scroll.top" },
+ });
});
});
- context('when the site matches to the blacklist', () => {
+ context("when the site matches to the blacklist", () => {
const settings = Settings.fromJSON({
keymaps: {
- k: {type: 'scroll.vertically', count: -1},
- a: {type: 'addon.enable'},
- b: {type: 'addon.toggle.enabled'},
+ k: { type: "scroll.vertically", count: -1 },
+ a: { type: "addon.enable" },
+ b: { type: "addon.toggle.enabled" },
},
});
@@ -182,58 +202,76 @@ describe('KeymapUseCase', () => {
before(() => {
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(false),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(false),
+ new MockAddressRepository(new URL("https://example.com"))
);
});
- it('returns only ADDON_ENABLE and ADDON_TOGGLE_ENABLED operation', () => {
- expect(sut.nextOps(Key.fromMapKey('k'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('a'))).to.deep.equal({ repeat: 1, op: {type: 'addon.enable'}});
- expect(sut.nextOps(Key.fromMapKey('b'))).to.deep.equal({ repeat: 1, op: {type: 'addon.toggle.enabled'}});
+ it("returns only ADDON_ENABLE and ADDON_TOGGLE_ENABLED operation", () => {
+ expect(sut.nextOps(Key.fromMapKey("k"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("a"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "addon.enable" },
+ });
+ expect(sut.nextOps(Key.fromMapKey("b"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "addon.toggle.enabled" },
+ });
});
});
- context('when the site matches to the partial blacklist', () => {
+ context("when the site matches to the partial blacklist", () => {
const settings = Settings.fromJSON({
keymaps: {
- k: {type: 'scroll.vertically', count: -1},
- j: {type: 'scroll.vertically', count: 1},
- gg: {type: "scroll.top"},
- G: {type: "scroll.bottom"},
+ k: { type: "scroll.vertically", count: -1 },
+ j: { type: "scroll.vertically", count: 1 },
+ gg: { type: "scroll.top" },
+ G: { type: "scroll.bottom" },
},
blacklist: [
- { url: "example.com", keys: ['g'] },
- { url: "example.org", keys: ['<S-G>'] }
+ { url: "example.com", keys: ["g"] },
+ { url: "example.org", keys: ["<S-G>"] },
],
});
- it('blocks keys in the partial blacklist', () => {
+ it("blocks keys in the partial blacklist", () => {
let sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.com"))
);
- expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.vertically', count: -1}});
- expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.vertically', count: 1}});
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('G'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.bottom'}});
+ expect(sut.nextOps(Key.fromMapKey("k"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.vertically", count: -1 },
+ });
+ expect(sut.nextOps(Key.fromMapKey("j"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.vertically", count: 1 },
+ });
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("G"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.bottom" },
+ });
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.org')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.org"))
);
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.top'}});
- expect(sut.nextOps(Key.fromMapKey('G'))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.top" },
+ });
+ expect(sut.nextOps(Key.fromMapKey("G"))).to.be.null;
});
});
});
diff --git a/test/content/usecases/MarkUseCase.test.ts b/test/content/usecases/MarkUseCase.test.ts
index 494497a..df3f7bf 100644
--- a/test/content/usecases/MarkUseCase.test.ts
+++ b/test/content/usecases/MarkUseCase.test.ts
@@ -1,14 +1,14 @@
-import MarkRepository from '../../../src/content/repositories/MarkRepository';
-import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
-import MarkUseCase from '../../../src/content/usecases/MarkUseCase';
-import MarkClient from '../../../src/content/client/MarkClient';
-import MockConsoleClient from '../mock/MockConsoleClient';
-import MockScrollPresenter from '../mock/MockScrollPresenter';
-import Mark from '../../../src/content/domains/Mark';
-import { expect } from 'chai';
+import MarkRepository from "../../../src/content/repositories/MarkRepository";
+import { SettingRepositoryImpl } from "../../../src/content/repositories/SettingRepository";
+import MarkUseCase from "../../../src/content/usecases/MarkUseCase";
+import MarkClient from "../../../src/content/client/MarkClient";
+import MockConsoleClient from "../mock/MockConsoleClient";
+import MockScrollPresenter from "../mock/MockScrollPresenter";
+import Mark from "../../../src/content/domains/Mark";
+import { expect } from "chai";
class MockMarkRepository implements MarkRepository {
- private current: {[key: string]: Mark};
+ private current: { [key: string]: Mark };
constructor() {
this.current = {};
@@ -24,12 +24,12 @@ class MockMarkRepository implements MarkRepository {
}
class MockMarkClient implements MarkClient {
- public marks: {[key: string]: Mark};
+ public marks: { [key: string]: Mark };
public last: string;
constructor() {
this.marks = {};
- this.last = '';
+ this.last = "";
}
setGloablMark(key: string, mark: Mark): Promise<void> {
@@ -38,12 +38,12 @@ class MockMarkClient implements MarkClient {
}
jumpGlobalMark(key: string): Promise<void> {
- this.last = key
+ this.last = key;
return Promise.resolve();
}
}
-describe('MarkUseCase', () => {
+describe("MarkUseCase", () => {
let repository: MockMarkRepository;
let client: MockMarkClient;
let consoleClient: MockConsoleClient;
@@ -60,53 +60,56 @@ describe('MarkUseCase', () => {
client,
repository,
new SettingRepositoryImpl(),
- consoleClient,
+ consoleClient
);
});
- describe('#set', () => {
- it('sets local mark', async() => {
+ describe("#set", () => {
+ it("sets local mark", async () => {
scrollPresenter.scrollTo(10, 20, false);
- await sut.set('x');
+ await sut.set("x");
- expect(repository.get('x')).to.deep.equals({ x: 10, y: 20 });
+ expect(repository.get("x")).to.deep.equals({ x: 10, y: 20 });
expect(consoleClient.text).to.equal("Set local mark to 'x'");
});
- it('sets global mark', async() => {
+ it("sets global mark", async () => {
scrollPresenter.scrollTo(30, 40, false);
- await sut.set('Z');
+ await sut.set("Z");
- expect(client.marks['Z']).to.deep.equals({ x: 30, y: 40 });
+ expect(client.marks["Z"]).to.deep.equals({ x: 30, y: 40 });
expect(consoleClient.text).to.equal("Set global mark to 'Z'");
});
});
- describe('#jump', () => {
- it('jumps to local mark', async() => {
- repository.set('x', { x: 20, y: 40 });
+ describe("#jump", () => {
+ it("jumps to local mark", async () => {
+ repository.set("x", { x: 20, y: 40 });
- await sut.jump('x');
+ await sut.jump("x");
expect(scrollPresenter.getScroll()).to.deep.equals({ x: 20, y: 40 });
});
- it('throws an error when no local marks', () => {
- return sut.jump('a').then(() => {
- throw new Error('error');
- }).catch((e) => {
- expect(e).to.be.instanceof(Error);
- })
- })
+ it("throws an error when no local marks", () => {
+ return sut
+ .jump("a")
+ .then(() => {
+ throw new Error("error");
+ })
+ .catch((e) => {
+ expect(e).to.be.instanceof(Error);
+ });
+ });
- it('jumps to global mark', async() => {
- client.marks['Z'] = { x: 20, y: 0 };
+ it("jumps to global mark", async () => {
+ client.marks["Z"] = { x: 20, y: 0 };
- await sut.jump('Z');
+ await sut.jump("Z");
- expect(client.last).to.equal('Z')
+ expect(client.last).to.equal("Z");
});
});
});
diff --git a/test/content/usecases/SettingUseCaase.test.ts b/test/content/usecases/SettingUseCaase.test.ts
index cf14e6e..1cc1e8a 100644
--- a/test/content/usecases/SettingUseCaase.test.ts
+++ b/test/content/usecases/SettingUseCaase.test.ts
@@ -1,8 +1,10 @@
-import SettingRepository from '../../../src/content/repositories/SettingRepository';
-import SettingClient from '../../../src/content/client/SettingClient';
-import SettingUseCase from '../../../src/content/usecases/SettingUseCase';
-import Settings, { DefaultSetting } from '../../../src/shared/settings/Settings';
-import { expect } from 'chai';
+import SettingRepository from "../../../src/content/repositories/SettingRepository";
+import SettingClient from "../../../src/content/client/SettingClient";
+import SettingUseCase from "../../../src/content/usecases/SettingUseCase";
+import Settings, {
+ DefaultSetting,
+} from "../../../src/shared/settings/Settings";
+import { expect } from "chai";
class MockSettingRepository implements SettingRepository {
private current: Settings;
@@ -12,7 +14,7 @@ class MockSettingRepository implements SettingRepository {
}
set(settings: Settings): void {
- this.current= settings;
+ this.current = settings;
}
get(): Settings {
@@ -32,40 +34,40 @@ class MockSettingClient implements SettingClient {
}
}
-describe('AddonEnabledUseCase', () => {
+describe("AddonEnabledUseCase", () => {
let repository: MockSettingRepository;
let client: MockSettingClient;
let sut: SettingUseCase;
beforeEach(() => {
- const testSettings = {
+ const testSettings = Settings.fromJSON({
keymaps: {},
search: {
- default: 'google',
+ default: "google",
engines: {
- google: 'https://google.com/?q={}',
- }
+ google: "https://google.com/?q={}",
+ },
},
properties: {
- hintchars: 'abcd1234',
+ hintchars: "abcd1234",
smoothscroll: false,
- complete: 'sbh',
+ complete: "sbh",
},
blacklist: [],
- };
+ });
repository = new MockSettingRepository();
client = new MockSettingClient(testSettings);
sut = new SettingUseCase(repository, client);
});
- describe('#reload', () => {
- it('loads settings and store to repository', async() => {
+ describe("#reload", () => {
+ it("loads settings and store to repository", async () => {
const settings = await sut.reload();
- expect(settings.properties.hintchars).to.equal('abcd1234');
+ expect(settings.properties.hintchars).to.equal("abcd1234");
const saved = repository.get();
- expect(saved.properties.hintchars).to.equal('abcd1234');
+ expect(saved.properties.hintchars).to.equal("abcd1234");
});
});
});