BlueGit

timfa filemanager

feat: add Share button to expanded file preview

timfa Tim Falken · pushed by timfa

Authored 2026-05-07 · 6 months ago

Hash
d51f946ef6783cb7a13f4f912f91f1daffae88d6
Parent
8a66a2b5
4 files changed +926 −862
.github/technical-reference.md +3 −0
@@ -132,6 +132,7 @@
132 132 - animateRect(el, fromRect, toRect, opts) - Helper that animates element rectangle (left/top/width/height) for expand/collapse transitions.
133 133 - openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents the real file tile to body, expands it to viewport preview, injects close/download controls.
134 134 - openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents tile to body, shows spinner during expand animation, renders content after animation; applies file-type accent colour to tile border and outline glow.
135 - openExpandedTilePreview(item, tileEl, sourceSvgEl, loadPreviewContent) - Adds preview action buttons for Download and Share; Share opens the same modal flow as sidebar sharing.
135 136 - closeExpandedTilePreview() - Collapses expanded tile preview back to original grid position and restores original icon markup.
136 137 - closePreview() - Closes either expanded-tile preview or overlay preview, then revokes active preview object URL.
137 138 - closePreview() - Closes expanded-tile preview and revokes active preview object URL.
@@ -169,6 +170,7 @@
169 170 - @keyframes drag-rise-spin-fall - Real tile rises, spins, falls/scales into folder on drop.
170 171 - @keyframes folder-bounce - Target folder bounces down then back on accept.
171 172 - .preview-backdrop/.file-item--preview/.preview-expand-* - In-place expanded tile preview styling (no separate overlay window), including preserved icon-outline layer.
173 - .preview-expand-share - Secondary action button positioned next to .preview-expand-download in expanded file preview.
172 174 - .move-modal/.move-tree/.move-node* - Move To tree picker styles with expandable/collapsible folder hierarchy.
173 175
174 176 ## tests/auth.routes.test.js
@@ -178,3 +180,4 @@
178 180 ## tests/page.load.test.js
179 181 - bootClient() - Boots the app in jsdom and waits until app shell is visible or timeout before assertions.
180 182 - waitFor(dom, predicate, timeoutMs) - Poll helper used by interaction tests to wait for rendered tiles.
183 - expanded file preview shows a Share button next to Download - Verifies expanded preview UI includes both actions for file sharing and downloading.
@@ -132,6 +132,7 @@
132- animateRect(el, fromRect, toRect, opts) - Helper that animates element rectangle (left/top/width/height) for expand/collapse transitions.
132- animateRect(el, fromRect, toRect, opts) - Helper that animates element rectangle (left/top/width/height) for expand/collapse transitions.
133- openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents the real file tile to body, expands it to viewport preview, injects close/download controls.
133- openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents the real file tile to body, expands it to viewport preview, injects close/download controls.
134- openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents tile to body, shows spinner during expand animation, renders content after animation; applies file-type accent colour to tile border and outline glow.
134- openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents tile to body, shows spinner during expand animation, renders content after animation; applies file-type accent colour to tile border and outline glow.
135- openExpandedTilePreview(item, tileEl, sourceSvgEl, loadPreviewContent) - Adds preview action buttons for Download and Share; Share opens the same modal flow as sidebar sharing.
135- closeExpandedTilePreview() - Collapses expanded tile preview back to original grid position and restores original icon markup.
136- closeExpandedTilePreview() - Collapses expanded tile preview back to original grid position and restores original icon markup.
136- closePreview() - Closes either expanded-tile preview or overlay preview, then revokes active preview object URL.
137- closePreview() - Closes either expanded-tile preview or overlay preview, then revokes active preview object URL.
137- closePreview() - Closes expanded-tile preview and revokes active preview object URL.
138- closePreview() - Closes expanded-tile preview and revokes active preview object URL.
@@ -169,6 +170,7 @@
169- @keyframes drag-rise-spin-fall - Real tile rises, spins, falls/scales into folder on drop.
170- @keyframes drag-rise-spin-fall - Real tile rises, spins, falls/scales into folder on drop.
170- @keyframes folder-bounce - Target folder bounces down then back on accept.
171- @keyframes folder-bounce - Target folder bounces down then back on accept.
171- .preview-backdrop/.file-item--preview/.preview-expand-* - In-place expanded tile preview styling (no separate overlay window), including preserved icon-outline layer.
172- .preview-backdrop/.file-item--preview/.preview-expand-* - In-place expanded tile preview styling (no separate overlay window), including preserved icon-outline layer.
173- .preview-expand-share - Secondary action button positioned next to .preview-expand-download in expanded file preview.
172- .move-modal/.move-tree/.move-node* - Move To tree picker styles with expandable/collapsible folder hierarchy.
174- .move-modal/.move-tree/.move-node* - Move To tree picker styles with expandable/collapsible folder hierarchy.
173
175
174## tests/auth.routes.test.js
176## tests/auth.routes.test.js
@@ -178,3 +180,4 @@
178## tests/page.load.test.js
180## tests/page.load.test.js
179- bootClient() - Boots the app in jsdom and waits until app shell is visible or timeout before assertions.
181- bootClient() - Boots the app in jsdom and waits until app shell is visible or timeout before assertions.
180- waitFor(dom, predicate, timeoutMs) - Poll helper used by interaction tests to wait for rendered tiles.
182- waitFor(dom, predicate, timeoutMs) - Poll helper used by interaction tests to wait for rendered tiles.
183- expanded file preview shows a Share button next to Download - Verifies expanded preview UI includes both actions for file sharing and downloading.
public/app.js +13 −0
@@ -2222,6 +2222,16 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, loadPreviewCo
2222 2222 triggerDownload(item.name, STATE.previewObjectUrl);
2223 2223 });
2224 2224
2225 const shareBtn = document.createElement('button');
2226 shareBtn.className = 'preview-expand-share';
2227 shareBtn.type = 'button';
2228 shareBtn.textContent = 'Share';
2229 shareBtn.addEventListener('click', (e) =>
2230 {
2231 e.stopPropagation();
2232 openShareModal(item);
2233 });
2234
2225 2235 iconEl.innerHTML = '';
2226 2236
2227 2237 if (originalIconSvg)
@@ -2243,6 +2253,7 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, loadPreviewCo
2243 2253 tileEl.insertBefore(titleEl, tileEl.firstChild);
2244 2254 tileEl.appendChild(closeBtn);
2245 2255 tileEl.appendChild(dlBtn);
2256 tileEl.appendChild(shareBtn);
2246 2257
2247 2258 STATE.previewExpandState = {
2248 2259 item,
@@ -2256,6 +2267,7 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, loadPreviewCo
2256 2267 backdrop,
2257 2268 closeBtn,
2258 2269 dlBtn,
2270 shareBtn,
2259 2271 titleEl,
2260 2272 previewMount,
2261 2273 startRect,
@@ -2321,6 +2333,7 @@ async function closeExpandedTilePreview ()
2321 2333 if (st.titleEl) st.titleEl.remove();
2322 2334 if (st.closeBtn) st.closeBtn.remove();
2323 2335 if (st.dlBtn) st.dlBtn.remove();
2336 if (st.shareBtn) st.shareBtn.remove();
2324 2337 if (st.iconEl) st.iconEl.innerHTML = st.iconHtml;
2325 2338 if (st.nameEl) st.nameEl.style.display = '';
2326 2339
@@ -2222,6 +2222,16 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, loadPreviewCo
2222 triggerDownload(item.name, STATE.previewObjectUrl);
2222 triggerDownload(item.name, STATE.previewObjectUrl);
2223 });
2223 });
2224
2224
2225 const shareBtn = document.createElement('button');
2226 shareBtn.className = 'preview-expand-share';
2227 shareBtn.type = 'button';
2228 shareBtn.textContent = 'Share';
2229 shareBtn.addEventListener('click', (e) =>
2230 {
2231 e.stopPropagation();
2232 openShareModal(item);
2233 });
2234
2225 iconEl.innerHTML = '';
2235 iconEl.innerHTML = '';
2226
2236
2227 if (originalIconSvg)
2237 if (originalIconSvg)
@@ -2243,6 +2253,7 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, loadPreviewCo
2243 tileEl.insertBefore(titleEl, tileEl.firstChild);
2253 tileEl.insertBefore(titleEl, tileEl.firstChild);
2244 tileEl.appendChild(closeBtn);
2254 tileEl.appendChild(closeBtn);
2245 tileEl.appendChild(dlBtn);
2255 tileEl.appendChild(dlBtn);
2256 tileEl.appendChild(shareBtn);
2246
2257
2247 STATE.previewExpandState = {
2258 STATE.previewExpandState = {
2248 item,
2259 item,
@@ -2256,6 +2267,7 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, loadPreviewCo
2256 backdrop,
2267 backdrop,
2257 closeBtn,
2268 closeBtn,
2258 dlBtn,
2269 dlBtn,
2270 shareBtn,
2259 titleEl,
2271 titleEl,
2260 previewMount,
2272 previewMount,
2261 startRect,
2273 startRect,
@@ -2321,6 +2333,7 @@ async function closeExpandedTilePreview ()
2321 if (st.titleEl) st.titleEl.remove();
2333 if (st.titleEl) st.titleEl.remove();
2322 if (st.closeBtn) st.closeBtn.remove();
2334 if (st.closeBtn) st.closeBtn.remove();
2323 if (st.dlBtn) st.dlBtn.remove();
2335 if (st.dlBtn) st.dlBtn.remove();
2336 if (st.shareBtn) st.shareBtn.remove();
2324 if (st.iconEl) st.iconEl.innerHTML = st.iconHtml;
2337 if (st.iconEl) st.iconEl.innerHTML = st.iconHtml;
2325 if (st.nameEl) st.nameEl.style.display = '';
2338 if (st.nameEl) st.nameEl.style.display = '';
2326
2339
public/drag-move.css +358 −337
@@ -1,337 +1,358 @@
1 /* =========================================================
2 DRAG-MOVE & ICON PREVIEW — real-icon lift styles
3 ========================================================= */
4
5 /* Item being actively dragged: lifted shadow + accent border */
6 .file-item.dragging {
7 box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
8 border-color: var(--accent, #5b7fff) !important;
9 z-index: 9999;
10 cursor: grabbing !important;
11 }
12
13 /* Folder highlighted while a dragged item hovers over it */
14 .file-item.drop-target .icon {
15 filter: drop-shadow(0 0 6px var(--accent, #5b7fff)) brightness(1.25);
16 }
17
18 .drag-parent-target {
19 position: fixed;
20 left: 16px;
21 top: 68px;
22 z-index: 10002;
23 display: inline-flex;
24 align-items: center;
25 gap: 0.45rem;
26 padding: 0.45rem 0.65rem;
27 border: 1px solid var(--border, #2e3247);
28 border-radius: 8px;
29 background: var(--surface, #1a1d27);
30 color: var(--text, #e8eaf0);
31 pointer-events: auto;
32 user-select: none;
33 box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
34 }
35
36 .drag-parent-target .up {
37 color: var(--accent, #5b7fff);
38 font-weight: 700;
39 }
40
41 .drag-parent-target .label {
42 font-size: 0.82rem;
43 }
44
45 .drag-parent-target.active {
46 border-color: var(--accent, #5b7fff);
47 box-shadow: 0 0 0 2px rgba(91, 127, 255, 0.22), 0 8px 20px rgba(0, 0, 0, 0.5);
48 }
49
50 .crumb-drop-target.active {
51 color: var(--accent, #5b7fff) !important;
52 text-decoration: underline;
53 text-underline-offset: 0.2rem;
54 }
55
56 /* ---- drop animation: rises, spins, falls into folder ---- */
57 /* --dx / --dy : current viewport X/Y of the item when released */
58 /* --fall-x / --fall-y : viewport position of the target folder */
59 @keyframes drag-rise-spin-fall {
60 0% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(0deg); opacity: 1; }
61 20% { transform: translate(var(--dx), calc(var(--dy) - 40px)) scale(1.05) rotate(60deg); opacity: 1; }
62 60% { transform: translate(var(--fall-x), calc(var(--fall-y) - 20px)) scale(0.5) rotate(200deg); opacity: 0.9; }
63 100% { transform: translate(var(--fall-x), var(--fall-y)) scale(0.05) rotate(360deg); opacity: 0; }
64 }
65
66 .file-item.dropping {
67 animation: drag-rise-spin-fall 0.45s cubic-bezier(0.4, 0, 0.8, 1) forwards;
68 pointer-events: none;
69 }
70
71 /* ---- bounce animation on the target folder ---- */
72 @keyframes folder-bounce {
73 0% { transform: translateY(0); }
74 30% { transform: translateY(8px); }
75 65% { transform: translateY(-4px); }
76 85% { transform: translateY(2px); }
77 100% { transform: translateY(0); }
78 }
79
80 .file-item.folder-bounce {
81 animation: folder-bounce 0.4s ease-out forwards;
82 }
83
84 /* =========================================================
85 EXPANDED PREVIEW TILE
86 The real .file-item element scales up in place to fill the
87 viewport — no separate overlay.
88 ========================================================= */
89
90 /* Dimming backdrop behind the expanded tile */
91 .preview-backdrop {
92 position: fixed;
93 inset: 0;
94 z-index: 9999;
95 background: rgba(8, 9, 14, 0.82);
96 opacity: 0;
97 transition: opacity 0.3s ease;
98 pointer-events: none;
99 }
100
101 .preview-backdrop.visible {
102 opacity: 1;
103 pointer-events: all;
104 }
105
106 /* .file-item in expanded preview state */
107 .file-item.file-item--preview {
108 background: var(--surface, #1a1d27) !important;
109 border: 2px solid var(--preview-accent, var(--border, #2e3247)) !important;
110 border-radius: 12px !important;
111 cursor: default !important;
112 user-select: text;
113 display: flex !important;
114 flex-direction: column !important;
115 overflow: hidden;
116 padding: 0 !important;
117 gap: 0 !important;
118 z-index: 10000;
119 }
120
121 .file-item.file-item--preview .icon {
122 width: 100% !important;
123 height: auto !important;
124 position: relative;
125 flex: 1;
126 min-height: 0;
127 display: flex !important;
128 align-items: center;
129 justify-content: center;
130 overflow: auto;
131 padding: 1rem;
132 box-sizing: border-box;
133 }
134
135 .file-item.file-item--preview .icon .preview-expand-outline {
136 position: absolute;
137 left: 50%;
138 top: 50%;
139 width: min(72%, 640px);
140 height: min(72%, 640px);
141 transform: translate(-50%, -50%);
142 opacity: 0.18;
143 pointer-events: none;
144 z-index: 1;
145 filter: drop-shadow(0 0 10px var(--preview-accent, transparent));
146 }
147
148 .file-item.file-item--preview .icon .preview-expand-content {
149 position: relative;
150 z-index: 2;
151 width: 100%;
152 height: 100%;
153 display: flex;
154 align-items: center;
155 justify-content: center;
156 }
157
158 /* Keep preview media constrained within the expanded icon */
159 .file-item.file-item--preview .icon .preview-media {
160 max-width: 100%;
161 max-height: 100%;
162 width: auto;
163 height: auto;
164 object-fit: contain;
165 }
166
167 .file-item.file-item--preview .icon .preview-frame {
168 width: 100%;
169 height: 100%;
170 border: none;
171 border-radius: 8px;
172 background: #fff;
173 }
174
175 .file-item.file-item--preview .icon .preview-text {
176 width: 100%;
177 min-height: auto;
178 flex: 1;
179 align-self: stretch;
180 }
181
182 .file-item.file-item--preview .icon .preview-audio {
183 width: min(640px, 95%);
184 }
185
186 .file-item.file-item--preview .icon .preview-unsupported {
187 color: var(--text-muted);
188 font-size: 0.95rem;
189 max-width: 56ch;
190 text-align: center;
191 }
192
193 /* Filename bar shown at top of expanded preview */
194 .preview-expand-title {
195 padding: 0.7rem 3.5rem 0.7rem 1rem;
196 font-size: 0.95rem;
197 color: var(--text);
198 border-bottom: 1px solid var(--border);
199 white-space: nowrap;
200 overflow: hidden;
201 text-overflow: ellipsis;
202 flex-shrink: 0;
203 }
204
205 /* Close button (×) — top-right corner */
206 .preview-expand-close {
207 position: absolute;
208 top: 8px;
209 right: 8px;
210 width: 30px;
211 height: 30px;
212 background: rgba(20, 25, 40, 0.8);
213 color: #d6deef;
214 border: 1px solid rgba(255, 255, 255, 0.15);
215 border-radius: 50%;
216 cursor: pointer;
217 font-size: 1.2rem;
218 z-index: 10001;
219 display: flex;
220 align-items: center;
221 justify-content: center;
222 line-height: 1;
223 padding: 0;
224 transition: background 0.15s ease;
225 flex-shrink: 0;
226 }
227
228 .preview-expand-close:hover {
229 background: rgba(255, 255, 255, 0.14);
230 }
231
232 /* Download button — bottom-right corner */
233 .preview-expand-download {
234 position: absolute;
235 bottom: 14px;
236 right: 14px;
237 background: var(--accent, #5b7fff);
238 color: #fff;
239 border: none;
240 border-radius: 6px;
241 padding: 7px 18px;
242 cursor: pointer;
243 font-size: 0.9rem;
244 z-index: 10001;
245 transition: opacity 0.15s ease;
246 flex-shrink: 0;
247 }
248
249 .preview-expand-download:hover {
250 opacity: 0.85;
251 }
252
253 /* Spinner shown inside the expanded tile while content is loading */
254 .preview-loading-spinner {
255 width: 40px;
256 height: 40px;
257 border: 3px solid rgba(255, 255, 255, 0.12);
258 border-top-color: rgba(255, 255, 255, 0.7);
259 border-radius: 50%;
260 animation: preview-spin 0.7s linear infinite;
261 }
262
263 @keyframes preview-spin {
264 to { transform: rotate(360deg); }
265 }
266
267 .move-modal {
268 width: min(92vw, 760px);
269 max-height: min(86vh, 760px);
270 display: flex;
271 flex-direction: column;
272 gap: 0.6rem;
273 }
274
275 .move-tree {
276 border: 1px solid var(--border, #2e3247);
277 border-radius: 10px;
278 padding: 0.55rem;
279 max-height: min(58vh, 480px);
280 overflow: auto;
281 background: var(--bg, #0f1117);
282 }
283
284 .move-node {
285 margin-left: 0.25rem;
286 }
287
288 .move-node-row {
289 display: flex;
290 align-items: center;
291 gap: 0.35rem;
292 margin: 0.14rem 0;
293 }
294
295 .move-toggle {
296 width: 26px;
297 min-width: 26px;
298 height: 26px;
299 padding: 0;
300 display: inline-flex;
301 align-items: center;
302 justify-content: center;
303 }
304
305 .move-node-label {
306 display: inline-flex;
307 align-items: center;
308 justify-content: flex-start;
309 min-height: 28px;
310 width: auto;
311 padding: 0.2rem 0.5rem;
312 background: transparent;
313 border: 1px solid transparent;
314 color: var(--text, #e8eaf0);
315 }
316
317 .move-node-label:hover {
318 border-color: var(--border, #2e3247);
319 background: rgba(255, 255, 255, 0.03);
320 }
321
322 .move-node-label.selected {
323 border-color: var(--accent, #5b7fff);
324 background: rgba(91, 127, 255, 0.12);
325 }
326
327 .move-children {
328 margin-left: 1.2rem;
329 border-left: 1px dashed var(--border, #2e3247);
330 padding-left: 0.5rem;
331 }
332
333 .move-empty {
334 color: var(--text-muted, #7880a0);
335 font-size: 0.85rem;
336 margin: 0.2rem 0 0.4rem 0.2rem;
337 }
1 /* =========================================================
2 DRAG-MOVE & ICON PREVIEW — real-icon lift styles
3 ========================================================= */
4
5 /* Item being actively dragged: lifted shadow + accent border */
6 .file-item.dragging {
7 box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
8 border-color: var(--accent, #5b7fff) !important;
9 z-index: 9999;
10 cursor: grabbing !important;
11 }
12
13 /* Folder highlighted while a dragged item hovers over it */
14 .file-item.drop-target .icon {
15 filter: drop-shadow(0 0 6px var(--accent, #5b7fff)) brightness(1.25);
16 }
17
18 .drag-parent-target {
19 position: fixed;
20 left: 16px;
21 top: 68px;
22 z-index: 10002;
23 display: inline-flex;
24 align-items: center;
25 gap: 0.45rem;
26 padding: 0.45rem 0.65rem;
27 border: 1px solid var(--border, #2e3247);
28 border-radius: 8px;
29 background: var(--surface, #1a1d27);
30 color: var(--text, #e8eaf0);
31 pointer-events: auto;
32 user-select: none;
33 box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
34 }
35
36 .drag-parent-target .up {
37 color: var(--accent, #5b7fff);
38 font-weight: 700;
39 }
40
41 .drag-parent-target .label {
42 font-size: 0.82rem;
43 }
44
45 .drag-parent-target.active {
46 border-color: var(--accent, #5b7fff);
47 box-shadow: 0 0 0 2px rgba(91, 127, 255, 0.22), 0 8px 20px rgba(0, 0, 0, 0.5);
48 }
49
50 .crumb-drop-target.active {
51 color: var(--accent, #5b7fff) !important;
52 text-decoration: underline;
53 text-underline-offset: 0.2rem;
54 }
55
56 /* ---- drop animation: rises, spins, falls into folder ---- */
57 /* --dx / --dy : current viewport X/Y of the item when released */
58 /* --fall-x / --fall-y : viewport position of the target folder */
59 @keyframes drag-rise-spin-fall {
60 0% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(0deg); opacity: 1; }
61 20% { transform: translate(var(--dx), calc(var(--dy) - 40px)) scale(1.05) rotate(60deg); opacity: 1; }
62 60% { transform: translate(var(--fall-x), calc(var(--fall-y) - 20px)) scale(0.5) rotate(200deg); opacity: 0.9; }
63 100% { transform: translate(var(--fall-x), var(--fall-y)) scale(0.05) rotate(360deg); opacity: 0; }
64 }
65
66 .file-item.dropping {
67 animation: drag-rise-spin-fall 0.45s cubic-bezier(0.4, 0, 0.8, 1) forwards;
68 pointer-events: none;
69 }
70
71 /* ---- bounce animation on the target folder ---- */
72 @keyframes folder-bounce {
73 0% { transform: translateY(0); }
74 30% { transform: translateY(8px); }
75 65% { transform: translateY(-4px); }
76 85% { transform: translateY(2px); }
77 100% { transform: translateY(0); }
78 }
79
80 .file-item.folder-bounce {
81 animation: folder-bounce 0.4s ease-out forwards;
82 }
83
84 /* =========================================================
85 EXPANDED PREVIEW TILE
86 The real .file-item element scales up in place to fill the
87 viewport — no separate overlay.
88 ========================================================= */
89
90 /* Dimming backdrop behind the expanded tile */
91 .preview-backdrop {
92 position: fixed;
93 inset: 0;
94 z-index: 9999;
95 background: rgba(8, 9, 14, 0.82);
96 opacity: 0;
97 transition: opacity 0.3s ease;
98 pointer-events: none;
99 }
100
101 .preview-backdrop.visible {
102 opacity: 1;
103 pointer-events: all;
104 }
105
106 /* .file-item in expanded preview state */
107 .file-item.file-item--preview {
108 background: var(--surface, #1a1d27) !important;
109 border: 2px solid var(--preview-accent, var(--border, #2e3247)) !important;
110 border-radius: 12px !important;
111 cursor: default !important;
112 user-select: text;
113 display: flex !important;
114 flex-direction: column !important;
115 overflow: hidden;
116 padding: 0 !important;
117 gap: 0 !important;
118 z-index: 10000;
119 }
120
121 .file-item.file-item--preview .icon {
122 width: 100% !important;
123 height: auto !important;
124 position: relative;
125 flex: 1;
126 min-height: 0;
127 display: flex !important;
128 align-items: center;
129 justify-content: center;
130 overflow: auto;
131 padding: 1rem;
132 box-sizing: border-box;
133 }
134
135 .file-item.file-item--preview .icon .preview-expand-outline {
136 position: absolute;
137 left: 50%;
138 top: 50%;
139 width: min(72%, 640px);
140 height: min(72%, 640px);
141 transform: translate(-50%, -50%);
142 opacity: 0.18;
143 pointer-events: none;
144 z-index: 1;
145 filter: drop-shadow(0 0 10px var(--preview-accent, transparent));
146 }
147
148 .file-item.file-item--preview .icon .preview-expand-content {
149 position: relative;
150 z-index: 2;
151 width: 100%;
152 height: 100%;
153 display: flex;
154 align-items: center;
155 justify-content: center;
156 }
157
158 /* Keep preview media constrained within the expanded icon */
159 .file-item.file-item--preview .icon .preview-media {
160 max-width: 100%;
161 max-height: 100%;
162 width: auto;
163 height: auto;
164 object-fit: contain;
165 }
166
167 .file-item.file-item--preview .icon .preview-frame {
168 width: 100%;
169 height: 100%;
170 border: none;
171 border-radius: 8px;
172 background: #fff;
173 }
174
175 .file-item.file-item--preview .icon .preview-text {
176 width: 100%;
177 min-height: auto;
178 flex: 1;
179 align-self: stretch;
180 }
181
182 .file-item.file-item--preview .icon .preview-audio {
183 width: min(640px, 95%);
184 }
185
186 .file-item.file-item--preview .icon .preview-unsupported {
187 color: var(--text-muted);
188 font-size: 0.95rem;
189 max-width: 56ch;
190 text-align: center;
191 }
192
193 /* Filename bar shown at top of expanded preview */
194 .preview-expand-title {
195 padding: 0.7rem 3.5rem 0.7rem 1rem;
196 font-size: 0.95rem;
197 color: var(--text);
198 border-bottom: 1px solid var(--border);
199 white-space: nowrap;
200 overflow: hidden;
201 text-overflow: ellipsis;
202 flex-shrink: 0;
203 }
204
205 /* Close button (×) — top-right corner */
206 .preview-expand-close {
207 position: absolute;
208 top: 8px;
209 right: 8px;
210 width: 30px;
211 height: 30px;
212 background: rgba(20, 25, 40, 0.8);
213 color: #d6deef;
214 border: 1px solid rgba(255, 255, 255, 0.15);
215 border-radius: 50%;
216 cursor: pointer;
217 font-size: 1.2rem;
218 z-index: 10001;
219 display: flex;
220 align-items: center;
221 justify-content: center;
222 line-height: 1;
223 padding: 0;
224 transition: background 0.15s ease;
225 flex-shrink: 0;
226 }
227
228 .preview-expand-close:hover {
229 background: rgba(255, 255, 255, 0.14);
230 }
231
232 /* Download button — bottom-right corner */
233 .preview-expand-download {
234 position: absolute;
235 bottom: 14px;
236 right: 14px;
237 background: var(--accent, #5b7fff);
238 color: #fff;
239 border: none;
240 border-radius: 6px;
241 padding: 7px 18px;
242 cursor: pointer;
243 font-size: 0.9rem;
244 z-index: 10001;
245 transition: opacity 0.15s ease;
246 flex-shrink: 0;
247 }
248
249 .preview-expand-download:hover {
250 opacity: 0.85;
251 }
252
253 /* Share button — next to download button */
254 .preview-expand-share {
255 position: absolute;
256 bottom: 14px;
257 right: 112px;
258 background: rgba(20, 25, 40, 0.84);
259 color: #fff;
260 border: 1px solid rgba(255, 255, 255, 0.18);
261 border-radius: 6px;
262 padding: 7px 14px;
263 cursor: pointer;
264 font-size: 0.9rem;
265 z-index: 10001;
266 transition: opacity 0.15s ease;
267 flex-shrink: 0;
268 }
269
270 .preview-expand-share:hover {
271 opacity: 0.85;
272 }
273
274 /* Spinner shown inside the expanded tile while content is loading */
275 .preview-loading-spinner {
276 width: 40px;
277 height: 40px;
278 border: 3px solid rgba(255, 255, 255, 0.12);
279 border-top-color: rgba(255, 255, 255, 0.7);
280 border-radius: 50%;
281 animation: preview-spin 0.7s linear infinite;
282 }
283
284 @keyframes preview-spin {
285 to { transform: rotate(360deg); }
286 }
287
288 .move-modal {
289 width: min(92vw, 760px);
290 max-height: min(86vh, 760px);
291 display: flex;
292 flex-direction: column;
293 gap: 0.6rem;
294 }
295
296 .move-tree {
297 border: 1px solid var(--border, #2e3247);
298 border-radius: 10px;
299 padding: 0.55rem;
300 max-height: min(58vh, 480px);
301 overflow: auto;
302 background: var(--bg, #0f1117);
303 }
304
305 .move-node {
306 margin-left: 0.25rem;
307 }
308
309 .move-node-row {
310 display: flex;
311 align-items: center;
312 gap: 0.35rem;
313 margin: 0.14rem 0;
314 }
315
316 .move-toggle {
317 width: 26px;
318 min-width: 26px;
319 height: 26px;
320 padding: 0;
321 display: inline-flex;
322 align-items: center;
323 justify-content: center;
324 }
325
326 .move-node-label {
327 display: inline-flex;
328 align-items: center;
329 justify-content: flex-start;
330 min-height: 28px;
331 width: auto;
332 padding: 0.2rem 0.5rem;
333 background: transparent;
334 border: 1px solid transparent;
335 color: var(--text, #e8eaf0);
336 }
337
338 .move-node-label:hover {
339 border-color: var(--border, #2e3247);
340 background: rgba(255, 255, 255, 0.03);
341 }
342
343 .move-node-label.selected {
344 border-color: var(--accent, #5b7fff);
345 background: rgba(91, 127, 255, 0.12);
346 }
347
348 .move-children {
349 margin-left: 1.2rem;
350 border-left: 1px dashed var(--border, #2e3247);
351 padding-left: 0.5rem;
352 }
353
354 .move-empty {
355 color: var(--text-muted, #7880a0);
356 font-size: 0.85rem;
357 margin: 0.2rem 0 0.4rem 0.2rem;
358 }
@@ -1,337 +1,358 @@
1/* =========================================================
1/* =========================================================
2 DRAG-MOVE & ICON PREVIEW — real-icon lift styles
2 DRAG-MOVE & ICON PREVIEW — real-icon lift styles
3 ========================================================= */
3 ========================================================= */
4
4
5/* Item being actively dragged: lifted shadow + accent border */
5/* Item being actively dragged: lifted shadow + accent border */
6.file-item.dragging {
6.file-item.dragging {
7 box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
7 box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
8 border-color: var(--accent, #5b7fff) !important;
8 border-color: var(--accent, #5b7fff) !important;
9 z-index: 9999;
9 z-index: 9999;
10 cursor: grabbing !important;
10 cursor: grabbing !important;
11}
11}
12
12
13/* Folder highlighted while a dragged item hovers over it */
13/* Folder highlighted while a dragged item hovers over it */
14.file-item.drop-target .icon {
14.file-item.drop-target .icon {
15 filter: drop-shadow(0 0 6px var(--accent, #5b7fff)) brightness(1.25);
15 filter: drop-shadow(0 0 6px var(--accent, #5b7fff)) brightness(1.25);
16}
16}
17
17
18.drag-parent-target {
18.drag-parent-target {
19 position: fixed;
19 position: fixed;
20 left: 16px;
20 left: 16px;
21 top: 68px;
21 top: 68px;
22 z-index: 10002;
22 z-index: 10002;
23 display: inline-flex;
23 display: inline-flex;
24 align-items: center;
24 align-items: center;
25 gap: 0.45rem;
25 gap: 0.45rem;
26 padding: 0.45rem 0.65rem;
26 padding: 0.45rem 0.65rem;
27 border: 1px solid var(--border, #2e3247);
27 border: 1px solid var(--border, #2e3247);
28 border-radius: 8px;
28 border-radius: 8px;
29 background: var(--surface, #1a1d27);
29 background: var(--surface, #1a1d27);
30 color: var(--text, #e8eaf0);
30 color: var(--text, #e8eaf0);
31 pointer-events: auto;
31 pointer-events: auto;
32 user-select: none;
32 user-select: none;
33 box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
33 box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
34}
34}
35
35
36.drag-parent-target .up {
36.drag-parent-target .up {
37 color: var(--accent, #5b7fff);
37 color: var(--accent, #5b7fff);
38 font-weight: 700;
38 font-weight: 700;
39}
39}
40
40
41.drag-parent-target .label {
41.drag-parent-target .label {
42 font-size: 0.82rem;
42 font-size: 0.82rem;
43}
43}
44
44
45.drag-parent-target.active {
45.drag-parent-target.active {
46 border-color: var(--accent, #5b7fff);
46 border-color: var(--accent, #5b7fff);
47 box-shadow: 0 0 0 2px rgba(91, 127, 255, 0.22), 0 8px 20px rgba(0, 0, 0, 0.5);
47 box-shadow: 0 0 0 2px rgba(91, 127, 255, 0.22), 0 8px 20px rgba(0, 0, 0, 0.5);
48}
48}
49
49
50.crumb-drop-target.active {
50.crumb-drop-target.active {
51 color: var(--accent, #5b7fff) !important;
51 color: var(--accent, #5b7fff) !important;
52 text-decoration: underline;
52 text-decoration: underline;
53 text-underline-offset: 0.2rem;
53 text-underline-offset: 0.2rem;
54}
54}
55
55
56/* ---- drop animation: rises, spins, falls into folder ---- */
56/* ---- drop animation: rises, spins, falls into folder ---- */
57/* --dx / --dy : current viewport X/Y of the item when released */
57/* --dx / --dy : current viewport X/Y of the item when released */
58/* --fall-x / --fall-y : viewport position of the target folder */
58/* --fall-x / --fall-y : viewport position of the target folder */
59@keyframes drag-rise-spin-fall {
59@keyframes drag-rise-spin-fall {
60 0% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(0deg); opacity: 1; }
60 0% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(0deg); opacity: 1; }
61 20% { transform: translate(var(--dx), calc(var(--dy) - 40px)) scale(1.05) rotate(60deg); opacity: 1; }
61 20% { transform: translate(var(--dx), calc(var(--dy) - 40px)) scale(1.05) rotate(60deg); opacity: 1; }
62 60% { transform: translate(var(--fall-x), calc(var(--fall-y) - 20px)) scale(0.5) rotate(200deg); opacity: 0.9; }
62 60% { transform: translate(var(--fall-x), calc(var(--fall-y) - 20px)) scale(0.5) rotate(200deg); opacity: 0.9; }
63 100% { transform: translate(var(--fall-x), var(--fall-y)) scale(0.05) rotate(360deg); opacity: 0; }
63 100% { transform: translate(var(--fall-x), var(--fall-y)) scale(0.05) rotate(360deg); opacity: 0; }
64}
64}
65
65
66.file-item.dropping {
66.file-item.dropping {
67 animation: drag-rise-spin-fall 0.45s cubic-bezier(0.4, 0, 0.8, 1) forwards;
67 animation: drag-rise-spin-fall 0.45s cubic-bezier(0.4, 0, 0.8, 1) forwards;
68 pointer-events: none;
68 pointer-events: none;
69}
69}
70
70
71/* ---- bounce animation on the target folder ---- */
71/* ---- bounce animation on the target folder ---- */
72@keyframes folder-bounce {
72@keyframes folder-bounce {
73 0% { transform: translateY(0); }
73 0% { transform: translateY(0); }
74 30% { transform: translateY(8px); }
74 30% { transform: translateY(8px); }
75 65% { transform: translateY(-4px); }
75 65% { transform: translateY(-4px); }
76 85% { transform: translateY(2px); }
76 85% { transform: translateY(2px); }
77 100% { transform: translateY(0); }
77 100% { transform: translateY(0); }
78}
78}
79
79
80.file-item.folder-bounce {
80.file-item.folder-bounce {
81 animation: folder-bounce 0.4s ease-out forwards;
81 animation: folder-bounce 0.4s ease-out forwards;
82}
82}
83
83
84/* =========================================================
84/* =========================================================
85 EXPANDED PREVIEW TILE
85 EXPANDED PREVIEW TILE
86 The real .file-item element scales up in place to fill the
86 The real .file-item element scales up in place to fill the
87 viewport — no separate overlay.
87 viewport — no separate overlay.
88 ========================================================= */
88 ========================================================= */
89
89
90/* Dimming backdrop behind the expanded tile */
90/* Dimming backdrop behind the expanded tile */
91.preview-backdrop {
91.preview-backdrop {
92 position: fixed;
92 position: fixed;
93 inset: 0;
93 inset: 0;
94 z-index: 9999;
94 z-index: 9999;
95 background: rgba(8, 9, 14, 0.82);
95 background: rgba(8, 9, 14, 0.82);
96 opacity: 0;
96 opacity: 0;
97 transition: opacity 0.3s ease;
97 transition: opacity 0.3s ease;
98 pointer-events: none;
98 pointer-events: none;
99}
99}
100
100
101.preview-backdrop.visible {
101.preview-backdrop.visible {
102 opacity: 1;
102 opacity: 1;
103 pointer-events: all;
103 pointer-events: all;
104}
104}
105
105
106/* .file-item in expanded preview state */
106/* .file-item in expanded preview state */
107.file-item.file-item--preview {
107.file-item.file-item--preview {
108 background: var(--surface, #1a1d27) !important;
108 background: var(--surface, #1a1d27) !important;
109 border: 2px solid var(--preview-accent, var(--border, #2e3247)) !important;
109 border: 2px solid var(--preview-accent, var(--border, #2e3247)) !important;
110 border-radius: 12px !important;
110 border-radius: 12px !important;
111 cursor: default !important;
111 cursor: default !important;
112 user-select: text;
112 user-select: text;
113 display: flex !important;
113 display: flex !important;
114 flex-direction: column !important;
114 flex-direction: column !important;
115 overflow: hidden;
115 overflow: hidden;
116 padding: 0 !important;
116 padding: 0 !important;
117 gap: 0 !important;
117 gap: 0 !important;
118 z-index: 10000;
118 z-index: 10000;
119}
119}
120
120
121.file-item.file-item--preview .icon {
121.file-item.file-item--preview .icon {
122 width: 100% !important;
122 width: 100% !important;
123 height: auto !important;
123 height: auto !important;
124 position: relative;
124 position: relative;
125 flex: 1;
125 flex: 1;
126 min-height: 0;
126 min-height: 0;
127 display: flex !important;
127 display: flex !important;
128 align-items: center;
128 align-items: center;
129 justify-content: center;
129 justify-content: center;
130 overflow: auto;
130 overflow: auto;
131 padding: 1rem;
131 padding: 1rem;
132 box-sizing: border-box;
132 box-sizing: border-box;
133}
133}
134
134
135.file-item.file-item--preview .icon .preview-expand-outline {
135.file-item.file-item--preview .icon .preview-expand-outline {
136 position: absolute;
136 position: absolute;
137 left: 50%;
137 left: 50%;
138 top: 50%;
138 top: 50%;
139 width: min(72%, 640px);
139 width: min(72%, 640px);
140 height: min(72%, 640px);
140 height: min(72%, 640px);
141 transform: translate(-50%, -50%);
141 transform: translate(-50%, -50%);
142 opacity: 0.18;
142 opacity: 0.18;
143 pointer-events: none;
143 pointer-events: none;
144 z-index: 1;
144 z-index: 1;
145 filter: drop-shadow(0 0 10px var(--preview-accent, transparent));
145 filter: drop-shadow(0 0 10px var(--preview-accent, transparent));
146}
146}
147
147
148.file-item.file-item--preview .icon .preview-expand-content {
148.file-item.file-item--preview .icon .preview-expand-content {
149 position: relative;
149 position: relative;
150 z-index: 2;
150 z-index: 2;
151 width: 100%;
151 width: 100%;
152 height: 100%;
152 height: 100%;
153 display: flex;
153 display: flex;
154 align-items: center;
154 align-items: center;
155 justify-content: center;
155 justify-content: center;
156}
156}
157
157
158/* Keep preview media constrained within the expanded icon */
158/* Keep preview media constrained within the expanded icon */
159.file-item.file-item--preview .icon .preview-media {
159.file-item.file-item--preview .icon .preview-media {
160 max-width: 100%;
160 max-width: 100%;
161 max-height: 100%;
161 max-height: 100%;
162 width: auto;
162 width: auto;
163 height: auto;
163 height: auto;
164 object-fit: contain;
164 object-fit: contain;
165}
165}
166
166
167.file-item.file-item--preview .icon .preview-frame {
167.file-item.file-item--preview .icon .preview-frame {
168 width: 100%;
168 width: 100%;
169 height: 100%;
169 height: 100%;
170 border: none;
170 border: none;
171 border-radius: 8px;
171 border-radius: 8px;
172 background: #fff;
172 background: #fff;
173}
173}
174
174
175.file-item.file-item--preview .icon .preview-text {
175.file-item.file-item--preview .icon .preview-text {
176 width: 100%;
176 width: 100%;
177 min-height: auto;
177 min-height: auto;
178 flex: 1;
178 flex: 1;
179 align-self: stretch;
179 align-self: stretch;
180}
180}
181
181
182.file-item.file-item--preview .icon .preview-audio {
182.file-item.file-item--preview .icon .preview-audio {
183 width: min(640px, 95%);
183 width: min(640px, 95%);
184}
184}
185
185
186.file-item.file-item--preview .icon .preview-unsupported {
186.file-item.file-item--preview .icon .preview-unsupported {
187 color: var(--text-muted);
187 color: var(--text-muted);
188 font-size: 0.95rem;
188 font-size: 0.95rem;
189 max-width: 56ch;
189 max-width: 56ch;
190 text-align: center;
190 text-align: center;
191}
191}
192
192
193/* Filename bar shown at top of expanded preview */
193/* Filename bar shown at top of expanded preview */
194.preview-expand-title {
194.preview-expand-title {
195 padding: 0.7rem 3.5rem 0.7rem 1rem;
195 padding: 0.7rem 3.5rem 0.7rem 1rem;
196 font-size: 0.95rem;
196 font-size: 0.95rem;
197 color: var(--text);
197 color: var(--text);
198 border-bottom: 1px solid var(--border);
198 border-bottom: 1px solid var(--border);
199 white-space: nowrap;
199 white-space: nowrap;
200 overflow: hidden;
200 overflow: hidden;
201 text-overflow: ellipsis;
201 text-overflow: ellipsis;
202 flex-shrink: 0;
202 flex-shrink: 0;
203}
203}
204
204
205/* Close button (×) — top-right corner */
205/* Close button (×) — top-right corner */
206.preview-expand-close {
206.preview-expand-close {
207 position: absolute;
207 position: absolute;
208 top: 8px;
208 top: 8px;
209 right: 8px;
209 right: 8px;
210 width: 30px;
210 width: 30px;
211 height: 30px;
211 height: 30px;
212 background: rgba(20, 25, 40, 0.8);
212 background: rgba(20, 25, 40, 0.8);
213 color: #d6deef;
213 color: #d6deef;
214 border: 1px solid rgba(255, 255, 255, 0.15);
214 border: 1px solid rgba(255, 255, 255, 0.15);
215 border-radius: 50%;
215 border-radius: 50%;
216 cursor: pointer;
216 cursor: pointer;
217 font-size: 1.2rem;
217 font-size: 1.2rem;
218 z-index: 10001;
218 z-index: 10001;
219 display: flex;
219 display: flex;
220 align-items: center;
220 align-items: center;
221 justify-content: center;
221 justify-content: center;
222 line-height: 1;
222 line-height: 1;
223 padding: 0;
223 padding: 0;
224 transition: background 0.15s ease;
224 transition: background 0.15s ease;
225 flex-shrink: 0;
225 flex-shrink: 0;
226}
226}
227
227
228.preview-expand-close:hover {
228.preview-expand-close:hover {
229 background: rgba(255, 255, 255, 0.14);
229 background: rgba(255, 255, 255, 0.14);
230}
230}
231
231
232/* Download button — bottom-right corner */
232/* Download button — bottom-right corner */
233.preview-expand-download {
233.preview-expand-download {
234 position: absolute;
234 position: absolute;
235 bottom: 14px;
235 bottom: 14px;
236 right: 14px;
236 right: 14px;
237 background: var(--accent, #5b7fff);
237 background: var(--accent, #5b7fff);
238 color: #fff;
238 color: #fff;
239 border: none;
239 border: none;
240 border-radius: 6px;
240 border-radius: 6px;
241 padding: 7px 18px;
241 padding: 7px 18px;
242 cursor: pointer;
242 cursor: pointer;
243 font-size: 0.9rem;
243 font-size: 0.9rem;
244 z-index: 10001;
244 z-index: 10001;
245 transition: opacity 0.15s ease;
245 transition: opacity 0.15s ease;
246 flex-shrink: 0;
246 flex-shrink: 0;
247}
247}
248
248
249.preview-expand-download:hover {
249.preview-expand-download:hover {
250 opacity: 0.85;
250 opacity: 0.85;
251}
251}
252
252
253/* Spinner shown inside the expanded tile while content is loading */
253/* Share button — next to download button */
254.preview-loading-spinner {
254.preview-expand-share {
255 width: 40px;
255 position: absolute;
256 height: 40px;
256 bottom: 14px;
257 border: 3px solid rgba(255, 255, 255, 0.12);
257 right: 112px;
258 border-top-color: rgba(255, 255, 255, 0.7);
258 background: rgba(20, 25, 40, 0.84);
259 border-radius: 50%;
259 color: #fff;
260 animation: preview-spin 0.7s linear infinite;
260 border: 1px solid rgba(255, 255, 255, 0.18);
261}
261 border-radius: 6px;
262
262 padding: 7px 14px;
263@keyframes preview-spin {
263 cursor: pointer;
264 to { transform: rotate(360deg); }
264 font-size: 0.9rem;
265}
265 z-index: 10001;
266
266 transition: opacity 0.15s ease;
267.move-modal {
267 flex-shrink: 0;
268 width: min(92vw, 760px);
268}
269 max-height: min(86vh, 760px);
269
270 display: flex;
270.preview-expand-share:hover {
271 flex-direction: column;
271 opacity: 0.85;
272 gap: 0.6rem;
272}
273}
273
274
274/* Spinner shown inside the expanded tile while content is loading */
275.move-tree {
275.preview-loading-spinner {
276 border: 1px solid var(--border, #2e3247);
276 width: 40px;
277 border-radius: 10px;
277 height: 40px;
278 padding: 0.55rem;
278 border: 3px solid rgba(255, 255, 255, 0.12);
279 max-height: min(58vh, 480px);
279 border-top-color: rgba(255, 255, 255, 0.7);
280 overflow: auto;
280 border-radius: 50%;
281 background: var(--bg, #0f1117);
281 animation: preview-spin 0.7s linear infinite;
282}
282}
283
283
284.move-node {
284@keyframes preview-spin {
285 margin-left: 0.25rem;
285 to { transform: rotate(360deg); }
286}
286}
287
287
288.move-node-row {
288.move-modal {
289 display: flex;
289 width: min(92vw, 760px);
290 align-items: center;
290 max-height: min(86vh, 760px);
291 gap: 0.35rem;
291 display: flex;
292 margin: 0.14rem 0;
292 flex-direction: column;
293}
293 gap: 0.6rem;
294
294}
295.move-toggle {
295
296 width: 26px;
296.move-tree {
297 min-width: 26px;
297 border: 1px solid var(--border, #2e3247);
298 height: 26px;
298 border-radius: 10px;
299 padding: 0;
299 padding: 0.55rem;
300 display: inline-flex;
300 max-height: min(58vh, 480px);
301 align-items: center;
301 overflow: auto;
302 justify-content: center;
302 background: var(--bg, #0f1117);
303}
303}
304
304
305.move-node-label {
305.move-node {
306 display: inline-flex;
306 margin-left: 0.25rem;
307 align-items: center;
307}
308 justify-content: flex-start;
308
309 min-height: 28px;
309.move-node-row {
310 width: auto;
310 display: flex;
311 padding: 0.2rem 0.5rem;
311 align-items: center;
312 background: transparent;
312 gap: 0.35rem;
313 border: 1px solid transparent;
313 margin: 0.14rem 0;
314 color: var(--text, #e8eaf0);
314}
315}
315
316
316.move-toggle {
317.move-node-label:hover {
317 width: 26px;
318 border-color: var(--border, #2e3247);
318 min-width: 26px;
319 background: rgba(255, 255, 255, 0.03);
319 height: 26px;
320}
320 padding: 0;
321
321 display: inline-flex;
322.move-node-label.selected {
322 align-items: center;
323 border-color: var(--accent, #5b7fff);
323 justify-content: center;
324 background: rgba(91, 127, 255, 0.12);
324}
325}
325
326
326.move-node-label {
327.move-children {
327 display: inline-flex;
328 margin-left: 1.2rem;
328 align-items: center;
329 border-left: 1px dashed var(--border, #2e3247);
329 justify-content: flex-start;
330 padding-left: 0.5rem;
330 min-height: 28px;
331}
331 width: auto;
332
332 padding: 0.2rem 0.5rem;
333.move-empty {
333 background: transparent;
334 color: var(--text-muted, #7880a0);
334 border: 1px solid transparent;
335 font-size: 0.85rem;
335 color: var(--text, #e8eaf0);
336 margin: 0.2rem 0 0.4rem 0.2rem;
336}
337}
337
338.move-node-label:hover {
339 border-color: var(--border, #2e3247);
340 background: rgba(255, 255, 255, 0.03);
341}
342
343.move-node-label.selected {
344 border-color: var(--accent, #5b7fff);
345 background: rgba(91, 127, 255, 0.12);
346}
347
348.move-children {
349 margin-left: 1.2rem;
350 border-left: 1px dashed var(--border, #2e3247);
351 padding-left: 0.5rem;
352}
353
354.move-empty {
355 color: var(--text-muted, #7880a0);
356 font-size: 0.85rem;
357 margin: 0.2rem 0 0.4rem 0.2rem;
358}
tests/page.load.test.js +552 −525
@@ -1,525 +1,552 @@
1 'use strict';
2
3 const express = require('express');
4 const http = require('http');
5 const path = require('path');
6 const { once } = require('events');
7 const { webcrypto } = require('crypto');
8
9 describe('page load smoke test', () =>
10 {
11 let server;
12 let baseUrl;
13 let JSDOM;
14 let VirtualConsole;
15 let rootsFixture;
16 let listFixture;
17 let spaceFixture;
18 let meFixture;
19 let thumbnailStatusFixture;
20 let rootAccessFixture;
21 let folderIconFixture;
22 let adminUsersFixture;
23 let adminConfigFixture;
24 let downloadFixture;
25 const openDoms = [];
26
27 beforeEach(() =>
28 {
29 rootsFixture = [{ label: 'Root', path: '/data' }];
30 listFixture = {
31 '/data': [
32 {
33 name: 'readme.txt',
34 path: '/data/readme.txt',
35 isDir: false,
36 size: 12,
37 mtime: Date.now(),
38 },
39 ],
40 };
41 spaceFixture = {
42 '/data': { usedBytes: 0, freeBytes: 1024 * 1024 },
43 };
44 meFixture = { username: 'tester', isAdmin: false, permissions: {} };
45 thumbnailStatusFixture = {};
46 rootAccessFixture = {};
47 folderIconFixture = {};
48 adminUsersFixture = { users: [] };
49 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
50 downloadFixture = {};
51 });
52
53 beforeAll(async () =>
54 {
55 ({ JSDOM, VirtualConsole } = require('jsdom'));
56
57 const app = express();
58 const publicDir = path.join(__dirname, '../public');
59
60 app.use(express.json());
61 app.use(express.static(publicDir));
62
63 app.get('/api/auth/server-key', (req, res) => res.json({ publicKey: null }));
64 app.get('/api/auth/setup-needed', (req, res) => res.json({ needed: false }));
65 app.get('/api/auth/me', (req, res) => res.json(meFixture));
66 app.get('/api/files/roots', (req, res) => res.json({ roots: rootsFixture }));
67 app.get('/api/files/list', (req, res) =>
68 {
69 const dir = req.query.dir;
70 res.json({ items: listFixture[dir] || [] });
71 });
72 app.get('/api/files/space', (req, res) =>
73 {
74 const dir = req.query.dir;
75 const stats = spaceFixture[dir] || { usedBytes: 0, freeBytes: null };
76 res.json(stats);
77 });
78 app.get('/api/files/thumbnail', (req, res) =>
79 {
80 const file = String(req.query.file || '');
81 const status = Number(thumbnailStatusFixture[file] || 200);
82 if (status === 404)
83 {
84 return res.status(404).json({ error: 'Thumbnail not ready.' });
85 }
86 res.type('image/webp').send('thumb');
87 });
88 app.get('/api/files/download', (req, res) =>
89 {
90 const file = String(req.query.file || '');
91 const payload = downloadFixture[file];
92 if (!payload)
93 {
94 return res.status(404).json({ error: 'File not found.' });
95 }
96 res.type(payload.type || 'application/octet-stream').send(payload.body || 'x');
97 });
98 app.get('/api/files/root-access', (req, res) =>
99 {
100 const rootPath = String(req.query.rootPath || '');
101 res.json({ users: rootAccessFixture[rootPath] || [] });
102 });
103 app.get('/api/files/folder-icon', (req, res) =>
104 {
105 const dir = String(req.query.dir || '');
106 const icon = folderIconFixture[dir] || null;
107 res.json({ icon });
108 });
109 app.get('/api/files/folder-images', (req, res) =>
110 {
111 res.json({ images: [] });
112 });
113 app.get('/api/admin/config', (req, res) => res.json(adminConfigFixture));
114 app.get('/api/admin/users', (req, res) => res.json(adminUsersFixture));
115 app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
116 app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
117
118 server = http.createServer(app);
119 server.listen(0);
120 await once(server, 'listening');
121 baseUrl = `http://127.0.0.1:${server.address().port}`;
122 });
123
124 afterAll(() => server.close());
125
126 afterEach(() =>
127 {
128 while (openDoms.length)
129 {
130 const dom = openDoms.pop();
131 try { dom.window.close(); } catch { /* ignore */ }
132 }
133 });
134
135 async function bootClient ({ mobile = false, savedSession } = {})
136 {
137 const virtualConsole = new VirtualConsole();
138 const runtimeErrors = [];
139
140 virtualConsole.on('jsdomError', (err) =>
141 {
142 runtimeErrors.push(err);
143 });
144
145 const dom = await JSDOM.fromURL(baseUrl + '/', {
146 resources: 'usable',
147 runScripts: 'dangerously',
148 pretendToBeVisual: true,
149 virtualConsole,
150 beforeParse (window)
151 {
152 window.crypto = webcrypto;
153 window.fetch = (input, init) =>
154 {
155 const url = typeof input === 'string' ? input : input.url;
156 return fetch(new URL(url, baseUrl).toString(), init);
157 };
158 window.HTMLElement.prototype.focus = function focus () { };
159 window.HTMLCanvasElement.prototype.getContext = () => null;
160 window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
161 window.scrollTo = () => { };
162 let blobCounter = 0;
163 window.URL.createObjectURL = () => `blob:mock-${blobCounter++}`;
164 window.URL.revokeObjectURL = () => { };
165
166 const defaultSaved = {
167 token: 'saved-token',
168 dir: '/data',
169 rootPath: '/data',
170 lastOperationAt: Date.now(),
171 };
172 const effectiveSaved = savedSession === undefined ? defaultSaved : savedSession;
173 if (effectiveSaved)
174 {
175 window.localStorage.setItem('filemanager.session.v1', JSON.stringify(effectiveSaved));
176 }
177 window.addEventListener('error', (event) => runtimeErrors.push(event.error || new Error(event.message)));
178 window.addEventListener('unhandledrejection', (event) => runtimeErrors.push(event.reason || new Error('Unhandled rejection')));
179 },
180 });
181
182 await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
183 await new Promise((resolve) =>
184 {
185 const startedAt = Date.now();
186 const maxWaitMs = 2000;
187
188 function checkReady ()
189 {
190 const app = dom.window.document.getElementById('app');
191 if (app && !app.classList.contains('hidden'))
192 {
193 resolve();
194 return;
195 }
196
197 if (Date.now() - startedAt >= maxWaitMs)
198 {
199 resolve();
200 return;
201 }
202
203 dom.window.setTimeout(checkReady, 25);
204 }
205
206 checkReady();
207 });
208
209 openDoms.push(dom);
210
211 return { dom, runtimeErrors };
212 }
213
214 async function waitFor (dom, predicate, timeoutMs = 5000)
215 {
216 const startedAt = Date.now();
217 while (Date.now() - startedAt < timeoutMs)
218 {
219 if (predicate()) return true;
220 await new Promise(resolve => dom.window.setTimeout(resolve, 25));
221 }
222 return predicate();
223 }
224
225 test('requests / and boots the client without runtime errors', async () =>
226 {
227 const { dom, runtimeErrors } = await bootClient();
228
229 expect(runtimeErrors).toEqual([]);
230 expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
231 expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(false);
232
233 dom.window.close();
234 });
235
236 test('keeps sidebar folded on initial mobile boot', async () =>
237 {
238 const { dom, runtimeErrors } = await bootClient({ mobile: true });
239
240 expect(runtimeErrors).toEqual([]);
241 expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
242 expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(true);
243
244 dom.window.close();
245 });
246
247 test('suppresses default context menu on mobile file long-press', async () =>
248 {
249 const { dom, runtimeErrors } = await bootClient({ mobile: true });
250
251 expect(runtimeErrors).toEqual([]);
252
253 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item'));
254
255 const tile = dom.window.document.querySelector('.file-item');
256 expect(tile).toBeTruthy();
257
258 const evt = new dom.window.MouseEvent('contextmenu', {
259 bubbles: true,
260 cancelable: true,
261 view: dom.window,
262 });
263
264 const dispatchResult = tile.dispatchEvent(evt);
265 expect(dispatchResult).toBe(false);
266 expect(evt.defaultPrevented).toBe(true);
267
268 dom.window.close();
269 });
270
271 test('in Home, root tiles single-click focus and double-click open', async () =>
272 {
273 rootsFixture = [
274 { label: 'Root A', path: '/data-a' },
275 { label: 'Root B', path: '/data-b' },
276 ];
277 listFixture = {
278 '/data-a': [
279 {
280 name: 'docs',
281 path: '/data-a/docs',
282 isDir: true,
283 size: 0,
284 mtime: Date.now(),
285 },
286 ],
287 };
288 spaceFixture = {
289 '/data-a': { usedBytes: 2048, freeBytes: 4096 },
290 '/data-b': { usedBytes: 1024, freeBytes: 8192 },
291 };
292 folderIconFixture = {
293 '/data-a': { filePath: '/data-a/docs/cover.jpg' },
294 };
295
296 const { dom, runtimeErrors } = await bootClient({
297 savedSession: {
298 token: 'saved-token',
299 dir: null,
300 rootPath: null,
301 lastOperationAt: Date.now(),
302 },
303 });
304 expect(runtimeErrors).toEqual([]);
305
306 const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
307 expect(rootTile).toBeTruthy();
308
309 rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
310 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
311
312 expect(rootTile.classList.contains('selected')).toBe(true);
313 expect(dom.window.document.querySelector('.file-item[data-path="/data-b"]')).toBeTruthy();
314 expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
315 expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
316
317 let rootIconImage = null;
318 for (let i = 0; i < 10; i++)
319 {
320 const rootIconSvg = rootTile.querySelector('.icon svg');
321 rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
322 if (rootIconImage) break;
323 await new Promise(resolve => dom.window.setTimeout(resolve, 25));
324 }
325 // Root tiles should load folder icon thumbnails in Home view.
326 expect(rootIconImage).toBeTruthy();
327
328 rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
329 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
330
331 expect(dom.window.document.querySelector('.file-item[data-path="/data-a/docs"]')).toBeTruthy();
332
333 dom.window.close();
334 });
335
336 test('root sidebar shows alias and original name, and excludes Move to action', async () =>
337 {
338 rootsFixture = [
339 { label: 'Shared', path: '/data-a', originalName: 'data-a', alias: 'Shared' },
340 { label: 'Root B', path: '/data-b', originalName: 'data-b', alias: null },
341 ];
342 meFixture = {
343 username: 'tester',
344 isAdmin: false,
345 permissions: {
346 'data-a': { read: true, write: true },
347 'data-b': { read: true, write: false },
348 },
349 };
350 spaceFixture = {
351 '/data-a': { usedBytes: 1024, freeBytes: 2048 },
352 '/data-b': { usedBytes: 2048, freeBytes: 1024 },
353 };
354 rootAccessFixture = {
355 '/data-a': [
356 { username: 'alice', mode: 'R' },
357 { username: 'bob', mode: 'R+W' },
358 ],
359 };
360
361 const { dom, runtimeErrors } = await bootClient({
362 savedSession: {
363 token: 'saved-token',
364 dir: null,
365 rootPath: null,
366 lastOperationAt: Date.now(),
367 },
368 });
369
370 expect(runtimeErrors).toEqual([]);
371 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data-a"]'));
372
373 const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
374 expect(rootTile).toBeTruthy();
375 rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
376 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
377
378 const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
379 expect(sidebarText).toContain('Alias');
380 expect(sidebarText).toContain('Shared');
381 expect(sidebarText).toContain('Original name');
382 expect(sidebarText).toContain('data-a');
383 expect(sidebarText).toContain('Access');
384 expect(sidebarText).toContain('alice R');
385 expect(sidebarText).toContain('bob R+W');
386
387 const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
388 expect(accessItems).toEqual(['bob R+W', 'alice R']);
389
390 const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
391 expect(actionButtons).toContain('Rename');
392 expect(actionButtons).not.toContain('Move to');
393 expect(actionButtons).not.toContain('Delete');
394
395 dom.window.close();
396 });
397
398 test('base-level root sidebar shows access list with no item selected', async () =>
399 {
400 rootAccessFixture = {
401 '/data': [
402 { username: 'tim', mode: 'R+W' },
403 { username: 'guest', mode: 'R' },
404 ],
405 };
406
407 const { dom, runtimeErrors } = await bootClient();
408 expect(runtimeErrors).toEqual([]);
409
410 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
411 const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
412 expect(sidebarText).toContain('Access');
413 expect(sidebarText).toContain('tim R+W');
414 expect(sidebarText).toContain('guest R');
415
416 const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
417 expect(accessItems).toEqual(['tim R+W', 'guest R']);
418
419 dom.window.close();
420 });
421
422 test('shows pending icon spinner when image thumbnail cache is not ready', async () =>
423 {
424 listFixture = {
425 '/data': [
426 {
427 name: 'photo.png',
428 path: '/data/photo.png',
429 isDir: false,
430 size: 1024,
431 mtime: Date.now(),
432 },
433 ],
434 };
435 thumbnailStatusFixture['/data/photo.png'] = 404;
436
437 const { dom, runtimeErrors } = await bootClient();
438 expect(runtimeErrors).toEqual([]);
439
440 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
441 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');
442 expect(icon).toBeTruthy();
443 expect(icon.classList.contains('thumb-pending')).toBe(true);
444
445 dom.window.close();
446 });
447
448 test('admin user modal locks write checkbox while read is unchecked', async () =>
449 {
450 meFixture = { username: 'admin', isAdmin: true, permissions: {} };
451 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
452 adminUsersFixture = {
453 users: [
454 {
455 id: 9,
456 username: 'guest',
457 isAdmin: false,
458 permissions: { data: { read: false, write: true } },
459 },
460 ],
461 };
462
463 const { dom, runtimeErrors } = await bootClient();
464 expect(runtimeErrors).toEqual([]);
465
466 dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
467 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
468
469 const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
470 expect(editBtn).toBeTruthy();
471 editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
472 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
473
474 const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
475 const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
476 expect(readCb).toBeTruthy();
477 expect(writeCb).toBeTruthy();
478 expect(readCb.checked).toBe(false);
479 expect(writeCb.checked).toBe(false);
480 expect(writeCb.disabled).toBe(true);
481
482 readCb.checked = true;
483 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
484 expect(writeCb.disabled).toBe(false);
485
486 writeCb.checked = true;
487 readCb.checked = false;
488 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
489 expect(writeCb.checked).toBe(false);
490 expect(writeCb.disabled).toBe(true);
491
492 dom.window.close();
493 });
494
495 test('uses direct svg thumbnail when svg file is under 1MB', async () =>
496 {
497 listFixture = {
498 '/data': [
499 {
500 name: 'icon.svg',
501 path: '/data/icon.svg',
502 isDir: false,
503 size: 400 * 1024,
504 mtime: Date.now(),
505 },
506 ],
507 };
508 thumbnailStatusFixture['/data/icon.svg'] = 404;
509 downloadFixture['/data/icon.svg'] = {
510 type: 'image/svg+xml',
511 body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
512 };
513
514 const { dom, runtimeErrors } = await bootClient();
515 expect(runtimeErrors).toEqual([]);
516
517 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
518 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
519 expect(icon).toBeTruthy();
520 expect(icon.classList.contains('thumb-pending')).toBe(false);
521 expect(icon.dataset.thumbReady).toBe('1');
522
523 dom.window.close();
524 });
525 });
1 'use strict';
2
3 const express = require('express');
4 const http = require('http');
5 const path = require('path');
6 const { once } = require('events');
7 const { webcrypto } = require('crypto');
8
9 describe('page load smoke test', () =>
10 {
11 let server;
12 let baseUrl;
13 let JSDOM;
14 let VirtualConsole;
15 let rootsFixture;
16 let listFixture;
17 let spaceFixture;
18 let meFixture;
19 let thumbnailStatusFixture;
20 let rootAccessFixture;
21 let folderIconFixture;
22 let adminUsersFixture;
23 let adminConfigFixture;
24 let downloadFixture;
25 const openDoms = [];
26
27 beforeEach(() =>
28 {
29 rootsFixture = [{ label: 'Root', path: '/data' }];
30 listFixture = {
31 '/data': [
32 {
33 name: 'readme.txt',
34 path: '/data/readme.txt',
35 isDir: false,
36 size: 12,
37 mtime: Date.now(),
38 },
39 ],
40 };
41 spaceFixture = {
42 '/data': { usedBytes: 0, freeBytes: 1024 * 1024 },
43 };
44 meFixture = { username: 'tester', isAdmin: false, permissions: {} };
45 thumbnailStatusFixture = {};
46 rootAccessFixture = {};
47 folderIconFixture = {};
48 adminUsersFixture = { users: [] };
49 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
50 downloadFixture = {};
51 });
52
53 beforeAll(async () =>
54 {
55 ({ JSDOM, VirtualConsole } = require('jsdom'));
56
57 const app = express();
58 const publicDir = path.join(__dirname, '../public');
59
60 app.use(express.json());
61 app.use(express.static(publicDir));
62
63 app.get('/api/auth/server-key', (req, res) => res.json({ publicKey: null }));
64 app.get('/api/auth/setup-needed', (req, res) => res.json({ needed: false }));
65 app.get('/api/auth/me', (req, res) => res.json(meFixture));
66 app.get('/api/files/roots', (req, res) => res.json({ roots: rootsFixture }));
67 app.get('/api/files/list', (req, res) =>
68 {
69 const dir = req.query.dir;
70 res.json({ items: listFixture[dir] || [] });
71 });
72 app.get('/api/files/space', (req, res) =>
73 {
74 const dir = req.query.dir;
75 const stats = spaceFixture[dir] || { usedBytes: 0, freeBytes: null };
76 res.json(stats);
77 });
78 app.get('/api/files/thumbnail', (req, res) =>
79 {
80 const file = String(req.query.file || '');
81 const status = Number(thumbnailStatusFixture[file] || 200);
82 if (status === 404)
83 {
84 return res.status(404).json({ error: 'Thumbnail not ready.' });
85 }
86 res.type('image/webp').send('thumb');
87 });
88 app.get('/api/files/download', (req, res) =>
89 {
90 const file = String(req.query.file || '');
91 const payload = downloadFixture[file];
92 if (!payload)
93 {
94 return res.status(404).json({ error: 'File not found.' });
95 }
96 res.type(payload.type || 'application/octet-stream').send(payload.body || 'x');
97 });
98 app.get('/api/files/root-access', (req, res) =>
99 {
100 const rootPath = String(req.query.rootPath || '');
101 res.json({ users: rootAccessFixture[rootPath] || [] });
102 });
103 app.get('/api/files/folder-icon', (req, res) =>
104 {
105 const dir = String(req.query.dir || '');
106 const icon = folderIconFixture[dir] || null;
107 res.json({ icon });
108 });
109 app.get('/api/files/folder-images', (req, res) =>
110 {
111 res.json({ images: [] });
112 });
113 app.get('/api/admin/config', (req, res) => res.json(adminConfigFixture));
114 app.get('/api/admin/users', (req, res) => res.json(adminUsersFixture));
115 app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
116 app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
117
118 server = http.createServer(app);
119 server.listen(0);
120 await once(server, 'listening');
121 baseUrl = `http://127.0.0.1:${server.address().port}`;
122 });
123
124 afterAll(() => server.close());
125
126 afterEach(() =>
127 {
128 while (openDoms.length)
129 {
130 const dom = openDoms.pop();
131 try { dom.window.close(); } catch { /* ignore */ }
132 }
133 });
134
135 async function bootClient ({ mobile = false, savedSession } = {})
136 {
137 const virtualConsole = new VirtualConsole();
138 const runtimeErrors = [];
139
140 virtualConsole.on('jsdomError', (err) =>
141 {
142 runtimeErrors.push(err);
143 });
144
145 const dom = await JSDOM.fromURL(baseUrl + '/', {
146 resources: 'usable',
147 runScripts: 'dangerously',
148 pretendToBeVisual: true,
149 virtualConsole,
150 beforeParse (window)
151 {
152 window.crypto = webcrypto;
153 window.fetch = (input, init) =>
154 {
155 const url = typeof input === 'string' ? input : input.url;
156 return fetch(new URL(url, baseUrl).toString(), init);
157 };
158 window.HTMLElement.prototype.focus = function focus () { };
159 window.HTMLCanvasElement.prototype.getContext = () => null;
160 window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
161 window.scrollTo = () => { };
162 let blobCounter = 0;
163 window.URL.createObjectURL = () => `blob:mock-${blobCounter++}`;
164 window.URL.revokeObjectURL = () => { };
165
166 const defaultSaved = {
167 token: 'saved-token',
168 dir: '/data',
169 rootPath: '/data',
170 lastOperationAt: Date.now(),
171 };
172 const effectiveSaved = savedSession === undefined ? defaultSaved : savedSession;
173 if (effectiveSaved)
174 {
175 window.localStorage.setItem('filemanager.session.v1', JSON.stringify(effectiveSaved));
176 }
177 window.addEventListener('error', (event) => runtimeErrors.push(event.error || new Error(event.message)));
178 window.addEventListener('unhandledrejection', (event) => runtimeErrors.push(event.reason || new Error('Unhandled rejection')));
179 },
180 });
181
182 await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
183 await new Promise((resolve) =>
184 {
185 const startedAt = Date.now();
186 const maxWaitMs = 2000;
187
188 function checkReady ()
189 {
190 const app = dom.window.document.getElementById('app');
191 if (app && !app.classList.contains('hidden'))
192 {
193 resolve();
194 return;
195 }
196
197 if (Date.now() - startedAt >= maxWaitMs)
198 {
199 resolve();
200 return;
201 }
202
203 dom.window.setTimeout(checkReady, 25);
204 }
205
206 checkReady();
207 });
208
209 openDoms.push(dom);
210
211 return { dom, runtimeErrors };
212 }
213
214 async function waitFor (dom, predicate, timeoutMs = 5000)
215 {
216 const startedAt = Date.now();
217 while (Date.now() - startedAt < timeoutMs)
218 {
219 if (predicate()) return true;
220 await new Promise(resolve => dom.window.setTimeout(resolve, 25));
221 }
222 return predicate();
223 }
224
225 test('requests / and boots the client without runtime errors', async () =>
226 {
227 const { dom, runtimeErrors } = await bootClient();
228
229 expect(runtimeErrors).toEqual([]);
230 expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
231 expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(false);
232
233 dom.window.close();
234 });
235
236 test('keeps sidebar folded on initial mobile boot', async () =>
237 {
238 const { dom, runtimeErrors } = await bootClient({ mobile: true });
239
240 expect(runtimeErrors).toEqual([]);
241 expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
242 expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(true);
243
244 dom.window.close();
245 });
246
247 test('suppresses default context menu on mobile file long-press', async () =>
248 {
249 const { dom, runtimeErrors } = await bootClient({ mobile: true });
250
251 expect(runtimeErrors).toEqual([]);
252
253 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item'));
254
255 const tile = dom.window.document.querySelector('.file-item');
256 expect(tile).toBeTruthy();
257
258 const evt = new dom.window.MouseEvent('contextmenu', {
259 bubbles: true,
260 cancelable: true,
261 view: dom.window,
262 });
263
264 const dispatchResult = tile.dispatchEvent(evt);
265 expect(dispatchResult).toBe(false);
266 expect(evt.defaultPrevented).toBe(true);
267
268 dom.window.close();
269 });
270
271 test('in Home, root tiles single-click focus and double-click open', async () =>
272 {
273 rootsFixture = [
274 { label: 'Root A', path: '/data-a' },
275 { label: 'Root B', path: '/data-b' },
276 ];
277 listFixture = {
278 '/data-a': [
279 {
280 name: 'docs',
281 path: '/data-a/docs',
282 isDir: true,
283 size: 0,
284 mtime: Date.now(),
285 },
286 ],
287 };
288 spaceFixture = {
289 '/data-a': { usedBytes: 2048, freeBytes: 4096 },
290 '/data-b': { usedBytes: 1024, freeBytes: 8192 },
291 };
292 folderIconFixture = {
293 '/data-a': { filePath: '/data-a/docs/cover.jpg' },
294 };
295
296 const { dom, runtimeErrors } = await bootClient({
297 savedSession: {
298 token: 'saved-token',
299 dir: null,
300 rootPath: null,
301 lastOperationAt: Date.now(),
302 },
303 });
304 expect(runtimeErrors).toEqual([]);
305
306 const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
307 expect(rootTile).toBeTruthy();
308
309 rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
310 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
311
312 expect(rootTile.classList.contains('selected')).toBe(true);
313 expect(dom.window.document.querySelector('.file-item[data-path="/data-b"]')).toBeTruthy();
314 expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
315 expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
316
317 let rootIconImage = null;
318 for (let i = 0; i < 10; i++)
319 {
320 const rootIconSvg = rootTile.querySelector('.icon svg');
321 rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
322 if (rootIconImage) break;
323 await new Promise(resolve => dom.window.setTimeout(resolve, 25));
324 }
325 // Root tiles should load folder icon thumbnails in Home view.
326 expect(rootIconImage).toBeTruthy();
327
328 rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
329 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
330
331 expect(dom.window.document.querySelector('.file-item[data-path="/data-a/docs"]')).toBeTruthy();
332
333 dom.window.close();
334 });
335
336 test('root sidebar shows alias and original name, and excludes Move to action', async () =>
337 {
338 rootsFixture = [
339 { label: 'Shared', path: '/data-a', originalName: 'data-a', alias: 'Shared' },
340 { label: 'Root B', path: '/data-b', originalName: 'data-b', alias: null },
341 ];
342 meFixture = {
343 username: 'tester',
344 isAdmin: false,
345 permissions: {
346 'data-a': { read: true, write: true },
347 'data-b': { read: true, write: false },
348 },
349 };
350 spaceFixture = {
351 '/data-a': { usedBytes: 1024, freeBytes: 2048 },
352 '/data-b': { usedBytes: 2048, freeBytes: 1024 },
353 };
354 rootAccessFixture = {
355 '/data-a': [
356 { username: 'alice', mode: 'R' },
357 { username: 'bob', mode: 'R+W' },
358 ],
359 };
360
361 const { dom, runtimeErrors } = await bootClient({
362 savedSession: {
363 token: 'saved-token',
364 dir: null,
365 rootPath: null,
366 lastOperationAt: Date.now(),
367 },
368 });
369
370 expect(runtimeErrors).toEqual([]);
371 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data-a"]'));
372
373 const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
374 expect(rootTile).toBeTruthy();
375 rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
376 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
377
378 const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
379 expect(sidebarText).toContain('Alias');
380 expect(sidebarText).toContain('Shared');
381 expect(sidebarText).toContain('Original name');
382 expect(sidebarText).toContain('data-a');
383 expect(sidebarText).toContain('Access');
384 expect(sidebarText).toContain('alice R');
385 expect(sidebarText).toContain('bob R+W');
386
387 const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
388 expect(accessItems).toEqual(['bob R+W', 'alice R']);
389
390 const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
391 expect(actionButtons).toContain('Rename');
392 expect(actionButtons).not.toContain('Move to');
393 expect(actionButtons).not.toContain('Delete');
394
395 dom.window.close();
396 });
397
398 test('base-level root sidebar shows access list with no item selected', async () =>
399 {
400 rootAccessFixture = {
401 '/data': [
402 { username: 'tim', mode: 'R+W' },
403 { username: 'guest', mode: 'R' },
404 ],
405 };
406
407 const { dom, runtimeErrors } = await bootClient();
408 expect(runtimeErrors).toEqual([]);
409
410 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
411 const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
412 expect(sidebarText).toContain('Access');
413 expect(sidebarText).toContain('tim R+W');
414 expect(sidebarText).toContain('guest R');
415
416 const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
417 expect(accessItems).toEqual(['tim R+W', 'guest R']);
418
419 dom.window.close();
420 });
421
422 test('shows pending icon spinner when image thumbnail cache is not ready', async () =>
423 {
424 listFixture = {
425 '/data': [
426 {
427 name: 'photo.png',
428 path: '/data/photo.png',
429 isDir: false,
430 size: 1024,
431 mtime: Date.now(),
432 },
433 ],
434 };
435 thumbnailStatusFixture['/data/photo.png'] = 404;
436
437 const { dom, runtimeErrors } = await bootClient();
438 expect(runtimeErrors).toEqual([]);
439
440 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
441 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');
442 expect(icon).toBeTruthy();
443 expect(icon.classList.contains('thumb-pending')).toBe(true);
444
445 dom.window.close();
446 });
447
448 test('admin user modal locks write checkbox while read is unchecked', async () =>
449 {
450 meFixture = { username: 'admin', isAdmin: true, permissions: {} };
451 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
452 adminUsersFixture = {
453 users: [
454 {
455 id: 9,
456 username: 'guest',
457 isAdmin: false,
458 permissions: { data: { read: false, write: true } },
459 },
460 ],
461 };
462
463 const { dom, runtimeErrors } = await bootClient();
464 expect(runtimeErrors).toEqual([]);
465
466 dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
467 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
468
469 const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
470 expect(editBtn).toBeTruthy();
471 editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
472 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
473
474 const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
475 const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
476 expect(readCb).toBeTruthy();
477 expect(writeCb).toBeTruthy();
478 expect(readCb.checked).toBe(false);
479 expect(writeCb.checked).toBe(false);
480 expect(writeCb.disabled).toBe(true);
481
482 readCb.checked = true;
483 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
484 expect(writeCb.disabled).toBe(false);
485
486 writeCb.checked = true;
487 readCb.checked = false;
488 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
489 expect(writeCb.checked).toBe(false);
490 expect(writeCb.disabled).toBe(true);
491
492 dom.window.close();
493 });
494
495 test('uses direct svg thumbnail when svg file is under 1MB', async () =>
496 {
497 listFixture = {
498 '/data': [
499 {
500 name: 'icon.svg',
501 path: '/data/icon.svg',
502 isDir: false,
503 size: 400 * 1024,
504 mtime: Date.now(),
505 },
506 ],
507 };
508 thumbnailStatusFixture['/data/icon.svg'] = 404;
509 downloadFixture['/data/icon.svg'] = {
510 type: 'image/svg+xml',
511 body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
512 };
513
514 const { dom, runtimeErrors } = await bootClient();
515 expect(runtimeErrors).toEqual([]);
516
517 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
518 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
519 expect(icon).toBeTruthy();
520 expect(icon.classList.contains('thumb-pending')).toBe(false);
521 expect(icon.dataset.thumbReady).toBe('1');
522
523 dom.window.close();
524 });
525
526 test('expanded file preview shows a Share button next to Download', async () =>
527 {
528 downloadFixture['/data/readme.txt'] = {
529 type: 'text/plain',
530 body: 'hello preview',
531 };
532
533 const { dom, runtimeErrors } = await bootClient();
534 expect(runtimeErrors).toEqual([]);
535
536 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]'));
537
538 const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]');
539 expect(fileTile).toBeTruthy();
540
541 fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
542 await waitFor(dom, () => !!dom.window.document.querySelector('.preview-expand-share'));
543
544 const shareBtn = dom.window.document.querySelector('.preview-expand-share');
545 const downloadBtn = dom.window.document.querySelector('.preview-expand-download');
546 expect(shareBtn).toBeTruthy();
547 expect(downloadBtn).toBeTruthy();
548 expect(shareBtn.textContent).toBe('Share');
549
550 dom.window.close();
551 });
552 });
@@ -1,525 +1,552 @@
1'use strict';
1'use strict';
2
2
3const express = require('express');
3const express = require('express');
4const http = require('http');
4const http = require('http');
5const path = require('path');
5const path = require('path');
6const { once } = require('events');
6const { once } = require('events');
7const { webcrypto } = require('crypto');
7const { webcrypto } = require('crypto');
8
8
9describe('page load smoke test', () =>
9describe('page load smoke test', () =>
10{
10{
11 let server;
11 let server;
12 let baseUrl;
12 let baseUrl;
13 let JSDOM;
13 let JSDOM;
14 let VirtualConsole;
14 let VirtualConsole;
15 let rootsFixture;
15 let rootsFixture;
16 let listFixture;
16 let listFixture;
17 let spaceFixture;
17 let spaceFixture;
18 let meFixture;
18 let meFixture;
19 let thumbnailStatusFixture;
19 let thumbnailStatusFixture;
20 let rootAccessFixture;
20 let rootAccessFixture;
21 let folderIconFixture;
21 let folderIconFixture;
22 let adminUsersFixture;
22 let adminUsersFixture;
23 let adminConfigFixture;
23 let adminConfigFixture;
24 let downloadFixture;
24 let downloadFixture;
25 const openDoms = [];
25 const openDoms = [];
26
26
27 beforeEach(() =>
27 beforeEach(() =>
28 {
28 {
29 rootsFixture = [{ label: 'Root', path: '/data' }];
29 rootsFixture = [{ label: 'Root', path: '/data' }];
30 listFixture = {
30 listFixture = {
31 '/data': [
31 '/data': [
32 {
32 {
33 name: 'readme.txt',
33 name: 'readme.txt',
34 path: '/data/readme.txt',
34 path: '/data/readme.txt',
35 isDir: false,
35 isDir: false,
36 size: 12,
36 size: 12,
37 mtime: Date.now(),
37 mtime: Date.now(),
38 },
38 },
39 ],
39 ],
40 };
40 };
41 spaceFixture = {
41 spaceFixture = {
42 '/data': { usedBytes: 0, freeBytes: 1024 * 1024 },
42 '/data': { usedBytes: 0, freeBytes: 1024 * 1024 },
43 };
43 };
44 meFixture = { username: 'tester', isAdmin: false, permissions: {} };
44 meFixture = { username: 'tester', isAdmin: false, permissions: {} };
45 thumbnailStatusFixture = {};
45 thumbnailStatusFixture = {};
46 rootAccessFixture = {};
46 rootAccessFixture = {};
47 folderIconFixture = {};
47 folderIconFixture = {};
48 adminUsersFixture = { users: [] };
48 adminUsersFixture = { users: [] };
49 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
49 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
50 downloadFixture = {};
50 downloadFixture = {};
51 });
51 });
52
52
53 beforeAll(async () =>
53 beforeAll(async () =>
54 {
54 {
55 ({ JSDOM, VirtualConsole } = require('jsdom'));
55 ({ JSDOM, VirtualConsole } = require('jsdom'));
56
56
57 const app = express();
57 const app = express();
58 const publicDir = path.join(__dirname, '../public');
58 const publicDir = path.join(__dirname, '../public');
59
59
60 app.use(express.json());
60 app.use(express.json());
61 app.use(express.static(publicDir));
61 app.use(express.static(publicDir));
62
62
63 app.get('/api/auth/server-key', (req, res) => res.json({ publicKey: null }));
63 app.get('/api/auth/server-key', (req, res) => res.json({ publicKey: null }));
64 app.get('/api/auth/setup-needed', (req, res) => res.json({ needed: false }));
64 app.get('/api/auth/setup-needed', (req, res) => res.json({ needed: false }));
65 app.get('/api/auth/me', (req, res) => res.json(meFixture));
65 app.get('/api/auth/me', (req, res) => res.json(meFixture));
66 app.get('/api/files/roots', (req, res) => res.json({ roots: rootsFixture }));
66 app.get('/api/files/roots', (req, res) => res.json({ roots: rootsFixture }));
67 app.get('/api/files/list', (req, res) =>
67 app.get('/api/files/list', (req, res) =>
68 {
68 {
69 const dir = req.query.dir;
69 const dir = req.query.dir;
70 res.json({ items: listFixture[dir] || [] });
70 res.json({ items: listFixture[dir] || [] });
71 });
71 });
72 app.get('/api/files/space', (req, res) =>
72 app.get('/api/files/space', (req, res) =>
73 {
73 {
74 const dir = req.query.dir;
74 const dir = req.query.dir;
75 const stats = spaceFixture[dir] || { usedBytes: 0, freeBytes: null };
75 const stats = spaceFixture[dir] || { usedBytes: 0, freeBytes: null };
76 res.json(stats);
76 res.json(stats);
77 });
77 });
78 app.get('/api/files/thumbnail', (req, res) =>
78 app.get('/api/files/thumbnail', (req, res) =>
79 {
79 {
80 const file = String(req.query.file || '');
80 const file = String(req.query.file || '');
81 const status = Number(thumbnailStatusFixture[file] || 200);
81 const status = Number(thumbnailStatusFixture[file] || 200);
82 if (status === 404)
82 if (status === 404)
83 {
83 {
84 return res.status(404).json({ error: 'Thumbnail not ready.' });
84 return res.status(404).json({ error: 'Thumbnail not ready.' });
85 }
85 }
86 res.type('image/webp').send('thumb');
86 res.type('image/webp').send('thumb');
87 });
87 });
88 app.get('/api/files/download', (req, res) =>
88 app.get('/api/files/download', (req, res) =>
89 {
89 {
90 const file = String(req.query.file || '');
90 const file = String(req.query.file || '');
91 const payload = downloadFixture[file];
91 const payload = downloadFixture[file];
92 if (!payload)
92 if (!payload)
93 {
93 {
94 return res.status(404).json({ error: 'File not found.' });
94 return res.status(404).json({ error: 'File not found.' });
95 }
95 }
96 res.type(payload.type || 'application/octet-stream').send(payload.body || 'x');
96 res.type(payload.type || 'application/octet-stream').send(payload.body || 'x');
97 });
97 });
98 app.get('/api/files/root-access', (req, res) =>
98 app.get('/api/files/root-access', (req, res) =>
99 {
99 {
100 const rootPath = String(req.query.rootPath || '');
100 const rootPath = String(req.query.rootPath || '');
101 res.json({ users: rootAccessFixture[rootPath] || [] });
101 res.json({ users: rootAccessFixture[rootPath] || [] });
102 });
102 });
103 app.get('/api/files/folder-icon', (req, res) =>
103 app.get('/api/files/folder-icon', (req, res) =>
104 {
104 {
105 const dir = String(req.query.dir || '');
105 const dir = String(req.query.dir || '');
106 const icon = folderIconFixture[dir] || null;
106 const icon = folderIconFixture[dir] || null;
107 res.json({ icon });
107 res.json({ icon });
108 });
108 });
109 app.get('/api/files/folder-images', (req, res) =>
109 app.get('/api/files/folder-images', (req, res) =>
110 {
110 {
111 res.json({ images: [] });
111 res.json({ images: [] });
112 });
112 });
113 app.get('/api/admin/config', (req, res) => res.json(adminConfigFixture));
113 app.get('/api/admin/config', (req, res) => res.json(adminConfigFixture));
114 app.get('/api/admin/users', (req, res) => res.json(adminUsersFixture));
114 app.get('/api/admin/users', (req, res) => res.json(adminUsersFixture));
115 app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
115 app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
116 app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
116 app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
117
117
118 server = http.createServer(app);
118 server = http.createServer(app);
119 server.listen(0);
119 server.listen(0);
120 await once(server, 'listening');
120 await once(server, 'listening');
121 baseUrl = `http://127.0.0.1:${server.address().port}`;
121 baseUrl = `http://127.0.0.1:${server.address().port}`;
122 });
122 });
123
123
124 afterAll(() => server.close());
124 afterAll(() => server.close());
125
125
126 afterEach(() =>
126 afterEach(() =>
127 {
127 {
128 while (openDoms.length)
128 while (openDoms.length)
129 {
129 {
130 const dom = openDoms.pop();
130 const dom = openDoms.pop();
131 try { dom.window.close(); } catch { /* ignore */ }
131 try { dom.window.close(); } catch { /* ignore */ }
132 }
132 }
133 });
133 });
134
134
135 async function bootClient ({ mobile = false, savedSession } = {})
135 async function bootClient ({ mobile = false, savedSession } = {})
136 {
136 {
137 const virtualConsole = new VirtualConsole();
137 const virtualConsole = new VirtualConsole();
138 const runtimeErrors = [];
138 const runtimeErrors = [];
139
139
140 virtualConsole.on('jsdomError', (err) =>
140 virtualConsole.on('jsdomError', (err) =>
141 {
141 {
142 runtimeErrors.push(err);
142 runtimeErrors.push(err);
143 });
143 });
144
144
145 const dom = await JSDOM.fromURL(baseUrl + '/', {
145 const dom = await JSDOM.fromURL(baseUrl + '/', {
146 resources: 'usable',
146 resources: 'usable',
147 runScripts: 'dangerously',
147 runScripts: 'dangerously',
148 pretendToBeVisual: true,
148 pretendToBeVisual: true,
149 virtualConsole,
149 virtualConsole,
150 beforeParse (window)
150 beforeParse (window)
151 {
151 {
152 window.crypto = webcrypto;
152 window.crypto = webcrypto;
153 window.fetch = (input, init) =>
153 window.fetch = (input, init) =>
154 {
154 {
155 const url = typeof input === 'string' ? input : input.url;
155 const url = typeof input === 'string' ? input : input.url;
156 return fetch(new URL(url, baseUrl).toString(), init);
156 return fetch(new URL(url, baseUrl).toString(), init);
157 };
157 };
158 window.HTMLElement.prototype.focus = function focus () { };
158 window.HTMLElement.prototype.focus = function focus () { };
159 window.HTMLCanvasElement.prototype.getContext = () => null;
159 window.HTMLCanvasElement.prototype.getContext = () => null;
160 window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
160 window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
161 window.scrollTo = () => { };
161 window.scrollTo = () => { };
162 let blobCounter = 0;
162 let blobCounter = 0;
163 window.URL.createObjectURL = () => `blob:mock-${blobCounter++}`;
163 window.URL.createObjectURL = () => `blob:mock-${blobCounter++}`;
164 window.URL.revokeObjectURL = () => { };
164 window.URL.revokeObjectURL = () => { };
165
165
166 const defaultSaved = {
166 const defaultSaved = {
167 token: 'saved-token',
167 token: 'saved-token',
168 dir: '/data',
168 dir: '/data',
169 rootPath: '/data',
169 rootPath: '/data',
170 lastOperationAt: Date.now(),
170 lastOperationAt: Date.now(),
171 };
171 };
172 const effectiveSaved = savedSession === undefined ? defaultSaved : savedSession;
172 const effectiveSaved = savedSession === undefined ? defaultSaved : savedSession;
173 if (effectiveSaved)
173 if (effectiveSaved)
174 {
174 {
175 window.localStorage.setItem('filemanager.session.v1', JSON.stringify(effectiveSaved));
175 window.localStorage.setItem('filemanager.session.v1', JSON.stringify(effectiveSaved));
176 }
176 }
177 window.addEventListener('error', (event) => runtimeErrors.push(event.error || new Error(event.message)));
177 window.addEventListener('error', (event) => runtimeErrors.push(event.error || new Error(event.message)));
178 window.addEventListener('unhandledrejection', (event) => runtimeErrors.push(event.reason || new Error('Unhandled rejection')));
178 window.addEventListener('unhandledrejection', (event) => runtimeErrors.push(event.reason || new Error('Unhandled rejection')));
179 },
179 },
180 });
180 });
181
181
182 await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
182 await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
183 await new Promise((resolve) =>
183 await new Promise((resolve) =>
184 {
184 {
185 const startedAt = Date.now();
185 const startedAt = Date.now();
186 const maxWaitMs = 2000;
186 const maxWaitMs = 2000;
187
187
188 function checkReady ()
188 function checkReady ()
189 {
189 {
190 const app = dom.window.document.getElementById('app');
190 const app = dom.window.document.getElementById('app');
191 if (app && !app.classList.contains('hidden'))
191 if (app && !app.classList.contains('hidden'))
192 {
192 {
193 resolve();
193 resolve();
194 return;
194 return;
195 }
195 }
196
196
197 if (Date.now() - startedAt >= maxWaitMs)
197 if (Date.now() - startedAt >= maxWaitMs)
198 {
198 {
199 resolve();
199 resolve();
200 return;
200 return;
201 }
201 }
202
202
203 dom.window.setTimeout(checkReady, 25);
203 dom.window.setTimeout(checkReady, 25);
204 }
204 }
205
205
206 checkReady();
206 checkReady();
207 });
207 });
208
208
209 openDoms.push(dom);
209 openDoms.push(dom);
210
210
211 return { dom, runtimeErrors };
211 return { dom, runtimeErrors };
212 }
212 }
213
213
214 async function waitFor (dom, predicate, timeoutMs = 5000)
214 async function waitFor (dom, predicate, timeoutMs = 5000)
215 {
215 {
216 const startedAt = Date.now();
216 const startedAt = Date.now();
217 while (Date.now() - startedAt < timeoutMs)
217 while (Date.now() - startedAt < timeoutMs)
218 {
218 {
219 if (predicate()) return true;
219 if (predicate()) return true;
220 await new Promise(resolve => dom.window.setTimeout(resolve, 25));
220 await new Promise(resolve => dom.window.setTimeout(resolve, 25));
221 }
221 }
222 return predicate();
222 return predicate();
223 }
223 }
224
224
225 test('requests / and boots the client without runtime errors', async () =>
225 test('requests / and boots the client without runtime errors', async () =>
226 {
226 {
227 const { dom, runtimeErrors } = await bootClient();
227 const { dom, runtimeErrors } = await bootClient();
228
228
229 expect(runtimeErrors).toEqual([]);
229 expect(runtimeErrors).toEqual([]);
230 expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
230 expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
231 expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(false);
231 expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(false);
232
232
233 dom.window.close();
233 dom.window.close();
234 });
234 });
235
235
236 test('keeps sidebar folded on initial mobile boot', async () =>
236 test('keeps sidebar folded on initial mobile boot', async () =>
237 {
237 {
238 const { dom, runtimeErrors } = await bootClient({ mobile: true });
238 const { dom, runtimeErrors } = await bootClient({ mobile: true });
239
239
240 expect(runtimeErrors).toEqual([]);
240 expect(runtimeErrors).toEqual([]);
241 expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
241 expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
242 expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(true);
242 expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(true);
243
243
244 dom.window.close();
244 dom.window.close();
245 });
245 });
246
246
247 test('suppresses default context menu on mobile file long-press', async () =>
247 test('suppresses default context menu on mobile file long-press', async () =>
248 {
248 {
249 const { dom, runtimeErrors } = await bootClient({ mobile: true });
249 const { dom, runtimeErrors } = await bootClient({ mobile: true });
250
250
251 expect(runtimeErrors).toEqual([]);
251 expect(runtimeErrors).toEqual([]);
252
252
253 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item'));
253 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item'));
254
254
255 const tile = dom.window.document.querySelector('.file-item');
255 const tile = dom.window.document.querySelector('.file-item');
256 expect(tile).toBeTruthy();
256 expect(tile).toBeTruthy();
257
257
258 const evt = new dom.window.MouseEvent('contextmenu', {
258 const evt = new dom.window.MouseEvent('contextmenu', {
259 bubbles: true,
259 bubbles: true,
260 cancelable: true,
260 cancelable: true,
261 view: dom.window,
261 view: dom.window,
262 });
262 });
263
263
264 const dispatchResult = tile.dispatchEvent(evt);
264 const dispatchResult = tile.dispatchEvent(evt);
265 expect(dispatchResult).toBe(false);
265 expect(dispatchResult).toBe(false);
266 expect(evt.defaultPrevented).toBe(true);
266 expect(evt.defaultPrevented).toBe(true);
267
267
268 dom.window.close();
268 dom.window.close();
269 });
269 });
270
270
271 test('in Home, root tiles single-click focus and double-click open', async () =>
271 test('in Home, root tiles single-click focus and double-click open', async () =>
272 {
272 {
273 rootsFixture = [
273 rootsFixture = [
274 { label: 'Root A', path: '/data-a' },
274 { label: 'Root A', path: '/data-a' },
275 { label: 'Root B', path: '/data-b' },
275 { label: 'Root B', path: '/data-b' },
276 ];
276 ];
277 listFixture = {
277 listFixture = {
278 '/data-a': [
278 '/data-a': [
279 {
279 {
280 name: 'docs',
280 name: 'docs',
281 path: '/data-a/docs',
281 path: '/data-a/docs',
282 isDir: true,
282 isDir: true,
283 size: 0,
283 size: 0,
284 mtime: Date.now(),
284 mtime: Date.now(),
285 },
285 },
286 ],
286 ],
287 };
287 };
288 spaceFixture = {
288 spaceFixture = {
289 '/data-a': { usedBytes: 2048, freeBytes: 4096 },
289 '/data-a': { usedBytes: 2048, freeBytes: 4096 },
290 '/data-b': { usedBytes: 1024, freeBytes: 8192 },
290 '/data-b': { usedBytes: 1024, freeBytes: 8192 },
291 };
291 };
292 folderIconFixture = {
292 folderIconFixture = {
293 '/data-a': { filePath: '/data-a/docs/cover.jpg' },
293 '/data-a': { filePath: '/data-a/docs/cover.jpg' },
294 };
294 };
295
295
296 const { dom, runtimeErrors } = await bootClient({
296 const { dom, runtimeErrors } = await bootClient({
297 savedSession: {
297 savedSession: {
298 token: 'saved-token',
298 token: 'saved-token',
299 dir: null,
299 dir: null,
300 rootPath: null,
300 rootPath: null,
301 lastOperationAt: Date.now(),
301 lastOperationAt: Date.now(),
302 },
302 },
303 });
303 });
304 expect(runtimeErrors).toEqual([]);
304 expect(runtimeErrors).toEqual([]);
305
305
306 const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
306 const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
307 expect(rootTile).toBeTruthy();
307 expect(rootTile).toBeTruthy();
308
308
309 rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
309 rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
310 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
310 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
311
311
312 expect(rootTile.classList.contains('selected')).toBe(true);
312 expect(rootTile.classList.contains('selected')).toBe(true);
313 expect(dom.window.document.querySelector('.file-item[data-path="/data-b"]')).toBeTruthy();
313 expect(dom.window.document.querySelector('.file-item[data-path="/data-b"]')).toBeTruthy();
314 expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
314 expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
315 expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
315 expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
316
316
317 let rootIconImage = null;
317 let rootIconImage = null;
318 for (let i = 0; i < 10; i++)
318 for (let i = 0; i < 10; i++)
319 {
319 {
320 const rootIconSvg = rootTile.querySelector('.icon svg');
320 const rootIconSvg = rootTile.querySelector('.icon svg');
321 rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
321 rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
322 if (rootIconImage) break;
322 if (rootIconImage) break;
323 await new Promise(resolve => dom.window.setTimeout(resolve, 25));
323 await new Promise(resolve => dom.window.setTimeout(resolve, 25));
324 }
324 }
325 // Root tiles should load folder icon thumbnails in Home view.
325 // Root tiles should load folder icon thumbnails in Home view.
326 expect(rootIconImage).toBeTruthy();
326 expect(rootIconImage).toBeTruthy();
327
327
328 rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
328 rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
329 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
329 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
330
330
331 expect(dom.window.document.querySelector('.file-item[data-path="/data-a/docs"]')).toBeTruthy();
331 expect(dom.window.document.querySelector('.file-item[data-path="/data-a/docs"]')).toBeTruthy();
332
332
333 dom.window.close();
333 dom.window.close();
334 });
334 });
335
335
336 test('root sidebar shows alias and original name, and excludes Move to action', async () =>
336 test('root sidebar shows alias and original name, and excludes Move to action', async () =>
337 {
337 {
338 rootsFixture = [
338 rootsFixture = [
339 { label: 'Shared', path: '/data-a', originalName: 'data-a', alias: 'Shared' },
339 { label: 'Shared', path: '/data-a', originalName: 'data-a', alias: 'Shared' },
340 { label: 'Root B', path: '/data-b', originalName: 'data-b', alias: null },
340 { label: 'Root B', path: '/data-b', originalName: 'data-b', alias: null },
341 ];
341 ];
342 meFixture = {
342 meFixture = {
343 username: 'tester',
343 username: 'tester',
344 isAdmin: false,
344 isAdmin: false,
345 permissions: {
345 permissions: {
346 'data-a': { read: true, write: true },
346 'data-a': { read: true, write: true },
347 'data-b': { read: true, write: false },
347 'data-b': { read: true, write: false },
348 },
348 },
349 };
349 };
350 spaceFixture = {
350 spaceFixture = {
351 '/data-a': { usedBytes: 1024, freeBytes: 2048 },
351 '/data-a': { usedBytes: 1024, freeBytes: 2048 },
352 '/data-b': { usedBytes: 2048, freeBytes: 1024 },
352 '/data-b': { usedBytes: 2048, freeBytes: 1024 },
353 };
353 };
354 rootAccessFixture = {
354 rootAccessFixture = {
355 '/data-a': [
355 '/data-a': [
356 { username: 'alice', mode: 'R' },
356 { username: 'alice', mode: 'R' },
357 { username: 'bob', mode: 'R+W' },
357 { username: 'bob', mode: 'R+W' },
358 ],
358 ],
359 };
359 };
360
360
361 const { dom, runtimeErrors } = await bootClient({
361 const { dom, runtimeErrors } = await bootClient({
362 savedSession: {
362 savedSession: {
363 token: 'saved-token',
363 token: 'saved-token',
364 dir: null,
364 dir: null,
365 rootPath: null,
365 rootPath: null,
366 lastOperationAt: Date.now(),
366 lastOperationAt: Date.now(),
367 },
367 },
368 });
368 });
369
369
370 expect(runtimeErrors).toEqual([]);
370 expect(runtimeErrors).toEqual([]);
371 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data-a"]'));
371 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data-a"]'));
372
372
373 const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
373 const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
374 expect(rootTile).toBeTruthy();
374 expect(rootTile).toBeTruthy();
375 rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
375 rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
376 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
376 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
377
377
378 const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
378 const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
379 expect(sidebarText).toContain('Alias');
379 expect(sidebarText).toContain('Alias');
380 expect(sidebarText).toContain('Shared');
380 expect(sidebarText).toContain('Shared');
381 expect(sidebarText).toContain('Original name');
381 expect(sidebarText).toContain('Original name');
382 expect(sidebarText).toContain('data-a');
382 expect(sidebarText).toContain('data-a');
383 expect(sidebarText).toContain('Access');
383 expect(sidebarText).toContain('Access');
384 expect(sidebarText).toContain('alice R');
384 expect(sidebarText).toContain('alice R');
385 expect(sidebarText).toContain('bob R+W');
385 expect(sidebarText).toContain('bob R+W');
386
386
387 const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
387 const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
388 expect(accessItems).toEqual(['bob R+W', 'alice R']);
388 expect(accessItems).toEqual(['bob R+W', 'alice R']);
389
389
390 const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
390 const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
391 expect(actionButtons).toContain('Rename');
391 expect(actionButtons).toContain('Rename');
392 expect(actionButtons).not.toContain('Move to');
392 expect(actionButtons).not.toContain('Move to');
393 expect(actionButtons).not.toContain('Delete');
393 expect(actionButtons).not.toContain('Delete');
394
394
395 dom.window.close();
395 dom.window.close();
396 });
396 });
397
397
398 test('base-level root sidebar shows access list with no item selected', async () =>
398 test('base-level root sidebar shows access list with no item selected', async () =>
399 {
399 {
400 rootAccessFixture = {
400 rootAccessFixture = {
401 '/data': [
401 '/data': [
402 { username: 'tim', mode: 'R+W' },
402 { username: 'tim', mode: 'R+W' },
403 { username: 'guest', mode: 'R' },
403 { username: 'guest', mode: 'R' },
404 ],
404 ],
405 };
405 };
406
406
407 const { dom, runtimeErrors } = await bootClient();
407 const { dom, runtimeErrors } = await bootClient();
408 expect(runtimeErrors).toEqual([]);
408 expect(runtimeErrors).toEqual([]);
409
409
410 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
410 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
411 const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
411 const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
412 expect(sidebarText).toContain('Access');
412 expect(sidebarText).toContain('Access');
413 expect(sidebarText).toContain('tim R+W');
413 expect(sidebarText).toContain('tim R+W');
414 expect(sidebarText).toContain('guest R');
414 expect(sidebarText).toContain('guest R');
415
415
416 const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
416 const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
417 expect(accessItems).toEqual(['tim R+W', 'guest R']);
417 expect(accessItems).toEqual(['tim R+W', 'guest R']);
418
418
419 dom.window.close();
419 dom.window.close();
420 });
420 });
421
421
422 test('shows pending icon spinner when image thumbnail cache is not ready', async () =>
422 test('shows pending icon spinner when image thumbnail cache is not ready', async () =>
423 {
423 {
424 listFixture = {
424 listFixture = {
425 '/data': [
425 '/data': [
426 {
426 {
427 name: 'photo.png',
427 name: 'photo.png',
428 path: '/data/photo.png',
428 path: '/data/photo.png',
429 isDir: false,
429 isDir: false,
430 size: 1024,
430 size: 1024,
431 mtime: Date.now(),
431 mtime: Date.now(),
432 },
432 },
433 ],
433 ],
434 };
434 };
435 thumbnailStatusFixture['/data/photo.png'] = 404;
435 thumbnailStatusFixture['/data/photo.png'] = 404;
436
436
437 const { dom, runtimeErrors } = await bootClient();
437 const { dom, runtimeErrors } = await bootClient();
438 expect(runtimeErrors).toEqual([]);
438 expect(runtimeErrors).toEqual([]);
439
439
440 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
440 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
441 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');
441 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');
442 expect(icon).toBeTruthy();
442 expect(icon).toBeTruthy();
443 expect(icon.classList.contains('thumb-pending')).toBe(true);
443 expect(icon.classList.contains('thumb-pending')).toBe(true);
444
444
445 dom.window.close();
445 dom.window.close();
446 });
446 });
447
447
448 test('admin user modal locks write checkbox while read is unchecked', async () =>
448 test('admin user modal locks write checkbox while read is unchecked', async () =>
449 {
449 {
450 meFixture = { username: 'admin', isAdmin: true, permissions: {} };
450 meFixture = { username: 'admin', isAdmin: true, permissions: {} };
451 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
451 adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
452 adminUsersFixture = {
452 adminUsersFixture = {
453 users: [
453 users: [
454 {
454 {
455 id: 9,
455 id: 9,
456 username: 'guest',
456 username: 'guest',
457 isAdmin: false,
457 isAdmin: false,
458 permissions: { data: { read: false, write: true } },
458 permissions: { data: { read: false, write: true } },
459 },
459 },
460 ],
460 ],
461 };
461 };
462
462
463 const { dom, runtimeErrors } = await bootClient();
463 const { dom, runtimeErrors } = await bootClient();
464 expect(runtimeErrors).toEqual([]);
464 expect(runtimeErrors).toEqual([]);
465
465
466 dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
466 dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
467 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
467 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
468
468
469 const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
469 const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
470 expect(editBtn).toBeTruthy();
470 expect(editBtn).toBeTruthy();
471 editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
471 editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
472 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
472 await new Promise(resolve => dom.window.setTimeout(resolve, 40));
473
473
474 const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
474 const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
475 const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
475 const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
476 expect(readCb).toBeTruthy();
476 expect(readCb).toBeTruthy();
477 expect(writeCb).toBeTruthy();
477 expect(writeCb).toBeTruthy();
478 expect(readCb.checked).toBe(false);
478 expect(readCb.checked).toBe(false);
479 expect(writeCb.checked).toBe(false);
479 expect(writeCb.checked).toBe(false);
480 expect(writeCb.disabled).toBe(true);
480 expect(writeCb.disabled).toBe(true);
481
481
482 readCb.checked = true;
482 readCb.checked = true;
483 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
483 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
484 expect(writeCb.disabled).toBe(false);
484 expect(writeCb.disabled).toBe(false);
485
485
486 writeCb.checked = true;
486 writeCb.checked = true;
487 readCb.checked = false;
487 readCb.checked = false;
488 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
488 readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
489 expect(writeCb.checked).toBe(false);
489 expect(writeCb.checked).toBe(false);
490 expect(writeCb.disabled).toBe(true);
490 expect(writeCb.disabled).toBe(true);
491
491
492 dom.window.close();
492 dom.window.close();
493 });
493 });
494
494
495 test('uses direct svg thumbnail when svg file is under 1MB', async () =>
495 test('uses direct svg thumbnail when svg file is under 1MB', async () =>
496 {
496 {
497 listFixture = {
497 listFixture = {
498 '/data': [
498 '/data': [
499 {
499 {
500 name: 'icon.svg',
500 name: 'icon.svg',
501 path: '/data/icon.svg',
501 path: '/data/icon.svg',
502 isDir: false,
502 isDir: false,
503 size: 400 * 1024,
503 size: 400 * 1024,
504 mtime: Date.now(),
504 mtime: Date.now(),
505 },
505 },
506 ],
506 ],
507 };
507 };
508 thumbnailStatusFixture['/data/icon.svg'] = 404;
508 thumbnailStatusFixture['/data/icon.svg'] = 404;
509 downloadFixture['/data/icon.svg'] = {
509 downloadFixture['/data/icon.svg'] = {
510 type: 'image/svg+xml',
510 type: 'image/svg+xml',
511 body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
511 body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
512 };
512 };
513
513
514 const { dom, runtimeErrors } = await bootClient();
514 const { dom, runtimeErrors } = await bootClient();
515 expect(runtimeErrors).toEqual([]);
515 expect(runtimeErrors).toEqual([]);
516
516
517 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
517 await new Promise(resolve => dom.window.setTimeout(resolve, 80));
518 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
518 const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
519 expect(icon).toBeTruthy();
519 expect(icon).toBeTruthy();
520 expect(icon.classList.contains('thumb-pending')).toBe(false);
520 expect(icon.classList.contains('thumb-pending')).toBe(false);
521 expect(icon.dataset.thumbReady).toBe('1');
521 expect(icon.dataset.thumbReady).toBe('1');
522
522
523 dom.window.close();
523 dom.window.close();
524 });
524 });
525});
525
526 test('expanded file preview shows a Share button next to Download', async () =>
527 {
528 downloadFixture['/data/readme.txt'] = {
529 type: 'text/plain',
530 body: 'hello preview',
531 };
532
533 const { dom, runtimeErrors } = await bootClient();
534 expect(runtimeErrors).toEqual([]);
535
536 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]'));
537
538 const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]');
539 expect(fileTile).toBeTruthy();
540
541 fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
542 await waitFor(dom, () => !!dom.window.document.querySelector('.preview-expand-share'));
543
544 const shareBtn = dom.window.document.querySelector('.preview-expand-share');
545 const downloadBtn = dom.window.document.querySelector('.preview-expand-download');
546 expect(shareBtn).toBeTruthy();
547 expect(downloadBtn).toBeTruthy();
548 expect(shareBtn.textContent).toBe('Share');
549
550 dom.window.close();
551 });
552});