test: static: user-menu: coverage

This commit is contained in:
coderaiser 2023-01-17 21:53:47 +02:00
parent 924f8696d0
commit 09de19b46e
2 changed files with 89 additions and 19 deletions

View file

@ -37,22 +37,23 @@ module.exports = {
},
'C - Create User Menu File': async ({DOM, CloudCmd}) => {
const {Dialog} = DOM;
const currentFile = DOM.getCurrentByName('.cloudcmd.menu.js')
const {
Dialog,
CurrentInfo,
} = DOM;
const currentFile = DOM.getCurrentByName('.cloudcmd.menu.js');
if (currentFile) {
const [cancel] = await Dialog.confirm(`Looks like file '.cloudcmd.menu.js' already exists. Overwrite?`);
if (cancel)
return;
}
const {CurrentInfo} = DOM;
const {dirPath} = CurrentInfo;
const path = `${dirPath}.cloudcmd.menu.js`;
const {prefix} = CloudCmd;
const data = await readDefaultMenu({prefix});
await createDefaultMenu({
path,

View file

@ -45,39 +45,55 @@ test('cloudcmd: static: user menu: R', (t) => {
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 DOM = {};
const fn = defaultMenu[name];
t.ok(fn);
const [error] = await tryToCatch(fn, {
DOM,
});
t.equal(error.code, 'ERR_UNSUPPORTED_ESM_URL_SCHEME');
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 DOM = {};
const fn = defaultMenu[name];
t.ok(fn);
const [error] = await tryToCatch(fn, {
DOM,
});
t.equal(error.code, 'ERR_UNSUPPORTED_ESM_URL_SCHEME');
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 DOM = {};
const fn = defaultMenu[name];
t.ok(fn);
const [error] = await tryToCatch(fn, {
DOM,
});
t.equal(error.code, 'ERR_UNSUPPORTED_ESM_URL_SCHEME');
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 DOM = {};
const fn = defaultMenu[name];
t.ok(fn);
const [error] = await tryToCatch(fn, {
DOM,
});
t.equal(error.code, 'ERR_UNSUPPORTED_ESM_URL_SCHEME');
t.end();
});
@ -98,6 +114,54 @@ test('cloudcmd: static: user menu: IO.write', async (t) => {
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) => {
const name = 'C - Create User Menu File';
const DOM = getDOM();
@ -234,6 +298,10 @@ function getDOM() {
write: stub(),
};
const Dialog = {
confirm: stub(),
};
const CurrentInfo = {
dirPath: '/',
files: [],
@ -244,6 +312,7 @@ function getDOM() {
return {
IO,
Dialog,
CurrentInfo,
setCurrentByName: stub(),
getFilenames: stub().returns([]),