fix(current-file) getParrentDirPath: path contains "+++"

This commit is contained in:
coderaiser 2018-05-22 21:06:09 +03:00
parent 550f76461e
commit 4118f90b6b
3 changed files with 41 additions and 9 deletions

View file

@ -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);
};
/**

View file

@ -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: '/',
}
};
}

View file

@ -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;
};