feature: client: improve testability

This commit is contained in:
coderiaser 2026-01-16 19:12:24 +02:00
parent f75bf4a401
commit 450f14614d
2 changed files with 22 additions and 11 deletions

View file

@ -12,7 +12,7 @@ const {
const {DOM = {}, CloudCmd = {},
} = globalThis;
const {Dialog} = DOM;
const {Dialog = {}} = DOM;
const DEPS = {
...DOM,
@ -21,7 +21,7 @@ const DEPS = {
module.exports = async (key, event, deps = DEPS) => {
const operations = getOperations(event, deps);
await vim(key, operations);
await vim(key, operations, deps);
};
const getOperations = (event, deps) => {
@ -32,6 +32,8 @@ const getOperations = (event, deps) => {
setCurrentFile,
setCurrentByName,
getCurrentName,
prompt = Dialog.prompt,
preventDefault = event?.preventDefault?.bind(event),
toggleSelectedFile,
Buffer = {},
@ -103,8 +105,8 @@ const getOperations = (event, deps) => {
},
find: async () => {
event.preventDefault();
const [, value] = await Dialog.prompt('Find', '');
preventDefault();
const [, value] = await prompt('Find', '');
if (!value)
return;

View file

@ -13,7 +13,7 @@ const {getDOM, getCloudCmd} = require('./globals.fixture');
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const vim = require(pathVim);
const vim = require('./index.js');
const {assign} = Object;
const {DOM} = globalThis;
@ -517,18 +517,27 @@ test('cloudcmd: client: key: Enter', async (t) => {
t.end();
});
test.skip('cloudcmd: client: key: /', (t) => {
test('cloudcmd: client: key: /', (t) => {
const preventDefault = stub();
const element = {};
const Info = {
element,
files: [],
};
DOM.CurrentInfo.element = element;
DOM.getCurrentName = () => '';
vim('/', {
const getCurrentName = stub().returns('');
const event = {
preventDefault,
};
const prompt = stub().returns([]);
vim('/', event, {
getCurrentName,
Info,
prompt,
});
t.calledWithNoArgs(preventDefault, 'should call preventDefault');
t.calledWithNoArgs(preventDefault);
t.end();
});