feat: workspace helpers - quoting paths, what a dropped file does, with node tests
This commit is contained in:
1 parent
0ada0899cf
commit
7b9daa524e
4 files changed
+90
No files matched your search
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const U = require('./wsutil.js');
|
||||
|
||||
test('shellQuote keeps a path one literal word', () => {
|
||||
assert.strictEqual(U.shellQuote('/srv/a b'), "'/srv/a b'");
|
||||
assert.strictEqual(U.shellQuote("/x/it's"), "'/x/it'\\''s'");
|
||||
assert.strictEqual(U.shellQuote('/x/$HOME;rm'), "'/x/$HOME;rm'");
|
||||
assert.strictEqual(U.shellQuoteAll(['/a', '/b c']), "'/a' '/b c'");
|
||||
});
|
||||
|
||||
const m1 = {kind: 'agent', id: 'm1', label: 'web'};
|
||||
const m2 = {kind: 'agent', id: 'm2', label: 'db'};
|
||||
const s1 = {kind: 'ssh', id: 'm1|root@h:22', label: 'root@h'};
|
||||
const item = {source: m1, paths: ['/etc/x'], dir: '/etc'};
|
||||
|
||||
test('dropAction: files into a file pane is a transfer', () => {
|
||||
assert.deepStrictEqual(U.dropAction(item, {kind: 'files', source: m2, dir: '/tmp'}), {kind: 'transfer'});
|
||||
assert.deepStrictEqual(U.dropAction(item, {kind: 'folder', source: m1, dir: '/var'}), {kind: 'transfer'});
|
||||
});
|
||||
test('dropAction: into its own folder does nothing', () => {
|
||||
assert.deepStrictEqual(U.dropAction(item, {kind: 'files', source: m1, dir: '/etc'}), {kind: 'none'});
|
||||
});
|
||||
test('dropAction: terminal of the same place pastes, of another is denied', () => {
|
||||
assert.deepStrictEqual(U.dropAction(item, {kind: 'term', source: m1}), {kind: 'paste'});
|
||||
const d = U.dropAction(item, {kind: 'term', source: m2});
|
||||
assert.strictEqual(d.kind, 'deny');
|
||||
assert.strictEqual(d.reason, 'Нельзя: файл на web, а терминал на db');
|
||||
assert.strictEqual(U.dropAction({source: s1, paths: ['/a'], dir: '/'}, {kind: 'term', source: s1}).kind, 'paste');
|
||||
});
|
||||
test('fmtSize', () => {
|
||||
assert.strictEqual(U.fmtSize(10), '10 B');
|
||||
assert.strictEqual(U.fmtSize(2048), '2.0 K');
|
||||
});
|
||||
Reference in new issue
Block a user