From 493ffc83b01bfbae5f84c66f4db0cc4e1f90a588 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 6 Dec 2019 22:49:04 +0900 Subject: Repeat content operation with a numeric prefix --- test/content/usecases/KeymapUseCase.test.ts | 204 +++++++++++++++++++++------- 1 file changed, 155 insertions(+), 49 deletions(-) (limited to 'test/content/usecases') diff --git a/test/content/usecases/KeymapUseCase.test.ts b/test/content/usecases/KeymapUseCase.test.ts index 5f2feba..9fced9c 100644 --- a/test/content/usecases/KeymapUseCase.test.ts +++ b/test/content/usecases/KeymapUseCase.test.ts @@ -1,3 +1,4 @@ +import "reflect-metadata"; import KeymapUseCase from '../../../src/content/usecases/KeymapUseCase'; import {expect} from 'chai'; import SettingRepository from "../../../src/content/repositories/SettingRepository"; @@ -50,7 +51,7 @@ class MockAddressRepository implements AddressRepository { describe('KeymapUseCase', () => { - it('returns matched operation', () => { + context('with no-digis keymaps', () => { let settings = Settings.fromJSON({ keymaps: { k: {type: 'scroll.vertically', count: -1}, @@ -58,21 +59,117 @@ describe('KeymapUseCase', () => { gg: {type: 'scroll.top'}, }, }); - let sut = new KeymapUseCase( - new KeymapRepositoryImpl(), - new MockSettingRepository(settings), - new MockAddonEnabledRepository(true), - new MockAddressRepository(new URL('https://example.com')), - ); - - expect(sut.nextOp(Key.fromMapKey('k'))).to.deep.equal({type: 'scroll.vertically', count: -1}); - expect(sut.nextOp(Key.fromMapKey('j'))).to.deep.equal({type: 'scroll.vertically', count: 1}); - expect(sut.nextOp(Key.fromMapKey('g'))).to.be.null; - expect(sut.nextOp(Key.fromMapKey('g'))).to.deep.equal({type: 'scroll.top'}); - expect(sut.nextOp(Key.fromMapKey('z'))).to.be.null; + + let sut: KeymapUseCase; + + before(() => { + sut = new KeymapUseCase( + 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([{type: 'scroll.vertically', count: -1}]); + expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal([{type: 'scroll.vertically', count: 1}]); + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal([{type: 'scroll.top'}]); + expect(sut.nextOps(Key.fromMapKey('z'))).to.be.empty; + }); + + it('repeats n-times by numeric prefix and multiple key operations', () => { + expect(sut.nextOps(Key.fromMapKey('1'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('0'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal(Array(10).fill({type: "scroll.top"})); + }); + }); + + context('when keymaps containing numeric mappings', () => { + let settings = Settings.fromJSON({ + keymaps: { + 20: {type: "scroll.top"}, + g5: {type: 'scroll.bottom'}, + }, + }); + + let sut: KeymapUseCase; + + before(() => { + sut = new KeymapUseCase( + 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.empty; + expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal([{ type: 'scroll.bottom'}]); + }); + + it('returns an operation matched the operation with digit keymaps', () => { + expect(sut.nextOps(Key.fromMapKey('2'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('0'))).to.be.deep.equal([{ type: 'scroll.top'}]); + }); + + it('returns operations repeated by numeric prefix', () => { + expect(sut.nextOps(Key.fromMapKey('2'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal(Array(2).fill({ type: 'scroll.bottom'})); + }); + + it('does not matches with digit operation with numeric prefix', () => { + expect(sut.nextOps(Key.fromMapKey('3'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('2'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('0'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal(Array(320).fill({ type: 'scroll.bottom'})); + }); }); - it('returns only ADDON_ENABLE and ADDON_TOGGLE_ENABLED operation', () => { + context('when the keys are mismatched with the operations', () => { + let settings = Settings.fromJSON({ + keymaps: { + gg: {type: "scroll.top"}, + G: {type: "scroll.bottom"}, + }, + }); + + let sut: KeymapUseCase; + + before(() => { + sut = new KeymapUseCase( + 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.empty; + expect(sut.nextOps(Key.fromMapKey('x'))).to.be.empty; // clear + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal([{type: "scroll.top"}]); + }); + + it('clears input keys and the prefix with no-matched operations', () => { + expect(sut.nextOps(Key.fromMapKey('1'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('0'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('x'))).to.be.empty; // clear + expect(sut.nextOps(Key.fromMapKey('1'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('0'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal(Array(10).fill({type: "scroll.top"})); + }); + }); + + context('when the site matches to the blacklist', () => { let settings = Settings.fromJSON({ keymaps: { k: {type: 'scroll.vertically', count: -1}, @@ -80,25 +177,32 @@ describe('KeymapUseCase', () => { b: {type: 'addon.toggle.enabled'}, }, }); - let sut = new KeymapUseCase( - new KeymapRepositoryImpl(), - new MockSettingRepository(settings), - new MockAddonEnabledRepository(false), - new MockAddressRepository(new URL('https://example.com')), - ); - expect(sut.nextOp(Key.fromMapKey('k'))).to.be.null; - expect(sut.nextOp(Key.fromMapKey('a'))).to.deep.equal({type: 'addon.enable'}); - expect(sut.nextOp(Key.fromMapKey('b'))).to.deep.equal({type: 'addon.toggle.enabled'}); + let sut: KeymapUseCase; + + before(() => { + sut = new KeymapUseCase( + 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.empty; + expect(sut.nextOps(Key.fromMapKey('a'))).to.deep.equal([{type: 'addon.enable'}]); + expect(sut.nextOps(Key.fromMapKey('b'))).to.deep.equal([{type: 'addon.toggle.enabled'}]); + }); }); - it('blocks keys in the partial blacklist', () => { + context('when the site matches to the partial blacklist', () => { let settings = Settings.fromJSON({ keymaps: { k: {type: 'scroll.vertically', count: -1}, j: {type: 'scroll.vertically', count: 1}, - gg: {"type": "scroll.top"}, - G: {"type": "scroll.bottom"}, + gg: {type: "scroll.top"}, + G: {type: "scroll.bottom"}, }, blacklist: [ { url: "example.com", keys: ['g'] }, @@ -106,28 +210,30 @@ describe('KeymapUseCase', () => { ], }); - let sut = new KeymapUseCase( - new KeymapRepositoryImpl(), - new MockSettingRepository(settings), - new MockAddonEnabledRepository(true), - new MockAddressRepository(new URL('https://example.com')), - ); - - expect(sut.nextOp(Key.fromMapKey('k'))).to.deep.equal({type: 'scroll.vertically', count: -1}); - expect(sut.nextOp(Key.fromMapKey('j'))).to.deep.equal({type: 'scroll.vertically', count: 1}); - expect(sut.nextOp(Key.fromMapKey('g'))).to.be.null; - expect(sut.nextOp(Key.fromMapKey('g'))).to.be.null; - expect(sut.nextOp(Key.fromMapKey('G'))).to.deep.equal({type: 'scroll.bottom'}); - - sut = new KeymapUseCase( - new KeymapRepositoryImpl(), - new MockSettingRepository(settings), - new MockAddonEnabledRepository(true), - new MockAddressRepository(new URL('https://example.org')), - ); - - expect(sut.nextOp(Key.fromMapKey('g'))).to.be.null; - expect(sut.nextOp(Key.fromMapKey('g'))).to.deep.equal({type: 'scroll.top'}); - expect(sut.nextOp(Key.fromMapKey('G'))).to.be.null; + 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')), + ); + + expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal([{type: 'scroll.vertically', count: -1}]); + expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal([{type: 'scroll.vertically', count: 1}]); + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('G'))).to.deep.equal([{type: 'scroll.bottom'}]); + + sut = new KeymapUseCase( + new KeymapRepositoryImpl(), + new MockSettingRepository(settings), + new MockAddonEnabledRepository(true), + new MockAddressRepository(new URL('https://example.org')), + ); + + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal([{type: 'scroll.top'}]); + expect(sut.nextOps(Key.fromMapKey('G'))).to.be.empty; + }); }); }); -- cgit v1.2.3 From d05f1ad554551919f8c603d335df578674752b06 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 21 Dec 2019 17:45:21 +0900 Subject: Fix KeymapUseCase test --- test/content/usecases/KeymapUseCase.test.ts | 88 ++++++++++++++--------------- 1 file changed, 44 insertions(+), 44 deletions(-) (limited to 'test/content/usecases') diff --git a/test/content/usecases/KeymapUseCase.test.ts b/test/content/usecases/KeymapUseCase.test.ts index 9fced9c..904a180 100644 --- a/test/content/usecases/KeymapUseCase.test.ts +++ b/test/content/usecases/KeymapUseCase.test.ts @@ -72,18 +72,18 @@ describe('KeymapUseCase', () => { }); it('returns matched operation', () => { - expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal([{type: 'scroll.vertically', count: -1}]); - expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal([{type: 'scroll.vertically', count: 1}]); - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal([{type: 'scroll.top'}]); - expect(sut.nextOps(Key.fromMapKey('z'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal({ count: 1, op: {type: 'scroll.vertically', count: -1}}); + expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal({ count: 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({ count: 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.empty; - expect(sut.nextOps(Key.fromMapKey('0'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal(Array(10).fill({type: "scroll.top"})); + 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({ count: 10, op: {type: "scroll.top"}}); }); }); @@ -107,27 +107,27 @@ describe('KeymapUseCase', () => { }); it('returns the matched operation ends with digit', () => { - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal([{ type: 'scroll.bottom'}]); + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null; + expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal({ count: 1, op: { type: 'scroll.bottom'}}); }); it('returns an operation matched the operation with digit keymaps', () => { - expect(sut.nextOps(Key.fromMapKey('2'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('0'))).to.be.deep.equal([{ type: 'scroll.top'}]); + expect(sut.nextOps(Key.fromMapKey('2'))).to.be.null; + expect(sut.nextOps(Key.fromMapKey('0'))).to.be.deep.equal({ count: 1, op: { type: 'scroll.top'}}); }); it('returns operations repeated by numeric prefix', () => { - expect(sut.nextOps(Key.fromMapKey('2'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal(Array(2).fill({ type: 'scroll.bottom'})); + 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({ count: 2, op: { type: 'scroll.bottom'}}); }); it('does not matches with digit operation with numeric prefix', () => { - expect(sut.nextOps(Key.fromMapKey('3'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('2'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('0'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal(Array(320).fill({ type: 'scroll.bottom'})); + 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({ count: 320, op: { type: 'scroll.bottom'}}); }); }); @@ -151,21 +151,21 @@ describe('KeymapUseCase', () => { }); it('clears input keys with no-matched operations', () => { - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('x'))).to.be.empty; // clear - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal([{type: "scroll.top"}]); + 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({count: 1, op: {type: "scroll.top"}}); }); it('clears input keys and the prefix with no-matched operations', () => { - expect(sut.nextOps(Key.fromMapKey('1'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('0'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('x'))).to.be.empty; // clear - expect(sut.nextOps(Key.fromMapKey('1'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('0'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal(Array(10).fill({type: "scroll.top"})); + 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({ count: 10, op: {type: "scroll.top"}}); }); }); @@ -190,9 +190,9 @@ describe('KeymapUseCase', () => { }); it('returns only ADDON_ENABLE and ADDON_TOGGLE_ENABLED operation', () => { - expect(sut.nextOps(Key.fromMapKey('k'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('a'))).to.deep.equal([{type: 'addon.enable'}]); - expect(sut.nextOps(Key.fromMapKey('b'))).to.deep.equal([{type: 'addon.toggle.enabled'}]); + expect(sut.nextOps(Key.fromMapKey('k'))).to.be.null; + expect(sut.nextOps(Key.fromMapKey('a'))).to.deep.equal({ count: 1, op: {type: 'addon.enable'}}); + expect(sut.nextOps(Key.fromMapKey('b'))).to.deep.equal({ count: 1, op: {type: 'addon.toggle.enabled'}}); }); }); @@ -218,11 +218,11 @@ describe('KeymapUseCase', () => { new MockAddressRepository(new URL('https://example.com')), ); - expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal([{type: 'scroll.vertically', count: -1}]); - expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal([{type: 'scroll.vertically', count: 1}]); - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('G'))).to.deep.equal([{type: 'scroll.bottom'}]); + expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal({ count: 1, op: {type: 'scroll.vertically', count: -1}}); + expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal({ count: 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({ count: 1, op: {type: 'scroll.bottom'}}); sut = new KeymapUseCase( new KeymapRepositoryImpl(), @@ -231,9 +231,9 @@ describe('KeymapUseCase', () => { new MockAddressRepository(new URL('https://example.org')), ); - expect(sut.nextOps(Key.fromMapKey('g'))).to.be.empty; - expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal([{type: 'scroll.top'}]); - expect(sut.nextOps(Key.fromMapKey('G'))).to.be.empty; + expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null; + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ count: 1, op: {type: 'scroll.top'}}); + expect(sut.nextOps(Key.fromMapKey('G'))).to.be.null; }); }); }); -- cgit v1.2.3 From 5963b91cbdf880e1f10b77146d3be5775f0920c0 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 21 Dec 2019 17:51:48 +0900 Subject: Rename count to repeat --- src/background/controllers/OperationController.ts | 8 +++--- .../infrastructures/ContentMessageListener.ts | 2 +- src/content/client/OperationClient.ts | 8 +++--- src/content/controllers/KeymapController.ts | 6 ++-- src/content/usecases/KeymapUseCase.ts | 6 ++-- src/shared/messages.ts | 2 +- test/content/usecases/KeymapUseCase.test.ts | 32 +++++++++++----------- 7 files changed, 32 insertions(+), 32 deletions(-) (limited to 'test/content/usecases') diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index 69b45c3..2f5d4a6 100644 --- a/src/background/controllers/OperationController.ts +++ b/src/background/controllers/OperationController.ts @@ -21,8 +21,8 @@ export default class OperationController { ) { } - async exec(count: number, op: operations.Operation): Promise { - await this.doOperation(count, op); + async exec(repeat: number, op: operations.Operation): Promise { + await this.doOperation(repeat, op); if (this.repeatUseCase.isRepeatable(op)) { this.repeatUseCase.storeLastOperation(op); } @@ -30,7 +30,7 @@ export default class OperationController { // eslint-disable-next-line complexity, max-lines-per-function async doOperation( - count: number, + repeat: number, operation: operations.Operation, ): Promise { // eslint-disable-next-line complexity, max-lines-per-function @@ -119,7 +119,7 @@ export default class OperationController { } })(); - for (let i = 0; i < count; ++i) { + for (let i = 0; i < repeat; ++i) { // eslint-disable-next-line no-await-in-loop await opFunc(); } diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts index 51a9f82..f20340b 100644 --- a/src/background/infrastructures/ContentMessageListener.ts +++ b/src/background/infrastructures/ContentMessageListener.ts @@ -80,7 +80,7 @@ export default class ContentMessageListener { senderTab.id as number, message.background); case messages.BACKGROUND_OPERATION: - return this.onBackgroundOperation(message.count, message.operation); + return this.onBackgroundOperation(message.repeat, message.operation); case messages.MARK_SET_GLOBAL: return this.onMarkSetGlobal(message.key, message.x, message.y); case messages.MARK_JUMP_GLOBAL: diff --git a/src/content/client/OperationClient.ts b/src/content/client/OperationClient.ts index 06077dc..9c72c75 100644 --- a/src/content/client/OperationClient.ts +++ b/src/content/client/OperationClient.ts @@ -2,7 +2,7 @@ import * as operations from '../../shared/operations'; import * as messages from '../../shared/messages'; export default interface OperationClient { - execBackgroundOp(count: number, op: operations.Operation): Promise; + execBackgroundOp(repeat: number, op: operations.Operation): Promise; internalOpenUrl( url: string, newTab?: boolean, background?: boolean, @@ -10,10 +10,10 @@ export default interface OperationClient { } export class OperationClientImpl implements OperationClient { - execBackgroundOp(count: number, op: operations.Operation): Promise { + execBackgroundOp(repeat: number, op: operations.Operation): Promise { return browser.runtime.sendMessage({ type: messages.BACKGROUND_OPERATION, - count, + repeat, operation: op, }); } @@ -23,7 +23,7 @@ export class OperationClientImpl implements OperationClient { ): Promise { return browser.runtime.sendMessage({ type: messages.BACKGROUND_OPERATION, - count: 1, + repeat: 1, operation: { type: operations.INTERNAL_OPEN_URL, url, diff --git a/src/content/controllers/KeymapController.ts b/src/content/controllers/KeymapController.ts index b8069f9..452e3d4 100644 --- a/src/content/controllers/KeymapController.ts +++ b/src/content/controllers/KeymapController.ts @@ -38,7 +38,7 @@ export default class KeymapController { } if (!operations.isNRepeatable(nextOp.op.type)) { - nextOp.count = 1; + nextOp.repeat = 1; } const doFunc = ((op: operations.Operation) => { @@ -91,9 +91,9 @@ export default class KeymapController { // Do not await asynchronous methods to return a boolean immidiately. The // caller requires the synchronous response from the callback to identify // to continue of abandon the event propagations. - this.operationClient.execBackgroundOp(nextOp.count, nextOp.op); + this.operationClient.execBackgroundOp(nextOp.repeat, nextOp.op); } else { - for (let i = 0; i < nextOp.count; ++i) { + for (let i = 0; i < nextOp.repeat; ++i) { doFunc(); } } diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index fab13f5..a2e7cc3 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -36,7 +36,7 @@ export default class KeymapUseCase { } // eslint-disable-next-line max-statements - nextOps(key: Key): { count: number, op: operations.Operation } | null { + nextOps(key: Key): { repeat: number, op: operations.Operation } | null { let sequence = this.repository.enqueueKey(key); let baseSequence = sequence.trimNumericPrefix(); if (baseSequence.length() === 1 && this.blacklistKey(key)) { @@ -53,13 +53,13 @@ export default class KeymapUseCase { sequence.length() === matched[0][0].length()) { // keys are matched with an operation this.repository.clear(); - return { count: 1, op: matched[0][1] }; + return { repeat: 1, op: matched[0][1] }; } else if ( baseMatched.length === 1 && baseSequence.length() === baseMatched[0][0].length()) { // keys are matched with an operation with a numeric prefix this.repository.clear(); - return { count: sequence.repeatCount(), op: baseMatched[0][1] }; + return { repeat: sequence.repeatCount(), op: baseMatched[0][1] }; } else if (matched.length >= 1 || baseMatched.length >= 1) { // keys are matched with an operation's prefix return null; diff --git a/src/shared/messages.ts b/src/shared/messages.ts index 8032109..7f8bd5b 100644 --- a/src/shared/messages.ts +++ b/src/shared/messages.ts @@ -49,7 +49,7 @@ export const NAVIGATE_LINK_PREV = 'navigate.link.prev'; export interface BackgroundOperationMessage { type: typeof BACKGROUND_OPERATION; - count: number; + repeat: number; operation: operations.Operation; } diff --git a/test/content/usecases/KeymapUseCase.test.ts b/test/content/usecases/KeymapUseCase.test.ts index 904a180..598d5a3 100644 --- a/test/content/usecases/KeymapUseCase.test.ts +++ b/test/content/usecases/KeymapUseCase.test.ts @@ -72,10 +72,10 @@ describe('KeymapUseCase', () => { }); it('returns matched operation', () => { - expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal({ count: 1, op: {type: 'scroll.vertically', count: -1}}); - expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal({ count: 1, op: {type: 'scroll.vertically', count: 1}}); + 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({ count: 1, op: {type: 'scroll.top'}}); + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.top'}}); expect(sut.nextOps(Key.fromMapKey('z'))).to.be.null; }); @@ -83,7 +83,7 @@ describe('KeymapUseCase', () => { 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({ count: 10, op: {type: "scroll.top"}}); + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 10, op: {type: "scroll.top"}}); }); }); @@ -108,18 +108,18 @@ 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({ count: 1, op: { type: 'scroll.bottom'}}); + 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({ count: 1, op: { type: 'scroll.top'}}); + 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({ count: 2, op: { type: 'scroll.bottom'}}); + 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', () => { @@ -127,7 +127,7 @@ describe('KeymapUseCase', () => { 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({ count: 320, op: { type: 'scroll.bottom'}}); + expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal({ repeat: 320, op: { type: 'scroll.bottom'}}); }); }); @@ -154,7 +154,7 @@ describe('KeymapUseCase', () => { 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({count: 1, op: {type: "scroll.top"}}); + 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', () => { @@ -165,7 +165,7 @@ describe('KeymapUseCase', () => { 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({ count: 10, op: {type: "scroll.top"}}); + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 10, op: {type: "scroll.top"}}); }); }); @@ -191,8 +191,8 @@ 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({ count: 1, op: {type: 'addon.enable'}}); - expect(sut.nextOps(Key.fromMapKey('b'))).to.deep.equal({ count: 1, op: {type: 'addon.toggle.enabled'}}); + 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'}}); }); }); @@ -218,11 +218,11 @@ describe('KeymapUseCase', () => { new MockAddressRepository(new URL('https://example.com')), ); - expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal({ count: 1, op: {type: 'scroll.vertically', count: -1}}); - expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal({ count: 1, op: {type: 'scroll.vertically', count: 1}}); + 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({ count: 1, op: {type: 'scroll.bottom'}}); + expect(sut.nextOps(Key.fromMapKey('G'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.bottom'}}); sut = new KeymapUseCase( new KeymapRepositoryImpl(), @@ -232,7 +232,7 @@ describe('KeymapUseCase', () => { ); expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null; - expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ count: 1, op: {type: 'scroll.top'}}); + expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.top'}}); expect(sut.nextOps(Key.fromMapKey('G'))).to.be.null; }); }); -- cgit v1.2.3