Skip to content

Commit

Permalink
feature(user-menu) add ability to ignore private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed May 28, 2019
1 parent 554023c commit 8961841
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client/modules/user-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports.hide = hide;

const getKey = (a) => a.split(' - ')[0];
const beginWith = (a) => (b) => a === getKey(b);
const notPrivate = ([a]) => a !== '_';

const {CurrentInfo} = DOM;

Expand All @@ -49,7 +50,9 @@ async function show() {
if (error)
return Dialog.alert(`User menu error: ${error.message}`);

const options = Object.keys(userMenu);
const options = Object
.keys(userMenu)
.filter(notPrivate);

const button = createElement('button', {
className: 'cloudcmd-user-menu-button',
Expand Down
2 changes: 2 additions & 0 deletions static/user-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ async function readDefaultMenu({prefix}) {
return data;
}

module.exports._selectNames = selectNames;
function selectNames(names, panel, {selectFile, getCurrentByName}) {
for (const name of names) {
const file = getCurrentByName(name, panel);
selectFile(file);
}
}

module.exports._compare = compare;
function compare(a, b) {
const result = [];

Expand Down
50 changes: 50 additions & 0 deletions static/user-menu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,56 @@ test('cloudcmd: static: user menu: compare directories', async (t) => {
t.end();
});

test('cloudcmd: static: user menu: compare directories: select names', async (t) => {
const {_selectNames} = defaultMenu;
const selectFile = stub();
const file = {};
const getCurrentByName = stub().returns(file);

const names = ['hi'];
const panel = {};

_selectNames(names, panel, {
selectFile,
getCurrentByName,
});

t.ok(selectFile.calledWith(file), 'should call selectFile');
t.end();
});

test('cloudcmd: static: user menu: compare directories: select names: getCurrentByName', async (t) => {
const {_selectNames} = defaultMenu;
const selectFile = stub();
const getCurrentByName = stub();

const name = 'hi';
const names = [name];
const panel = {};

_selectNames(names, panel, {
selectFile,
getCurrentByName,
});

t.ok(getCurrentByName.calledWith(name, panel), 'should call selectFile');
t.end();
});

test('cloudcmd: static: user menu: compare directories: select names: compare', async (t) => {
const {_compare} = defaultMenu;
const a = [1, 2];
const b = [1, 3];

const result = _compare(a, b);
const expected = [
2,
];

t.deepEqual(result, expected, 'should equal');
t.end();
});

function getDOM() {
const IO = {
write: stub(),
Expand Down

0 comments on commit 8961841

Please sign in to comment.