diff --git a/client/client.js b/client/client.js index b9e6bfce..1cd1a39d 100644 --- a/client/client.js +++ b/client/client.js @@ -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, }; }; diff --git a/client/dom/current-file.js b/client/dom/current-file.js index 568297a0..99fc6822 100644 --- a/client/dom/current-file.js +++ b/client/dom/current-file.js @@ -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); +}; + diff --git a/client/dom/current-file.spec.js b/client/dom/current-file.spec.js index e5995fa8..8b0c33f8 100644 --- a/client/dom/current-file.spec.js +++ b/client/dom/current-file.spec.js @@ -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: '/', diff --git a/client/dom/index.js b/client/dom/index.js index f50c6d26..f9b8d6aa 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -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 *