aboutsummaryrefslogtreecommitdiff
path: root/test/content/usecases/KeymapUseCase.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/content/usecases/KeymapUseCase.test.ts')
-rw-r--r--test/content/usecases/KeymapUseCase.test.ts107
1 files changed, 53 insertions, 54 deletions
diff --git a/test/content/usecases/KeymapUseCase.test.ts b/test/content/usecases/KeymapUseCase.test.ts
index 24ac6d8..7af3ab2 100644
--- a/test/content/usecases/KeymapUseCase.test.ts
+++ b/test/content/usecases/KeymapUseCase.test.ts
@@ -1,6 +1,5 @@
import "reflect-metadata";
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";
@@ -41,7 +40,7 @@ class MockAddressRepository implements AddressRepository {
}
describe("KeymapUseCase", () => {
- context("with no-digis keymaps", () => {
+ describe("with no-digis keymaps", () => {
const settings = Settings.fromJSON({
keymaps: {
k: { type: "scroll.vertically", count: -1 },
@@ -52,7 +51,7 @@ describe("KeymapUseCase", () => {
let sut: KeymapUseCase;
- before(() => {
+ beforeEach(() => {
sut = new KeymapUseCase(
new KeymapRepositoryImpl(),
new MockSettingRepository(settings),
@@ -62,34 +61,34 @@ describe("KeymapUseCase", () => {
});
it("returns matched operation", () => {
- expect(sut.nextOps(Key.fromMapKey("k"))).to.deep.equal({
+ expect(sut.nextOps(Key.fromMapKey("k"))).toEqual({
repeat: 1,
op: { type: "scroll.vertically", count: -1 },
});
- expect(sut.nextOps(Key.fromMapKey("j"))).to.deep.equal({
+ expect(sut.nextOps(Key.fromMapKey("j"))).toEqual({
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({
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({
repeat: 1,
op: { type: "scroll.top" },
});
- expect(sut.nextOps(Key.fromMapKey("z"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("z"))).toBeNull;
});
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({
+ expect(sut.nextOps(Key.fromMapKey("1"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("0"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({
repeat: 10,
op: { type: "scroll.top" },
});
});
});
- context("when keymaps containing numeric mappings", () => {
+ describe("when keymaps containing numeric mappings", () => {
const settings = Settings.fromJSON({
keymaps: {
20: { type: "scroll.top" },
@@ -99,7 +98,7 @@ describe("KeymapUseCase", () => {
let sut: KeymapUseCase;
- before(() => {
+ beforeEach(() => {
sut = new KeymapUseCase(
new KeymapRepositoryImpl(),
new MockSettingRepository(settings),
@@ -109,43 +108,43 @@ describe("KeymapUseCase", () => {
});
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({
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("5"))).toEqual({
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({
+ expect(sut.nextOps(Key.fromMapKey("2"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("0"))).toEqual({
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({
+ expect(sut.nextOps(Key.fromMapKey("2"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("5"))).toEqual({
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({
+ expect(sut.nextOps(Key.fromMapKey("3"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("2"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("0"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("5"))).toEqual({
repeat: 320,
op: { type: "scroll.bottom" },
});
});
});
- context("when the keys are mismatched with the operations", () => {
+ describe("when the keys are mismatched with the operations", () => {
const settings = Settings.fromJSON({
keymaps: {
gg: { type: "scroll.top" },
@@ -155,7 +154,7 @@ describe("KeymapUseCase", () => {
let sut: KeymapUseCase;
- before(() => {
+ beforeEach(() => {
sut = new KeymapUseCase(
new KeymapRepositoryImpl(),
new MockSettingRepository(settings),
@@ -165,31 +164,31 @@ describe("KeymapUseCase", () => {
});
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({
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("x"))).toBeNull; // clear
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({
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({
+ expect(sut.nextOps(Key.fromMapKey("1"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("0"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("x"))).toBeNull; // clear
+ expect(sut.nextOps(Key.fromMapKey("1"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("0"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({
repeat: 10,
op: { type: "scroll.top" },
});
});
});
- context("when the site matches to the blacklist", () => {
+ describe("when the site matches to the blacklist", () => {
const settings = Settings.fromJSON({
keymaps: {
k: { type: "scroll.vertically", count: -1 },
@@ -200,7 +199,7 @@ describe("KeymapUseCase", () => {
let sut: KeymapUseCase;
- before(() => {
+ beforeEach(() => {
sut = new KeymapUseCase(
new KeymapRepositoryImpl(),
new MockSettingRepository(settings),
@@ -210,19 +209,19 @@ describe("KeymapUseCase", () => {
});
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({
+ expect(sut.nextOps(Key.fromMapKey("k"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("a"))).toEqual({
repeat: 1,
op: { type: "addon.enable" },
});
- expect(sut.nextOps(Key.fromMapKey("b"))).to.deep.equal({
+ expect(sut.nextOps(Key.fromMapKey("b"))).toEqual({
repeat: 1,
op: { type: "addon.toggle.enabled" },
});
});
});
- context("when the site matches to the partial blacklist", () => {
+ describe("when the site matches to the partial blacklist", () => {
const settings = Settings.fromJSON({
keymaps: {
k: { type: "scroll.vertically", count: -1 },
@@ -244,17 +243,17 @@ describe("KeymapUseCase", () => {
new MockAddressRepository(new URL("https://example.com"))
);
- expect(sut.nextOps(Key.fromMapKey("k"))).to.deep.equal({
+ expect(sut.nextOps(Key.fromMapKey("k"))).toEqual({
repeat: 1,
op: { type: "scroll.vertically", count: -1 },
});
- expect(sut.nextOps(Key.fromMapKey("j"))).to.deep.equal({
+ expect(sut.nextOps(Key.fromMapKey("j"))).toEqual({
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({
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("G"))).toEqual({
repeat: 1,
op: { type: "scroll.bottom" },
});
@@ -266,12 +265,12 @@ describe("KeymapUseCase", () => {
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({
+ expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull;
+ expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({
repeat: 1,
op: { type: "scroll.top" },
});
- expect(sut.nextOps(Key.fromMapKey("G"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("G"))).toBeNull;
});
});
});