mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test: static: user-menu: coverage
This commit is contained in:
parent
924f8696d0
commit
09de19b46e
2 changed files with 89 additions and 19 deletions
|
|
@ -37,22 +37,23 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
'C - Create User Menu File': async ({DOM, CloudCmd}) => {
|
'C - Create User Menu File': async ({DOM, CloudCmd}) => {
|
||||||
const {Dialog} = DOM;
|
const {
|
||||||
const currentFile = DOM.getCurrentByName('.cloudcmd.menu.js')
|
Dialog,
|
||||||
|
CurrentInfo,
|
||||||
|
} = DOM;
|
||||||
|
const currentFile = DOM.getCurrentByName('.cloudcmd.menu.js');
|
||||||
|
|
||||||
if (currentFile) {
|
if (currentFile) {
|
||||||
const [cancel] = await Dialog.confirm(`Looks like file '.cloudcmd.menu.js' already exists. Overwrite?`);
|
const [cancel] = await Dialog.confirm(`Looks like file '.cloudcmd.menu.js' already exists. Overwrite?`);
|
||||||
|
|
||||||
if (cancel)
|
if (cancel)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {CurrentInfo} = DOM;
|
|
||||||
const {dirPath} = CurrentInfo;
|
const {dirPath} = CurrentInfo;
|
||||||
const path = `${dirPath}.cloudcmd.menu.js`;
|
const path = `${dirPath}.cloudcmd.menu.js`;
|
||||||
const {prefix} = CloudCmd;
|
const {prefix} = CloudCmd;
|
||||||
|
|
||||||
|
|
||||||
const data = await readDefaultMenu({prefix});
|
const data = await readDefaultMenu({prefix});
|
||||||
await createDefaultMenu({
|
await createDefaultMenu({
|
||||||
path,
|
path,
|
||||||
|
|
|
||||||
|
|
@ -45,39 +45,55 @@ test('cloudcmd: static: user menu: R', (t) => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cloudcmd: static: user menu: F6', (t) => {
|
test('cloudcmd: static: user menu: F6', async (t) => {
|
||||||
const name = 'F6 - Copy URL to current file';
|
const name = 'F6 - Copy URL to current file';
|
||||||
|
const DOM = {};
|
||||||
|
|
||||||
const fn = defaultMenu[name];
|
const fn = defaultMenu[name];
|
||||||
|
const [error] = await tryToCatch(fn, {
|
||||||
t.ok(fn);
|
DOM,
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(error.code, 'ERR_UNSUPPORTED_ESM_URL_SCHEME');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cloudcmd: static: user menu: Y', (t) => {
|
test('cloudcmd: static: user menu: Y', async (t) => {
|
||||||
const name = 'Y - Convert YouTube to MP3';
|
const name = 'Y - Convert YouTube to MP3';
|
||||||
|
const DOM = {};
|
||||||
|
|
||||||
const fn = defaultMenu[name];
|
const fn = defaultMenu[name];
|
||||||
|
const [error] = await tryToCatch(fn, {
|
||||||
t.ok(fn);
|
DOM,
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(error.code, 'ERR_UNSUPPORTED_ESM_URL_SCHEME');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cloudcmd: static: user menu: F', (t) => {
|
test('cloudcmd: static: user menu: F', async (t) => {
|
||||||
const name = 'F - Convert flac to mp3 [ffmpeg]';
|
const name = 'F - Convert flac to mp3 [ffmpeg]';
|
||||||
|
const DOM = {};
|
||||||
|
|
||||||
const fn = defaultMenu[name];
|
const fn = defaultMenu[name];
|
||||||
|
const [error] = await tryToCatch(fn, {
|
||||||
t.ok(fn);
|
DOM,
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(error.code, 'ERR_UNSUPPORTED_ESM_URL_SCHEME');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cloudcmd: static: user menu: M', (t) => {
|
test('cloudcmd: static: user menu: M', async (t) => {
|
||||||
const name = 'M - Convert mpeg to mp3 [ffmpeg]';
|
const name = 'M - Convert mpeg to mp3 [ffmpeg]';
|
||||||
|
const DOM = {};
|
||||||
|
|
||||||
const fn = defaultMenu[name];
|
const fn = defaultMenu[name];
|
||||||
|
const [error] = await tryToCatch(fn, {
|
||||||
t.ok(fn);
|
DOM,
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(error.code, 'ERR_UNSUPPORTED_ESM_URL_SCHEME');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -98,6 +114,54 @@ test('cloudcmd: static: user menu: IO.write', async (t) => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('cloudcmd: static: user menu: C: exists: ok', async (t) => {
|
||||||
|
const name = 'C - Create User Menu File';
|
||||||
|
const DOM = getDOM();
|
||||||
|
const CloudCmd = getCloudCmd();
|
||||||
|
const {
|
||||||
|
Dialog,
|
||||||
|
getCurrentByName,
|
||||||
|
} = DOM;
|
||||||
|
const {confirm} = Dialog;
|
||||||
|
const {write} = DOM.IO;
|
||||||
|
|
||||||
|
getCurrentByName.returns({});
|
||||||
|
confirm.resolves([]);
|
||||||
|
|
||||||
|
await defaultMenu[name]({
|
||||||
|
DOM,
|
||||||
|
CloudCmd,
|
||||||
|
});
|
||||||
|
|
||||||
|
const path = '/.cloudcmd.menu.js';
|
||||||
|
|
||||||
|
t.calledWith(write, [path, _data], 'should call IO.write');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cloudcmd: static: user menu: C: exists: cancel', async (t) => {
|
||||||
|
const name = 'C - Create User Menu File';
|
||||||
|
const DOM = getDOM();
|
||||||
|
const CloudCmd = getCloudCmd();
|
||||||
|
const {
|
||||||
|
Dialog,
|
||||||
|
getCurrentByName,
|
||||||
|
} = DOM;
|
||||||
|
const {confirm} = Dialog;
|
||||||
|
const {write} = DOM.IO;
|
||||||
|
|
||||||
|
getCurrentByName.returns({});
|
||||||
|
confirm.resolves([Error('cancel')]);
|
||||||
|
|
||||||
|
await defaultMenu[name]({
|
||||||
|
DOM,
|
||||||
|
CloudCmd,
|
||||||
|
});
|
||||||
|
|
||||||
|
t.notCalled(write);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
test('cloudcmd: static: user menu: refresh', async (t) => {
|
test('cloudcmd: static: user menu: refresh', async (t) => {
|
||||||
const name = 'C - Create User Menu File';
|
const name = 'C - Create User Menu File';
|
||||||
const DOM = getDOM();
|
const DOM = getDOM();
|
||||||
|
|
@ -234,6 +298,10 @@ function getDOM() {
|
||||||
write: stub(),
|
write: stub(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Dialog = {
|
||||||
|
confirm: stub(),
|
||||||
|
};
|
||||||
|
|
||||||
const CurrentInfo = {
|
const CurrentInfo = {
|
||||||
dirPath: '/',
|
dirPath: '/',
|
||||||
files: [],
|
files: [],
|
||||||
|
|
@ -244,6 +312,7 @@ function getDOM() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
IO,
|
IO,
|
||||||
|
Dialog,
|
||||||
CurrentInfo,
|
CurrentInfo,
|
||||||
setCurrentByName: stub(),
|
setCurrentByName: stub(),
|
||||||
getFilenames: stub().returns([]),
|
getFilenames: stub().returns([]),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue