Skip to content

Commit 450f146

Browse files
committed
feature: client: improve testability
1 parent f75bf4a commit 450f146

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

client/key/vim/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
const {DOM = {}, CloudCmd = {},
1313
} = globalThis;
1414

15-
const {Dialog} = DOM;
15+
const {Dialog = {}} = DOM;
1616

1717
const DEPS = {
1818
...DOM,
@@ -21,7 +21,7 @@ const DEPS = {
2121

2222
module.exports = async (key, event, deps = DEPS) => {
2323
const operations = getOperations(event, deps);
24-
await vim(key, operations);
24+
await vim(key, operations, deps);
2525
};
2626

2727
const getOperations = (event, deps) => {
@@ -32,6 +32,8 @@ const getOperations = (event, deps) => {
3232
setCurrentFile,
3333
setCurrentByName,
3434
getCurrentName,
35+
prompt = Dialog.prompt,
36+
preventDefault = event?.preventDefault?.bind(event),
3537

3638
toggleSelectedFile,
3739
Buffer = {},
@@ -103,8 +105,8 @@ const getOperations = (event, deps) => {
103105
},
104106

105107
find: async () => {
106-
event.preventDefault();
107-
const [, value] = await Dialog.prompt('Find', '');
108+
preventDefault();
109+
const [, value] = await prompt('Find', '');
108110

109111
if (!value)
110112
return;

client/key/vim/index.spec.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {getDOM, getCloudCmd} = require('./globals.fixture');
1313
globalThis.DOM = getDOM();
1414
globalThis.CloudCmd = getCloudCmd();
1515

16-
const vim = require(pathVim);
16+
const vim = require('./index.js');
1717

1818
const {assign} = Object;
1919
const {DOM} = globalThis;
@@ -517,18 +517,27 @@ test('cloudcmd: client: key: Enter', async (t) => {
517517
t.end();
518518
});
519519

520-
test.skip('cloudcmd: client: key: /', (t) => {
520+
test('cloudcmd: client: key: /', (t) => {
521521
const preventDefault = stub();
522522
const element = {};
523+
const Info = {
524+
element,
525+
files: [],
526+
};
523527

524-
DOM.CurrentInfo.element = element;
525-
DOM.getCurrentName = () => '';
526-
527-
vim('/', {
528+
const getCurrentName = stub().returns('');
529+
const event = {
528530
preventDefault,
531+
};
532+
const prompt = stub().returns([]);
533+
534+
vim('/', event, {
535+
getCurrentName,
536+
Info,
537+
prompt,
529538
});
530539

531-
t.calledWithNoArgs(preventDefault, 'should call preventDefault');
540+
t.calledWithNoArgs(preventDefault);
532541
t.end();
533542
});
534543

0 commit comments

Comments
 (0)