mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test: client: dom: goTiDirectory: get rid of mock-require
This commit is contained in:
parent
5cc6f79d6a
commit
5b4bb90d61
2 changed files with 9 additions and 17 deletions
|
|
@ -729,17 +729,19 @@ module.exports.getPackerExt = (type) => {
|
|||
return '.tar.gz';
|
||||
};
|
||||
|
||||
module.exports.goToDirectory = async () => {
|
||||
const msg = 'Go to directory:';
|
||||
module.exports.goToDirectory = async (overrides = {}) => {
|
||||
const {Dialog} = DOM;
|
||||
const {prompt = Dialog.prompt, changeDir = CloudCmd.changeDir} = overrides;
|
||||
|
||||
const msg = 'Go to directory:';
|
||||
const {dirPath} = CurrentInfo;
|
||||
|
||||
const [cancel, path = dirPath] = await Dialog.prompt(msg, dirPath);
|
||||
const [cancel, path = dirPath] = await prompt(msg, dirPath);
|
||||
|
||||
if (cancel)
|
||||
return;
|
||||
|
||||
await CloudCmd.changeDir(path);
|
||||
await changeDir(path);
|
||||
};
|
||||
|
||||
module.exports.duplicatePanel = async () => {
|
||||
|
|
|
|||
|
|
@ -3,30 +3,20 @@
|
|||
require('css-modules-require-hook/preset');
|
||||
|
||||
const {test, stub} = require('supertape');
|
||||
const mockRequire = require('mock-require');
|
||||
const {getCSSVar} = require('./index');
|
||||
const {reRequire, stopAll} = mockRequire;
|
||||
const {getCSSVar, goToDirectory} = require('./index');
|
||||
|
||||
global.CloudCmd = {};
|
||||
|
||||
test('cloudcmd: client: dom: goToDirectory', async (t) => {
|
||||
const path = '';
|
||||
const {CloudCmd} = global;
|
||||
const changeDir = stub();
|
||||
const prompt = stub().returns([null, path]);
|
||||
|
||||
CloudCmd.changeDir = changeDir;
|
||||
|
||||
mockRequire('./dialog', {
|
||||
await goToDirectory({
|
||||
prompt,
|
||||
changeDir,
|
||||
});
|
||||
|
||||
const {goToDirectory} = reRequire('.');
|
||||
|
||||
await goToDirectory();
|
||||
|
||||
stopAll();
|
||||
|
||||
t.calledWith(changeDir, [path]);
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue