test(route) keys panel: show

This commit is contained in:
coderaiser 2017-12-06 15:04:32 +02:00
parent af70eb5ee6
commit 81f4a207a7
2 changed files with 35 additions and 18 deletions

View file

@ -43,8 +43,6 @@ module.exports._getIndexPath = getIndexPath;
* additional processing of index file
*/
function indexProcessing(options) {
const keysPanel = '<div id="js-keyspanel" class="{{ className }}"';
const keysPanelRegExp = '<div id="?js-keyspanel"? class="?{{ className }}"?';
const isOnePanel = config('onePanelMode');
const noContact = !config('contact');
const noConfig = !config('configDialog');
@ -54,20 +52,8 @@ function indexProcessing(options) {
let data = options.data;
let from;
let to;
if (!config('showKeysPanel')) {
from = rendy(keysPanelRegExp, {
className: 'keyspanel'
});
to = rendy(keysPanel, {
className: 'keyspanel hidden'
});
data = data.replace(RegExp(from), to);
}
if (!config('showKeysPanel'))
data = hideKeysPanel(data);
if (isOnePanel)
data = data
@ -90,7 +76,7 @@ function indexProcessing(options) {
data = data
.replace('icon-terminal', 'icon-terminal none');
let left = rendy(Template.panel, {
const left = rendy(Template.panel, {
side : 'left',
content : panel,
className : !isOnePanel ? '' : 'panel-single'
@ -188,6 +174,22 @@ function buildIndex(json, callback) {
});
}
module.exports._hideKeysPanel = hideKeysPanel;
function hideKeysPanel(html) {
const keysPanel = '<div id="js-keyspanel" class="{{ className }}"';
const keysPanelRegExp = '<div id="?js-keyspanel"? class="?{{ className }}"?';
const from = rendy(keysPanelRegExp, {
className: 'keyspanel'
});
const to = rendy(keysPanel, {
className: 'keyspanel hidden'
});
return html.replace(RegExp(from), to);
}
function check(req, res, next) {
if (!req)
throw Error('req could not be empty!');

View file

@ -148,7 +148,7 @@ test('cloudcmd: route: buttons: one panel mode: move', (t) => {
});
});
test('cloudcmd: route: keys panel', (t) => {
test('cloudcmd: route: keys panel: hide', (t) => {
const config = {
showKeysPanel: false
};
@ -163,6 +163,21 @@ test('cloudcmd: route: keys panel', (t) => {
});
});
test('cloudcmd: route: keys panel', (t) => {
const config = {
showKeysPanel: true
};
before({config}, (port, after) => {
getStr(`http://localhost:${port}/`)
.then((result) => {
t.notOk(/keyspanel hidden/.test(result), 'should show keyspanel');
t.end();
after();
});
});
});
test('cloudcmd: route: no index', (t) => {
const name = path.join(__dirname, '../../dist/index.html');
const nameAfter = path.join(__dirname, '../../dist/index1.html');