mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test: client: dom: operations: rename-current: get rid of mock-require
This commit is contained in:
parent
14452d05b6
commit
c231fca334
2 changed files with 35 additions and 37 deletions
|
|
@ -3,21 +3,29 @@
|
|||
/* global CloudCmd */
|
||||
const capitalize = require('just-capitalize');
|
||||
|
||||
const Dialog = require('../dialog');
|
||||
const _Dialog = require('../dialog');
|
||||
const Storage = require('../storage');
|
||||
const RESTful = require('../rest');
|
||||
|
||||
const {
|
||||
isCurrentFile,
|
||||
getCurrentName,
|
||||
getCurrentFile,
|
||||
getCurrentByName,
|
||||
getCurrentType,
|
||||
getCurrentDirPath,
|
||||
setCurrentName,
|
||||
} = require('../current-file');
|
||||
const _currentFile = require('../current-file');
|
||||
|
||||
module.exports = async (current) => {
|
||||
module.exports = async (current, overrides = {}) => {
|
||||
const {
|
||||
refresh = CloudCmd.refresh,
|
||||
Dialog = _Dialog,
|
||||
currentFile = _currentFile,
|
||||
} = overrides;
|
||||
|
||||
const {
|
||||
isCurrentFile,
|
||||
getCurrentName,
|
||||
getCurrentFile,
|
||||
getCurrentByName,
|
||||
getCurrentType,
|
||||
getCurrentDirPath,
|
||||
setCurrentName,
|
||||
} = currentFile;
|
||||
|
||||
if (!isCurrentFile(current))
|
||||
current = getCurrentFile();
|
||||
|
||||
|
|
@ -58,5 +66,5 @@ module.exports = async (current) => {
|
|||
setCurrentName(to, current);
|
||||
|
||||
Storage.remove(dirPath);
|
||||
CloudCmd.refresh();
|
||||
refresh();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,23 +2,20 @@
|
|||
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const mockRequire = require('mock-require');
|
||||
|
||||
const {reRequire, stopAll} = mockRequire;
|
||||
const renameCurrent = require('./rename-current');
|
||||
|
||||
test('cloudcmd: client: dom: renameCurrent: isCurrentFile', async (t) => {
|
||||
const current = {};
|
||||
const isCurrentFile = stub();
|
||||
|
||||
mockRequire('../dialog', stubDialog());
|
||||
mockRequire('../current-file', stubCurrentFile({
|
||||
const currentFile = stubCurrentFile({
|
||||
isCurrentFile,
|
||||
}));
|
||||
});
|
||||
|
||||
const renameCurrent = reRequire('./rename-current');
|
||||
await renameCurrent(current);
|
||||
|
||||
stopAll();
|
||||
await renameCurrent(current, {
|
||||
Dialog: stubDialog(),
|
||||
currentFile,
|
||||
});
|
||||
|
||||
t.calledWith(isCurrentFile, [current], 'should call isCurrentFile');
|
||||
t.end();
|
||||
|
|
@ -27,11 +24,6 @@ test('cloudcmd: client: dom: renameCurrent: isCurrentFile', async (t) => {
|
|||
test('cloudcmd: client: dom: renameCurrent: file exist', async (t) => {
|
||||
const current = {};
|
||||
const name = 'hello';
|
||||
const {CloudCmd} = global;
|
||||
|
||||
global.CloudCmd = {
|
||||
refresh: stub(),
|
||||
};
|
||||
|
||||
const prompt = stub().returns([null, name]);
|
||||
const confirm = stub().returns([true]);
|
||||
|
|
@ -39,25 +31,23 @@ test('cloudcmd: client: dom: renameCurrent: file exist', async (t) => {
|
|||
const getCurrentByName = stub().returns(current);
|
||||
const getCurrentType = stub().returns('directory');
|
||||
|
||||
mockRequire('../dialog', stubDialog({
|
||||
const Dialog = stubDialog({
|
||||
confirm,
|
||||
prompt,
|
||||
}));
|
||||
});
|
||||
|
||||
mockRequire('../current-file', stubCurrentFile({
|
||||
const currentFile = stubCurrentFile({
|
||||
getCurrentByName,
|
||||
getCurrentType,
|
||||
}));
|
||||
});
|
||||
|
||||
const renameCurrent = reRequire('./rename-current');
|
||||
await renameCurrent();
|
||||
await renameCurrent(null, {
|
||||
Dialog,
|
||||
currentFile,
|
||||
});
|
||||
|
||||
const expected = 'Directory "hello" already exists. Proceed?';
|
||||
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
||||
stopAll();
|
||||
|
||||
t.calledWith(confirm, [expected], 'should call confirm');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue