diff --git a/client/key/vim/index.js b/client/key/vim/index.js index ddfe49c3..707fe777 100644 --- a/client/key/vim/index.js +++ b/client/key/vim/index.js @@ -40,12 +40,16 @@ const getOperations = (event, deps) => { toggleSelectedFile, Buffer = {}, createFindNext = _createFindNext, + createFindPrevious = _createFindPrevious, } = deps; return { findNext: createFindNext({ setCurrentByName, }), + findPrevious: createFindPrevious({ + setCurrentByName, + }), escape: unselectFiles, remove: () => { @@ -122,16 +126,18 @@ const getOperations = (event, deps) => { setCurrentByName(result); }, - - findPrevious: () => { - const name = finder.findPrevious(); - setCurrentByName(name); - }, }; }; module.exports.selectFile = selectFileNotParent; +const _createFindPrevious = (overrides = {}) => () => { + const {setCurrentByName} = overrides; + const name = finder.findPrevious(); + + setCurrentByName(name); +}; + const _createFindNext = (overrides = {}) => () => { const {setCurrentByName} = overrides; const name = finder.findNext(); diff --git a/client/key/vim/index.spec.js b/client/key/vim/index.spec.js index 6fcad11e..57f40a49 100644 --- a/client/key/vim/index.spec.js +++ b/client/key/vim/index.spec.js @@ -2,7 +2,6 @@ const {join} = require('node:path'); const {test, stub} = require('supertape'); -const mockRequire = require('mock-require'); const dir = '../'; @@ -18,8 +17,8 @@ const vim = require('./index.js'); const {assign} = Object; const {DOM} = globalThis; const {Buffer} = DOM; -const pathFind = join(dir, 'vim', 'find'); -const {reRequire, stopAll} = mockRequire; + +const {reRequire, stopAll} = require('mock-require'); test('cloudcmd: client: key: set next file: no', (t) => { const element = {}; @@ -584,19 +583,14 @@ test('cloudcmd: client: key: n', (t) => { test('cloudcmd: client: key: N', (t) => { const findPrevious = stub(); - - mockRequire(pathFind, { - findPrevious, - }); - - const vim = reRequire(`${dir}vim`); + const createFindPrevious = stub().returns(findPrevious); const event = {}; - vim('N', event); + vim('N', event, { + createFindPrevious, + }); - stopAll(); - - t.calledWithNoArgs(findPrevious, 'should call findPrevious'); + t.calledWithNoArgs(findPrevious); t.end(); });