mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
fix(current-file) getParrentDirPath: path contains "+++"
This commit is contained in:
parent
550f76461e
commit
4118f90b6b
3 changed files with 41 additions and 9 deletions
|
|
@ -112,10 +112,10 @@ module.exports.getParentDirPath = (panel) => {
|
|||
const dirName = DOM.getCurrentDirName() + '/';
|
||||
const index = path.lastIndexOf(dirName);
|
||||
|
||||
if (path !== '/')
|
||||
return path.slice(0, index);
|
||||
if (path === '/')
|
||||
return path;
|
||||
|
||||
return path;
|
||||
return path.slice(0, index);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
const test = require('tape');
|
||||
const diff = require('sinon-called-with-diff');
|
||||
const sinon = diff(require('sinon'));
|
||||
const id = (a) => a;
|
||||
const wraptile = require('wraptile');
|
||||
const returns = wraptile(id);
|
||||
|
||||
const currentFile = require('./current-file');
|
||||
|
||||
|
|
@ -82,7 +85,7 @@ test('current-file: emit', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('current-file: return', (t) => {
|
||||
test('current-file: setCurrentName: return', (t) => {
|
||||
const {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
|
|
@ -111,6 +114,28 @@ test('current-file: return', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('current-file: getParentDirPath: result', (t) => {
|
||||
const {
|
||||
DOM,
|
||||
} = global;
|
||||
|
||||
const getCurrentDirPath = returns('/D/Films/+++favorite films/');
|
||||
const getCurrentDirName = returns('+++favorite films');
|
||||
|
||||
global.DOM = getDOM({
|
||||
getCurrentDirPath,
|
||||
getCurrentDirName,
|
||||
});
|
||||
|
||||
const result = currentFile.getParentDirPath();
|
||||
const expected = '/D/Films/';
|
||||
|
||||
global.DOM = DOM;
|
||||
|
||||
t.equal(result, expected, 'should return parent dir path');
|
||||
t.end();
|
||||
});
|
||||
|
||||
function getCloudCmd({emit} = {}) {
|
||||
return {
|
||||
PREFIX: '',
|
||||
|
|
@ -118,14 +143,20 @@ function getCloudCmd({emit} = {}) {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
function getDOM({link} = {}) {
|
||||
link = link || {};
|
||||
|
||||
function getDOM({
|
||||
link = {},
|
||||
getCurrentDirPath = sinon.stub(),
|
||||
getCurrentDirName = sinon.stub(),
|
||||
getByDataName = sinon.stub(),
|
||||
} = {}) {
|
||||
return {
|
||||
getCurrentDirPath,
|
||||
getCurrentDirName,
|
||||
getByDataName,
|
||||
CurrentInfo: {
|
||||
link,
|
||||
dirPath: '/',
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,9 +152,10 @@ function CmdProto() {
|
|||
this.getParentDirPath = (panel) => {
|
||||
const path = DOM.getCurrentDirPath(panel);
|
||||
const dirName = DOM.getCurrentDirName() + '/';
|
||||
const index = path.lastIndexOf(dirName);
|
||||
|
||||
if (path !== '/')
|
||||
return path.replace(RegExp(dirName + '$'), '');
|
||||
return path.slice(0, index);
|
||||
|
||||
return path;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue