Collapse folders and zips by default
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { render } from '../upload/frontend/table/render.js';
|
||||
|
||||
function elements() {
|
||||
return { tableBodyEl: { innerHTML: '' }, countEl: { textContent: '' } };
|
||||
}
|
||||
|
||||
function fileNode() {
|
||||
return {
|
||||
id: 'file-1',
|
||||
kind: 'file',
|
||||
name: 'document.txt',
|
||||
path: 'folder/document.txt',
|
||||
file: { size: 7 },
|
||||
children: [],
|
||||
expanded: true,
|
||||
};
|
||||
}
|
||||
|
||||
test('render: папка по умолчанию скрывает дочерние файлы', () => {
|
||||
const child = fileNode();
|
||||
const state = {
|
||||
nodes: [{
|
||||
id: 'folder-1',
|
||||
kind: 'folder',
|
||||
name: 'folder',
|
||||
path: 'folder',
|
||||
children: [child],
|
||||
expanded: false,
|
||||
}],
|
||||
};
|
||||
const output = elements();
|
||||
|
||||
render(state, output);
|
||||
|
||||
assert.match(output.tableBodyEl.innerHTML, /data-toggle="folder-1"/);
|
||||
assert.match(output.tableBodyEl.innerHTML, /aria-expanded="false"/);
|
||||
assert.doesNotMatch(output.tableBodyEl.innerHTML, /data-path="folder\/document\.txt"/);
|
||||
assert.equal(output.countEl.textContent, '1 файлов · 7 B');
|
||||
|
||||
state.nodes[0].expanded = true;
|
||||
render(state, output);
|
||||
|
||||
assert.match(output.tableBodyEl.innerHTML, /data-path="folder\/document\.txt"/);
|
||||
assert.match(output.tableBodyEl.innerHTML, /aria-expanded="true"/);
|
||||
});
|
||||
@@ -31,7 +31,7 @@ export function onFolderChange(state, cfg, elements) {
|
||||
if (!roots.has(rootName)) {
|
||||
// Один root на выбранный каталог позволяет сохранить дерево целиком.
|
||||
roots.set(rootName, { id: crypto.randomUUID(), kind: 'folder', name: rootName,
|
||||
path: rootName, children: [], expanded: true });
|
||||
path: rootName, children: [], expanded: false });
|
||||
}
|
||||
const root = roots.get(rootName);
|
||||
// Вставляет узел по его пути, создавая отсутствующие промежуточные папки.
|
||||
@@ -44,7 +44,7 @@ export function onFolderChange(state, cfg, elements) {
|
||||
if (!child) {
|
||||
child = last ? node : { id: crypto.randomUUID(), kind: 'folder', name: part,
|
||||
path: `${rootName}/${nodeParts.slice(0, index + 1).join('/')}`,
|
||||
children: [], expanded: true };
|
||||
children: [], expanded: false };
|
||||
current.children.push(child);
|
||||
}
|
||||
current = child;
|
||||
|
||||
@@ -36,9 +36,9 @@ function safeEntryParts(entryName) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
/** Создаёт единый узел file, folder или zip с уникальным id и раскрытым состоянием. */
|
||||
/** Создаёт единый узел file, folder или zip с уникальным id и начальным состоянием раскрытия. */
|
||||
function node(kind, name, path, children = [], file = null) {
|
||||
return { id: crypto.randomUUID(), kind, name, path, children, file, expanded: true };
|
||||
return { id: crypto.randomUUID(), kind, name, path, children, file, expanded: kind === 'file' };
|
||||
}
|
||||
|
||||
/** Вставляет leaf или вложенное дерево по сегментам пути, создавая folder-узлы. */
|
||||
|
||||
Reference in New Issue
Block a user