mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature: client: improve testability
This commit is contained in:
parent
f75bf4a401
commit
450f14614d
2 changed files with 22 additions and 11 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue