fix(cloudcmd) directoryStorage

This commit is contained in:
coderaiser 2020-03-31 12:27:16 +03:00
parent 12e813c432
commit 2d08fb98b7
4 changed files with 96 additions and 15 deletions

View file

@ -472,6 +472,7 @@ function CloudCmdProto(DOM) {
const owner = DOM.getCurrentOwner(current);
const mode = DOM.getCurrentMode(current);
const date = DOM.getCurrentDate(current);
const type = DOM.getCurrentType(current);
return {
name,
@ -479,6 +480,7 @@ function CloudCmdProto(DOM) {
mode,
owner,
date,
type,
};
};

View file

@ -280,3 +280,23 @@ module.exports.setTitle = (name) => {
return DOM;
};
/**
* check is current file is a directory
*
* @param currentFile
*/
module.exports.isCurrentIsDir = (currentFile) => {
const current = currentFile || DOM.getCurrentFile();
const fileType = DOM.getCurrentType(current);
return DOM.isContainClass(fileType, [
'directory',
'directory-link',
]);
};
module.exports.getCurrentType = (currentFile) => {
const current = currentFile || DOM.getCurrentFile();
return DOM.getByDataName('js-type', current);
};

View file

@ -168,6 +168,78 @@ test('current-file: isCurrentFile', (t) => {
t.end();
});
test('current-file: getCurrentType', (t) => {
const {
DOM,
CloudCmd,
} = global;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
const {getByDataName} = global.DOM;
const current = create();
currentFile.getCurrentType(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
t.ok(getByDataName.calledWith('js-type', current));
t.end();
});
test('current-file: isCurrentIsDir: getCurrentType', (t) => {
const {
DOM,
CloudCmd,
} = global;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
const {getCurrentType} = global.DOM;
const current = create();
currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
t.ok(getCurrentType.calledWith(current));
t.end();
});
test('current-file: isCurrentIsDir: isContainClass', (t) => {
const {
DOM,
CloudCmd,
} = global;
global.DOM = getDOM({
getCurrentType: stub().returns('file'),
});
global.CloudCmd = getCloudCmd();
const {isContainClass} = global.DOM;
const current = create();
currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
t.ok(isContainClass.calledWith('file', [
'directory',
'directory-link',
]));
t.end();
});
function getCloudCmd({emit} = {}) {
return {
prefix: '',
@ -181,12 +253,14 @@ function getDOM({
getCurrentDirName = stub(),
getByDataName = stub(),
isContainClass = stub(),
getCurrentType = stub(),
} = {}) {
return {
getCurrentDirPath,
getCurrentDirName,
getByDataName,
isContainClass,
getCurrentType,
CurrentInfo: {
link,
dirPath: '/',

View file

@ -462,21 +462,6 @@ function CmdProto() {
return DOM.isContainClass(selected, SELECTED_FILE);
};
/**
* check is current file is a directory
*
* @param currentFile
*/
this.isCurrentIsDir = (currentFile) => {
const current = currentFile || DOM.getCurrentFile();
const fileType = DOM.getByDataName('js-type', current);
return DOM.isContainClass(fileType, [
'directory',
'directory-link',
]);
};
/**
* get link from current (or param) file
*