BlueGit

timfa filemanager

Merge feature/fix-preview-alignment-and-test-cleanup

timfa Tim Falken · pushed by timfa

Authored 2026-05-04 · 6 months ago

Hash
3dbfd3d95f0378cf36d614c175e2a298c13b95f9
6 files changed +179 −4
.github/copilot-instructions.md +2 −1
@@ -16,9 +16,10 @@
16 16 ### Git authoring
17 17 - When starting work on something, create a feature or fix branch
18 18 - When concrete, complete steps are made, create a commit in that branch
19 - Try to commit frequently, chunking work into individual steps
19 20 - When all work is done, merge the branch into master, and then delete it so only master remains
20 21 - Ensure you don't leave old branches you've made in git and that everything is merged neatly.
21 - Always run the full test suite and fix any issues before merging to master.
22 - Always run the full test suite and fix any issues (including unrelated to your work) before merging to master.
22 23
23 24 ## Testing Expectations
24 25 - **Default rule:** every new feature should receive a test that verifies it behaves as requested.
@@ -16,9 +16,10 @@
16### Git authoring
16### Git authoring
17- When starting work on something, create a feature or fix branch
17- When starting work on something, create a feature or fix branch
18- When concrete, complete steps are made, create a commit in that branch
18- When concrete, complete steps are made, create a commit in that branch
19- Try to commit frequently, chunking work into individual steps
19- When all work is done, merge the branch into master, and then delete it so only master remains
20- When all work is done, merge the branch into master, and then delete it so only master remains
20- Ensure you don't leave old branches you've made in git and that everything is merged neatly.
21- Ensure you don't leave old branches you've made in git and that everything is merged neatly.
21- Always run the full test suite and fix any issues before merging to master.
22- Always run the full test suite and fix any issues (including unrelated to your work) before merging to master.
22
23
23## Testing Expectations
24## Testing Expectations
24- **Default rule:** every new feature should receive a test that verifies it behaves as requested.
25- **Default rule:** every new feature should receive a test that verifies it behaves as requested.
.github/technical-reference.md +2 −1
@@ -57,7 +57,7 @@
57 57 - showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().
58 58 - showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.
59 59 - loadThumbnails() - Registers visible file icons for lazy thumbnail loading; retries missing cache thumbnails during incremental refresh.
60 - loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404.
60 - loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404 and uses direct source SVG thumbnails for SVG files under 1MB.
61 61 - getThumbnailKind(name) - Classifies files into image/text/badge thumbnail strategies.
62 62 - observeThumbnailIcon(iconEl) - Defers thumbnail fetch work until file icons are near/in the viewport.
63 63 - disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.
@@ -100,6 +100,7 @@
100 100 - openSidebar(item) - Renders item details/actions in sidebar; root selections include alias/original name/usage/access list and keep Rename while hiding Move To/Delete.
101 101 - openFolderSidebar() - Shows current folder details when nothing is selected; when at root base-level it also shows root access list.
102 102 - openRenameModal(item) - Renames files/folders; for roots this writes display alias via /api/files/root-alias and reloads roots.
103 - openUserModal(user, paths) - Admin user editor; enforces UI permission rule that Write is disabled/unchecked while Read is unchecked.
103 104
104 105 ## public/drag-move.js
105 106 - makeDraggable(el, item) - Attaches pointerdown to a .file-item; starts drag after threshold movement. Depends on: api(), canWrite(), navigateTo(), STATE, closeSidebar(), toast() from app.js.
@@ -57,7 +57,7 @@
57- showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().
57- showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().
58- showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.
58- showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.
59- loadThumbnails() - Registers visible file icons for lazy thumbnail loading; retries missing cache thumbnails during incremental refresh.
59- loadThumbnails() - Registers visible file icons for lazy thumbnail loading; retries missing cache thumbnails during incremental refresh.
60- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404.
60- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404 and uses direct source SVG thumbnails for SVG files under 1MB.
61- getThumbnailKind(name) - Classifies files into image/text/badge thumbnail strategies.
61- getThumbnailKind(name) - Classifies files into image/text/badge thumbnail strategies.
62- observeThumbnailIcon(iconEl) - Defers thumbnail fetch work until file icons are near/in the viewport.
62- observeThumbnailIcon(iconEl) - Defers thumbnail fetch work until file icons are near/in the viewport.
63- disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.
63- disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.
@@ -100,6 +100,7 @@
100- openSidebar(item) - Renders item details/actions in sidebar; root selections include alias/original name/usage/access list and keep Rename while hiding Move To/Delete.
100- openSidebar(item) - Renders item details/actions in sidebar; root selections include alias/original name/usage/access list and keep Rename while hiding Move To/Delete.
101- openFolderSidebar() - Shows current folder details when nothing is selected; when at root base-level it also shows root access list.
101- openFolderSidebar() - Shows current folder details when nothing is selected; when at root base-level it also shows root access list.
102- openRenameModal(item) - Renames files/folders; for roots this writes display alias via /api/files/root-alias and reloads roots.
102- openRenameModal(item) - Renames files/folders; for roots this writes display alias via /api/files/root-alias and reloads roots.
103- openUserModal(user, paths) - Admin user editor; enforces UI permission rule that Write is disabled/unchecked while Read is unchecked.
103
104
104## public/drag-move.js
105## public/drag-move.js
105- makeDraggable(el, item) - Attaches pointerdown to a .file-item; starts drag after threshold movement. Depends on: api(), canWrite(), navigateTo(), STATE, closeSidebar(), toast() from app.js.
106- makeDraggable(el, item) - Attaches pointerdown to a .file-item; starts drag after threshold movement. Depends on: api(), canWrite(), navigateTo(), STATE, closeSidebar(), toast() from app.js.
.github/tests.md +2 −0
@@ -69,5 +69,7 @@
69 69 - `root sidebar shows alias and original name, and excludes Move to action`
70 70 - `base-level root sidebar shows access list with no item selected`
71 71 - `shows pending icon spinner when image thumbnail cache is not ready`
72 - `admin user modal locks write checkbox while read is unchecked`
73 - `uses direct svg thumbnail when svg file is under 1MB`
72 74
73 75 ---
@@ -69,5 +69,7 @@
69- `root sidebar shows alias and original name, and excludes Move to action`
69- `root sidebar shows alias and original name, and excludes Move to action`
70- `base-level root sidebar shows access list with no item selected`
70- `base-level root sidebar shows access list with no item selected`
71- `shows pending icon spinner when image thumbnail cache is not ready`
71- `shows pending icon spinner when image thumbnail cache is not ready`
72- `admin user modal locks write checkbox while read is unchecked`
73- `uses direct svg thumbnail when svg file is under 1MB`
72
74
73---
75---
public/app.js +61 −2
@@ -730,7 +730,9 @@ async function navigateTo (absPath, root, opts = {})
730 730
731 731 function renderBreadcrumb ()
732 732 {
733 if (typeof document === 'undefined') return;
733 734 const nav = document.getElementById('breadcrumb');
735 if (!nav) return;
734 736 nav.innerHTML = '';
735 737
736 738 // "Home" crumb
@@ -2501,6 +2503,42 @@ function openUserModal (user, paths)
2501 2503 };
2502 2504 adminChk.addEventListener('change', () => rebuildPermRows(adminChk.checked));
2503 2505
2506 const syncReadWriteConstraints = (row, admin = false) =>
2507 {
2508 const readCb = row.querySelector('input[data-type="read"]');
2509 const writeCb = row.querySelector('input[data-type="write"]');
2510 if (!readCb || !writeCb) return;
2511
2512 if (admin)
2513 {
2514 readCb.checked = true;
2515 writeCb.checked = true;
2516 readCb.disabled = true;
2517 writeCb.disabled = true;
2518 return;
2519 }
2520
2521 readCb.disabled = false;
2522 if (!readCb.checked)
2523 {
2524 writeCb.checked = false;
2525 writeCb.disabled = true;
2526 }
2527 else
2528 {
2529 writeCb.disabled = false;
2530 }
2531 };
2532
2533 const syncAllReadWriteConstraints = () =>
2534 {
2535 const admin = adminChk.checked;
2536 permDiv.querySelectorAll('.perm-row').forEach((row) =>
2537 {
2538 syncReadWriteConstraints(row, admin);
2539 });
2540 };
2541
2504 2542 for (const p of paths)
2505 2543 {
2506 2544 const label = p.split(/[\\/]/).pop();
@@ -2515,8 +2553,19 @@ function openUserModal (user, paths)
2515 2553 <label class="checkbox-label"><input type="checkbox" data-label="${label}" data-type="write" ${writeChecked ? 'checked' : ''} ${isAdminUser ? 'disabled' : ''} /> Write</label>
2516 2554 `;
2517 2555 if (isAdminUser) row.title = 'Admins always have full access';
2556 const readCb = row.querySelector('input[data-type="read"]');
2557 if (readCb)
2558 {
2559 readCb.addEventListener('change', () =>
2560 {
2561 syncReadWriteConstraints(row, adminChk.checked);
2562 });
2563 }
2518 2564 permDiv.appendChild(row);
2519 2565 }
2566
2567 syncAllReadWriteConstraints();
2568 adminChk.addEventListener('change', syncAllReadWriteConstraints);
2520 2569 }
2521 2570
2522 2571 document.getElementById('user-form').onsubmit = async (e) =>
@@ -2565,6 +2614,7 @@ const AUDIO_EXTS = new Set(['mp3', 'ogg', 'wav', 'flac', 'aac', 'm4a']);
2565 2614 const DOC_EXTS = new Set(['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']);
2566 2615 const CODE_EXTS = new Set(['js', 'ts', 'py', 'rb', 'go', 'rs', 'c', 'cpp', 'h', 'cs', 'java', 'php', 'html', 'css', 'json', 'xml', 'yaml', 'yml', 'sh', 'bash', 'md', 'txt']);
2567 2616 const ARCHIVE_EXTS = new Set(['zip', 'tar', 'gz', 'bz2', 'xz', 'rar', '7z']);
2617 const MAX_DIRECT_SVG_THUMB_BYTES = 1024 * 1024;
2568 2618
2569 2619 function iconFolder (size = 52)
2570 2620 {
@@ -2791,7 +2841,16 @@ async function loadOneThumbnail (iconEl)
2791 2841 }
2792 2842 else if (kind === 'image')
2793 2843 {
2794 const url = `/api/files/thumbnail?file=${encodeURIComponent(filePath)}`;
2844 const ext = extOf(item.name || '');
2845 const useDirectSvg =
2846 ext === 'svg' &&
2847 typeof item.size === 'number' &&
2848 item.size > 0 &&
2849 item.size <= MAX_DIRECT_SVG_THUMB_BYTES;
2850
2851 const url = useDirectSvg
2852 ? `/api/files/download?file=${encodeURIComponent(filePath)}`
2853 : `/api/files/thumbnail?file=${encodeURIComponent(filePath)}`;
2795 2854
2796 2855 let res;
2797 2856 try
@@ -2807,7 +2866,7 @@ async function loadOneThumbnail (iconEl)
2807 2866 return;
2808 2867 }
2809 2868
2810 if (res.status === 404)
2869 if (!useDirectSvg && res.status === 404)
2811 2870 {
2812 2871 setThumbnailPending(iconEl, true);
2813 2872 return;
@@ -730,7 +730,9 @@ async function navigateTo (absPath, root, opts = {})
730
730
731function renderBreadcrumb ()
731function renderBreadcrumb ()
732{
732{
733 if (typeof document === 'undefined') return;
733 const nav = document.getElementById('breadcrumb');
734 const nav = document.getElementById('breadcrumb');
735 if (!nav) return;
734 nav.innerHTML = '';
736 nav.innerHTML = '';
735
737
736 // "Home" crumb
738 // "Home" crumb
@@ -2501,6 +2503,42 @@ function openUserModal (user, paths)
2501 };
2503 };
2502 adminChk.addEventListener('change', () => rebuildPermRows(adminChk.checked));
2504 adminChk.addEventListener('change', () => rebuildPermRows(adminChk.checked));
2503
2505
2506 const syncReadWriteConstraints = (row, admin = false) =>
2507 {
2508 const readCb = row.querySelector('input[data-type="read"]');
2509 const writeCb = row.querySelector('input[data-type="write"]');
2510 if (!readCb || !writeCb) return;
2511
2512 if (admin)
2513 {
2514 readCb.checked = true;
2515 writeCb.checked = true;
2516 readCb.disabled = true;
2517 writeCb.disabled = true;
2518 return;
2519 }
2520
2521 readCb.disabled = false;
2522 if (!readCb.checked)
2523 {
2524 writeCb.checked = false;
2525 writeCb.disabled = true;
2526 }
2527 else
2528 {
2529 writeCb.disabled = false;
2530 }
2531 };
2532
2533 const syncAllReadWriteConstraints = () =>
2534 {
2535 const admin = adminChk.checked;
2536 permDiv.querySelectorAll('.perm-row').forEach((row) =>
2537 {
2538 syncReadWriteConstraints(row, admin);
2539 });
2540 };
2541
2504 for (const p of paths)
2542 for (const p of paths)
2505 {
2543 {
2506 const label = p.split(/[\\/]/).pop();
2544 const label = p.split(/[\\/]/).pop();
@@ -2515,8 +2553,19 @@ function openUserModal (user, paths)
2515 <label class="checkbox-label"><input type="checkbox" data-label="${label}" data-type="write" ${writeChecked ? 'checked' : ''} ${isAdminUser ? 'disabled' : ''} /> Write</label>
2553 <label class="checkbox-label"><input type="checkbox" data-label="${label}" data-type="write" ${writeChecked ? 'checked' : ''} ${isAdminUser ? 'disabled' : ''} /> Write</label>
2516 `;
2554 `;
2517 if (isAdminUser) row.title = 'Admins always have full access';
2555 if (isAdminUser) row.title = 'Admins always have full access';
2556 const readCb = row.querySelector('input[data-type="read"]');
2557 if (readCb)
2558 {
2559 readCb.addEventListener('change', () =>
2560 {
2561 syncReadWriteConstraints(row, adminChk.checked);
2562 });
2563 }
2518 permDiv.appendChild(row);
2564 permDiv.appendChild(row);
2519 }
2565 }
2566
2567 syncAllReadWriteConstraints();
2568 adminChk.addEventListener('change', syncAllReadWriteConstraints);
2520 }
2569 }
2521
2570
2522 document.getElementById('user-form').onsubmit = async (e) =>
2571 document.getElementById('user-form').onsubmit = async (e) =>
@@ -2565,6 +2614,7 @@ const AUDIO_EXTS = new Set(['mp3', 'ogg', 'wav', 'flac', 'aac', 'm4a']);
2565const DOC_EXTS = new Set(['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']);
2614const DOC_EXTS = new Set(['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']);
2566const CODE_EXTS = new Set(['js', 'ts', 'py', 'rb', 'go', 'rs', 'c', 'cpp', 'h', 'cs', 'java', 'php', 'html', 'css', 'json', 'xml', 'yaml', 'yml', 'sh', 'bash', 'md', 'txt']);
2615const CODE_EXTS = new Set(['js', 'ts', 'py', 'rb', 'go', 'rs', 'c', 'cpp', 'h', 'cs', 'java', 'php', 'html', 'css', 'json', 'xml', 'yaml', 'yml', 'sh', 'bash', 'md', 'txt']);
2567const ARCHIVE_EXTS = new Set(['zip', 'tar', 'gz', 'bz2', 'xz', 'rar', '7z']);
2616const ARCHIVE_EXTS = new Set(['zip', 'tar', 'gz', 'bz2', 'xz', 'rar', '7z']);
2617const MAX_DIRECT_SVG_THUMB_BYTES = 1024 * 1024;
2568
2618
2569function iconFolder (size = 52)
2619function iconFolder (size = 52)
2570{
2620{
@@ -2791,7 +2841,16 @@ async function loadOneThumbnail (iconEl)
2791 }
2841 }
2792 else if (kind === 'image')
2842 else if (kind === 'image')
2793 {
2843 {
2794 const url = `/api/files/thumbnail?file=${encodeURIComponent(filePath)}`;
2844 const ext = extOf(item.name || '');
2845 const useDirectSvg =
2846 ext === 'svg' &&
2847 typeof item.size === 'number' &&
2848 item.size > 0 &&
2849 item.size <= MAX_DIRECT_SVG_THUMB_BYTES;
2850
2851 const url = useDirectSvg
2852 ? `/api/files/download?file=${encodeURIComponent(filePath)}`
2853 : `/api/files/thumbnail?file=${encodeURIComponent(filePath)}`;
2795
2854
2796 let res;
2855 let res;
2797 try
2856 try
@@ -2807,7 +2866,7 @@ async function loadOneThumbnail (iconEl)
2807 return;
2866 return;
2808 }
2867 }
2809
2868
2810 if (res.status === 404)
2869 if (!useDirectSvg && res.status === 404)
2811 {
2870 {
2812 setThumbnailPending(iconEl, true);
2871 setThumbnailPending(iconEl, true);
2813 return;
2872 return;
public/style.css +1 −0
@@ -679,6 +679,7 @@ button.danger:hover {
679 679 font: 0.85rem/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
680 680 overflow: auto;
681 681 white-space: pre;
682 text-align: left;
682 683 }
683 684
684 685 .preview-code .tok-comment {
@@ -679,6 +679,7 @@ button.danger:hover {
679 font: 0.85rem/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
679 font: 0.85rem/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
680 overflow: auto;
680 overflow: auto;
681 white-space: pre;
681 white-space: pre;
682 text-align: left;
682}
683}
683
684
684.preview-code .tok-comment {
685.preview-code .tok-comment {
tests/page.load.test.js +111 −0
@@ -18,6 +18,10 @@ describe('page load smoke test', () =>
18 18 let meFixture;
19 19 let thumbnailStatusFixture;
20 20 let rootAccessFixture;
21 let adminUsersFixture;
22 let adminConfigFixture;
23 let downloadFixture;
24 const openDoms = [];
21 25
22 26 beforeEach(() =>
23 27 {
@@ -39,6 +43,9 @@ describe('page load smoke test', () =>
39 43 meFixture = { username: 'tester', isAdmin: false, permissions: {} };
40 44 thumbnailStatusFixture = {};
41 45 rootAccessFixture = {};
46 adminUsersFixture = { users: [] };
47 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
48 downloadFixture = {};
42 49 });
43 50
44 51 beforeAll(async () =>
@@ -76,11 +83,23 @@ describe('page load smoke test', () =>
76 83 }
77 84 res.type('image/webp').send('thumb');
78 85 });
86 app.get('/api/files/download', (req, res) =>
87 {
88 const file = String(req.query.file || '');
89 const payload = downloadFixture[file];
90 if (!payload)
91 {
92 return res.status(404).json({ error: 'File not found.' });
93 }
94 res.type(payload.type || 'application/octet-stream').send(payload.body || 'x');
95 });
79 96 app.get('/api/files/root-access', (req, res) =>
80 97 {
81 98 const rootPath = String(req.query.rootPath || '');
82 99 res.json({ users: rootAccessFixture[rootPath] || [] });
83 100 });
101 app.get('/api/admin/config', (req, res) => res.json(adminConfigFixture));
102 app.get('/api/admin/users', (req, res) => res.json(adminUsersFixture));
84 103 app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
85 104 app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
86 105
@@ -92,6 +111,15 @@ describe('page load smoke test', () =>
92 111
93 112 afterAll(() => server.close());
94 113
114 afterEach(() =>
115 {
116 while (openDoms.length)
117 {
118 const dom = openDoms.pop();
119 try { dom.window.close(); } catch { /* ignore */ }
120 }
121 });
122
95 123 async function bootClient ({ mobile = false, savedSession } = {})
96 124 {
97 125 const virtualConsole = new VirtualConsole();
@@ -119,6 +147,9 @@ describe('page load smoke test', () =>
119 147 window.HTMLCanvasElement.prototype.getContext = () => null;
120 148 window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
121 149 window.scrollTo = () => { };
150 let blobCounter = 0;
151 window.URL.createObjectURL = () => `blob:mock-${blobCounter++}`;
152 window.URL.revokeObjectURL = () => { };
122 153
123 154 const defaultSaved = {
124 155 token: 'saved-token',
@@ -139,6 +170,8 @@ describe('page load smoke test', () =>
139 170 await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
140 171 await new Promise(resolve => dom.window.setTimeout(resolve, 100));
141 172
173 openDoms.push(dom);
174
142 175 return { dom, runtimeErrors };
143 176 }
144 177
@@ -341,4 +374,82 @@ describe('page load smoke test', () =>
341 374
342 375 dom.window.close();
343 376 });
377
378 test('admin user modal locks write checkbox while read is unchecked', async () =>
379 {
380 meFixture = { username: 'admin', isAdmin: true, permissions: {} };
381 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
382 adminUsersFixture = {
383 users: [
384 {
385 id: 9,
386 username: 'guest',
387 isAdmin: false,
388 permissions: { data: { read: false, write: true } },
389 },
390 ],
391 };
392
393 const { dom, runtimeErrors } = await bootClient();
394 expect(runtimeErrors).toEqual([]);
395
396 dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
397 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
398
399 const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
400 expect(editBtn).toBeTruthy();
401 editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
402 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
403
404 const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
405 const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
406 expect(readCb).toBeTruthy();
407 expect(writeCb).toBeTruthy();
408 expect(readCb.checked).toBe(false);
409 expect(writeCb.checked).toBe(false);
410 expect(writeCb.disabled).toBe(true);
411
412 readCb.checked = true;
413 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
414 expect(writeCb.disabled).toBe(false);
415
416 writeCb.checked = true;
417 readCb.checked = false;
418 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
419 expect(writeCb.checked).toBe(false);
420 expect(writeCb.disabled).toBe(true);
421
422 dom.window.close();
423 });
424
425 test('uses direct svg thumbnail when svg file is under 1MB', async () =>
426 {
427 listFixture = {
428 '/data': [
429 {
430 name: 'icon.svg',
431 path: '/data/icon.svg',
432 isDir: false,
433 size: 400 * 1024,
434 mtime: Date.now(),
435 },
436 ],
437 };
438 thumbnailStatusFixture['/data/icon.svg'] = 404;
439 downloadFixture['/data/icon.svg'] = {
440 type: 'image/svg+xml',
441 body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
442 };
443
444 const { dom, runtimeErrors } = await bootClient();
445 expect(runtimeErrors).toEqual([]);
446
447 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
448 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
449 expect(icon).toBeTruthy();
450 expect(icon.classList.contains('thumb-pending')).toBe(false);
451 expect(icon.dataset.thumbReady).toBe('1');
452
453 dom.window.close();
454 });
344 455 });
@@ -18,6 +18,10 @@ describe('page load smoke test', () =>
18 let meFixture;
18 let meFixture;
19 let thumbnailStatusFixture;
19 let thumbnailStatusFixture;
20 let rootAccessFixture;
20 let rootAccessFixture;
21 let adminUsersFixture;
22 let adminConfigFixture;
23 let downloadFixture;
24 const openDoms = [];
21
25
22 beforeEach(() =>
26 beforeEach(() =>
23 {
27 {
@@ -39,6 +43,9 @@ describe('page load smoke test', () =>
39 meFixture = { username: 'tester', isAdmin: false, permissions: {} };
43 meFixture = { username: 'tester', isAdmin: false, permissions: {} };
40 thumbnailStatusFixture = {};
44 thumbnailStatusFixture = {};
41 rootAccessFixture = {};
45 rootAccessFixture = {};
46 adminUsersFixture = { users: [] };
47 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
48 downloadFixture = {};
42 });
49 });
43
50
44 beforeAll(async () =>
51 beforeAll(async () =>
@@ -76,11 +83,23 @@ describe('page load smoke test', () =>
76 }
83 }
77 res.type('image/webp').send('thumb');
84 res.type('image/webp').send('thumb');
78 });
85 });
86 app.get('/api/files/download', (req, res) =>
87 {
88 const file = String(req.query.file || '');
89 const payload = downloadFixture[file];
90 if (!payload)
91 {
92 return res.status(404).json({ error: 'File not found.' });
93 }
94 res.type(payload.type || 'application/octet-stream').send(payload.body || 'x');
95 });
79 app.get('/api/files/root-access', (req, res) =>
96 app.get('/api/files/root-access', (req, res) =>
80 {
97 {
81 const rootPath = String(req.query.rootPath || '');
98 const rootPath = String(req.query.rootPath || '');
82 res.json({ users: rootAccessFixture[rootPath] || [] });
99 res.json({ users: rootAccessFixture[rootPath] || [] });
83 });
100 });
101 app.get('/api/admin/config', (req, res) => res.json(adminConfigFixture));
102 app.get('/api/admin/users', (req, res) => res.json(adminUsersFixture));
84 app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
103 app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
85 app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
104 app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
86
105
@@ -92,6 +111,15 @@ describe('page load smoke test', () =>
92
111
93 afterAll(() => server.close());
112 afterAll(() => server.close());
94
113
114 afterEach(() =>
115 {
116 while (openDoms.length)
117 {
118 const dom = openDoms.pop();
119 try { dom.window.close(); } catch { /* ignore */ }
120 }
121 });
122
95 async function bootClient ({ mobile = false, savedSession } = {})
123 async function bootClient ({ mobile = false, savedSession } = {})
96 {
124 {
97 const virtualConsole = new VirtualConsole();
125 const virtualConsole = new VirtualConsole();
@@ -119,6 +147,9 @@ describe('page load smoke test', () =>
119 window.HTMLCanvasElement.prototype.getContext = () => null;
147 window.HTMLCanvasElement.prototype.getContext = () => null;
120 window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
148 window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
121 window.scrollTo = () => { };
149 window.scrollTo = () => { };
150 let blobCounter = 0;
151 window.URL.createObjectURL = () => `blob:mock-${blobCounter++}`;
152 window.URL.revokeObjectURL = () => { };
122
153
123 const defaultSaved = {
154 const defaultSaved = {
124 token: 'saved-token',
155 token: 'saved-token',
@@ -139,6 +170,8 @@ describe('page load smoke test', () =>
139 await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
170 await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
140 await new Promise(resolve => dom.window.setTimeout(resolve, 100));
171 await new Promise(resolve => dom.window.setTimeout(resolve, 100));
141
172
173 openDoms.push(dom);
174
142 return { dom, runtimeErrors };
175 return { dom, runtimeErrors };
143 }
176 }
144
177
@@ -341,4 +374,82 @@ describe('page load smoke test', () =>
341
374
342 dom.window.close();
375 dom.window.close();
343 });
376 });
377
378 test('admin user modal locks write checkbox while read is unchecked', async () =>
379 {
380 meFixture = { username: 'admin', isAdmin: true, permissions: {} };
381 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
382 adminUsersFixture = {
383 users: [
384 {
385 id: 9,
386 username: 'guest',
387 isAdmin: false,
388 permissions: { data: { read: false, write: true } },
389 },
390 ],
391 };
392
393 const { dom, runtimeErrors } = await bootClient();
394 expect(runtimeErrors).toEqual([]);
395
396 dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
397 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
398
399 const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
400 expect(editBtn).toBeTruthy();
401 editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
402 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
403
404 const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
405 const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
406 expect(readCb).toBeTruthy();
407 expect(writeCb).toBeTruthy();
408 expect(readCb.checked).toBe(false);
409 expect(writeCb.checked).toBe(false);
410 expect(writeCb.disabled).toBe(true);
411
412 readCb.checked = true;
413 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
414 expect(writeCb.disabled).toBe(false);
415
416 writeCb.checked = true;
417 readCb.checked = false;
418 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
419 expect(writeCb.checked).toBe(false);
420 expect(writeCb.disabled).toBe(true);
421
422 dom.window.close();
423 });
424
425 test('uses direct svg thumbnail when svg file is under 1MB', async () =>
426 {
427 listFixture = {
428 '/data': [
429 {
430 name: 'icon.svg',
431 path: '/data/icon.svg',
432 isDir: false,
433 size: 400 * 1024,
434 mtime: Date.now(),
435 },
436 ],
437 };
438 thumbnailStatusFixture['/data/icon.svg'] = 404;
439 downloadFixture['/data/icon.svg'] = {
440 type: 'image/svg+xml',
441 body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
442 };
443
444 const { dom, runtimeErrors } = await bootClient();
445 expect(runtimeErrors).toEqual([]);
446
447 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
448 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
449 expect(icon).toBeTruthy();
450 expect(icon.classList.contains('thumb-pending')).toBe(false);
451 expect(icon.dataset.thumbReady).toBe('1');
452
453 dom.window.close();
454 });
344});
455});