chore: cloudcmd

This commit is contained in:
coderiaser 2026-01-15 22:14:01 +02:00
parent 6e778a35ba
commit 4b84d20bb0
17 changed files with 121 additions and 132 deletions

View file

@ -11,10 +11,10 @@ const returns = wraptile(id);
const {_CURRENT_FILE} = currentFile;
test('current-file: setCurrentName: setAttribute', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const {setAttribute} = current;
@ -23,17 +23,17 @@ test('current-file: setCurrentName: setAttribute', (t) => {
t.calledWith(setAttribute, ['data-name', 'js-file-aGVsbG8='], 'should call setAttribute');
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.end();
});
test('current-file: setCurrentName: setAttribute: cyrillic', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const {setAttribute} = current;
@ -42,8 +42,8 @@ test('current-file: setCurrentName: setAttribute: cyrillic', (t) => {
t.calledWith(setAttribute, ['data-name', 'js-file-JUQwJUIwJUQwJUI5'], 'should call setAttribute');
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.end();
});
@ -59,12 +59,12 @@ test('current-file: getCurrentName', (t) => {
});
test('current-file: emit', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
const emit = stub();
global.DOM = getDOM();
global.CloudCmd = getCloudCmd({
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd({
emit,
});
@ -74,22 +74,22 @@ test('current-file: emit', (t) => {
t.calledWith(emit, ['current-file', current], 'should call emit');
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.end();
});
test('current-file: setCurrentName: return', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
const link = {};
global.DOM = getDOM({
globalThis.DOM = getDOM({
link,
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = create();
@ -97,19 +97,19 @@ test('current-file: setCurrentName: return', (t) => {
t.equal(result, link, 'should return link');
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.end();
});
test('current-file: getParentDirPath: result', (t) => {
const {DOM} = global;
const {DOM} = globalThis;
const getCurrentDirPath = returns('/D/Films/+++favorite films/');
const getCurrentDirName = returns('+++favorite films');
global.DOM = getDOM({
globalThis.DOM = getDOM({
getCurrentDirPath,
getCurrentDirName,
});
@ -117,55 +117,55 @@ test('current-file: getParentDirPath: result', (t) => {
const result = currentFile.getParentDirPath();
const expected = '/D/Films/';
global.DOM = DOM;
globalThis.DOM = DOM;
t.equal(result, expected, 'should return parent dir path');
t.end();
});
test('current-file: isCurrentFile: no', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const result = currentFile.isCurrentFile();
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.notOk(result);
t.end();
});
test('current-file: isCurrentFile', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
const isContainClass = stub();
global.DOM = getDOM({
globalThis.DOM = getDOM({
isContainClass,
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = {};
currentFile.isCurrentFile(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.calledWith(isContainClass, [current, _CURRENT_FILE], 'should call isContainClass');
t.end();
});
test('current-file: getCurrentType', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const {getByDataName} = global.DOM;
const {getByDataName} = globalThis.DOM;
getByDataName.returns({
className: 'mini-icon directory',
@ -175,87 +175,87 @@ test('current-file: getCurrentType', (t) => {
currentFile.getCurrentType(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.calledWith(getByDataName, ['js-type', current]);
t.end();
});
test('current-file: isCurrentIsDir: getCurrentType', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const {getCurrentType} = global.DOM;
const {getCurrentType} = globalThis.DOM;
const current = create();
currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.calledWith(getCurrentType, [current]);
t.end();
});
test('current-file: isCurrentIsDir: directory', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM({
globalThis.DOM = getDOM({
getCurrentType: stub().returns('directory'),
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const result = currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.ok(result);
t.end();
});
test('current-file: isCurrentIsDir: directory-link', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM({
globalThis.DOM = getDOM({
getCurrentType: stub().returns('directory-link'),
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const result = currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.ok(result);
t.end();
});
test('current-file: isCurrentIsDir: file', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM({
globalThis.DOM = getDOM({
getCurrentType: stub().returns('file'),
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const result = currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.notOk(result);
t.end();

View file

@ -416,7 +416,7 @@ module.exports.shrinkSelection = () => {
* setting history wrapper
*/
module.exports.setHistory = (data, title, url) => {
const ret = window.history;
const ret = globalThis.history;
const {prefix} = CloudCmd;
url = prefix + url;
@ -554,7 +554,7 @@ module.exports.getPanel = (options) => {
* then always work with passive
* panel
*/
if (window.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH)
if (globalThis.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH)
panel = DOM.getByDataName('js-left');
if (!panel)

View file

@ -5,7 +5,7 @@ require('css-modules-require-hook/preset');
const {test, stub} = require('supertape');
const {getCSSVar, goToDirectory} = require('./index');
global.CloudCmd = {};
globalThis.CloudCmd = {};
test('cloudcmd: client: dom: goToDirectory', async (t) => {
const path = '';
@ -25,14 +25,14 @@ test('cloudcmd: client: dom: getCSSVar', (t) => {
const body = {};
const getPropertyValue = stub().returns(0);
global.getComputedStyle = stub().returns({
globalThis.getComputedStyle = stub().returns({
getPropertyValue,
});
const result = getCSSVar('hello', {
body,
});
delete global.getComputedStyle;
delete globalThis.getComputedStyle;
t.notOk(result);
t.end();
@ -42,14 +42,14 @@ test('cloudcmd: client: dom: getCSSVar: 1', (t) => {
const body = {};
const getPropertyValue = stub().returns(1);
global.getComputedStyle = stub().returns({
globalThis.getComputedStyle = stub().returns({
getPropertyValue,
});
const result = getCSSVar('hello', {
body,
});
delete global.getComputedStyle;
delete globalThis.getComputedStyle;
t.ok(result);
t.end();

View file

@ -7,58 +7,58 @@ const storage = require('./storage');
const {stringify} = JSON;
test('cloudcmd: client: storage: set', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const setItem = stub();
global.localStorage = {
globalThis.localStorage = {
setItem,
};
await storage.set('hello', 'world');
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.calledWith(setItem, ['hello', 'world'], 'should call setItem');
t.end();
});
test('cloudcmd: client: storage: get', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const getItem = stub().returns('world');
global.localStorage = {
globalThis.localStorage = {
getItem,
};
const result = await storage.get('hello');
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.equal(result, 'world');
t.end();
});
test('cloudcmd: client: storage: getJson', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const expected = {
hello: 'world',
};
const getItem = stub().returns(stringify(expected));
global.localStorage = {
globalThis.localStorage = {
getItem,
};
const result = await storage.getJson('hello');
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.deepEqual(result, expected);
t.end();
});
test('cloudcmd: client: storage: setJson', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const data = {
hello: 'world',
};
@ -66,42 +66,42 @@ test('cloudcmd: client: storage: setJson', async (t) => {
const expected = stringify(data);
const setItem = stub();
global.localStorage = {
globalThis.localStorage = {
setItem,
};
await storage.setJson('hello', data);
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.calledWith(setItem, ['hello', expected]);
t.end();
});
test('cloudcmd: client: storage: remove', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const removeItem = stub();
global.localStorage = {
globalThis.localStorage = {
removeItem,
};
await storage.remove('hello');
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.calledWith(removeItem, ['hello'], 'should call removeItem');
t.end();
});
test('cloudcmd: client: storage: clear', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const clear = stub();
global.localStorage = {
globalThis.localStorage = {
clear,
};
await storage.clear();
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.calledWithNoArgs(clear, 'should call clear');
t.end();