mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
test(menu) defaultMenu: add
This commit is contained in:
parent
ee59fbf8d2
commit
19239655ed
2 changed files with 124 additions and 2 deletions
|
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
} = DOM;
|
||||
|
||||
const {dirPath} = CurrentInfo;
|
||||
const path = `${dirPath}/.cloudcmd.menu.js`;
|
||||
const path = `${dirPath}.cloudcmd.menu.js`;
|
||||
|
||||
const [e] = await tryToCatch(RESTful.write, path, data);
|
||||
|
||||
|
|
@ -30,8 +30,9 @@ module.exports = {
|
|||
|
||||
await CloudCmd.refresh();
|
||||
DOM.setCurrentByName('.cloudcmd.menu.js');
|
||||
|
||||
await CloudCmd.EditFile.show();
|
||||
},
|
||||
};
|
||||
|
||||
module.exports._data = data;
|
||||
|
||||
|
|
|
|||
121
client/modules/user-menu/default-menu.spec.js
Normal file
121
client/modules/user-menu/default-menu.spec.js
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('supertape');
|
||||
const stub = require('@cloudcmd/stub');
|
||||
const wraptile = require('wraptile');
|
||||
const defaultMenu = require('./default-menu');
|
||||
const tryToCatch = require('try-to-catch');
|
||||
const {_data} = defaultMenu;
|
||||
const reject = wraptile(async (a) => {
|
||||
throw Error(a);
|
||||
});
|
||||
|
||||
test('cloudcmd: client: user menu: RESTful.write', async (t) => {
|
||||
const name = 'C - Create User Menu File';
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
const {write} = DOM.RESTful;
|
||||
|
||||
await defaultMenu[name]({
|
||||
DOM,
|
||||
CloudCmd,
|
||||
tryToCatch,
|
||||
});
|
||||
|
||||
const path = '/.cloudcmd.menu.js';
|
||||
t.ok(write.calledWith(path, _data), 'should call RESTful.write');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: user menu: refresh', async (t) => {
|
||||
const name = 'C - Create User Menu File';
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
const {refresh} = CloudCmd;
|
||||
|
||||
await defaultMenu[name]({
|
||||
DOM,
|
||||
CloudCmd,
|
||||
tryToCatch,
|
||||
});
|
||||
|
||||
t.ok(refresh.calledWith(), 'should call CloudCmd.refresh');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: user menu: setCurrentByName', async (t) => {
|
||||
const name = 'C - Create User Menu File';
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
const {setCurrentByName} = DOM;
|
||||
|
||||
await defaultMenu[name]({
|
||||
DOM,
|
||||
CloudCmd,
|
||||
tryToCatch,
|
||||
});
|
||||
|
||||
const fileName = '.cloudcmd.menu.js';
|
||||
t.ok(setCurrentByName.calledWith(fileName), 'should call DOM.setCurrentByName');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: user menu: EditFile.show', async (t) => {
|
||||
const name = 'C - Create User Menu File';
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
const {EditFile} = CloudCmd;
|
||||
|
||||
await defaultMenu[name]({
|
||||
DOM,
|
||||
CloudCmd,
|
||||
tryToCatch,
|
||||
});
|
||||
|
||||
t.ok(EditFile.show.called, 'should call EditFile.show');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: user menu: no EditFile.show', async (t) => {
|
||||
const name = 'C - Create User Menu File';
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
const {RESTful} = DOM;
|
||||
const {EditFile} = CloudCmd;
|
||||
|
||||
RESTful.write = stub(reject('Error'));
|
||||
|
||||
await defaultMenu[name]({
|
||||
DOM,
|
||||
CloudCmd,
|
||||
tryToCatch,
|
||||
});
|
||||
|
||||
t.notOk(EditFile.show.called, 'should not call EditFile.show');
|
||||
t.end();
|
||||
});
|
||||
|
||||
function getDOM() {
|
||||
const RESTful = {
|
||||
write: stub(),
|
||||
};
|
||||
|
||||
const CurrentInfo = {
|
||||
dirPath: '/',
|
||||
};
|
||||
|
||||
return {
|
||||
RESTful,
|
||||
CurrentInfo,
|
||||
setCurrentByName: stub(),
|
||||
};
|
||||
}
|
||||
|
||||
function getCloudCmd() {
|
||||
return {
|
||||
refresh: stub(),
|
||||
EditFile: {
|
||||
show: stub(),
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue