48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
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"/);
|
|
}); |