diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-12-06 22:49:04 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-12-13 22:09:15 +0900 |
commit | 493ffc83b01bfbae5f84c66f4db0cc4e1f90a588 (patch) | |
tree | 2c0ee8335abc6ba1d772c37ae09536d45312e953 /test/content/usecases | |
parent | 38a69e4ca319f9db3c54a5cb69cd5645f12369d5 (diff) |
Repeat content operation with a numeric prefix
Diffstat (limited to 'test/content/usecases')
-rw-r--r-- | test/content/usecases/KeymapUseCase.test.ts | 204 |
1 files changed, 155 insertions, 49 deletions
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; + }); }); }); |