| 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 | let videoStreamFixture;
|
| 26 | let setupNeededFixture;
|
| 27 | const openDoms = [];
|
| 28 |
|
| 29 | beforeEach(() =>
|
| 30 | {
|
| 31 | rootsFixture = [{ label: 'Root', path: '/data' }];
|
| 32 | listFixture = {
|
| 33 | '/data': [
|
| 34 | {
|
| 35 | name: 'readme.txt',
|
| 36 | path: '/data/readme.txt',
|
| 37 | isDir: false,
|
| 38 | size: 12,
|
| 39 | mtime: Date.now(),
|
| 40 | },
|
| 41 | ],
|
| 42 | };
|
| 43 | spaceFixture = {
|
| 44 | '/data': { usedBytes: 0, freeBytes: 1024 * 1024 },
|
| 45 | };
|
| 46 | meFixture = { username: 'tester', isAdmin: false, permissions: {} };
|
| 47 | thumbnailStatusFixture = {};
|
| 48 | rootAccessFixture = {};
|
| 49 | folderIconFixture = {};
|
| 50 | adminUsersFixture = { users: [] };
|
| 51 | adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
|
| 52 | downloadFixture = {};
|
| 53 | videoStreamFixture = {};
|
| 54 | setupNeededFixture = false;
|
| 55 | });
|
| 56 |
|
| 57 | beforeAll(async () =>
|
| 58 | {
|
| 59 | ({ JSDOM, VirtualConsole } = require('jsdom'));
|
| 60 |
|
| 61 | const app = express();
|
| 62 | const publicDir = path.join(__dirname, '../public');
|
| 63 |
|
| 64 | app.use(express.json());
|
| 65 | app.use(express.static(publicDir));
|
| 66 |
|
| 67 | app.get('/api/auth/server-key', (req, res) => res.json({ publicKey: null }));
|
| 68 | app.get('/api/auth/setup-needed', (req, res) => res.json({ needed: setupNeededFixture }));
|
| 69 | app.get('/api/auth/me', (req, res) => res.json(meFixture));
|
| 70 | app.get('/api/files/roots', (req, res) => res.json({ roots: rootsFixture }));
|
| 71 | app.get('/api/files/list', (req, res) =>
|
| 72 | {
|
| 73 | const dir = req.query.dir;
|
| 74 | res.json({ items: listFixture[dir] || [] });
|
| 75 | });
|
| 76 | app.get('/api/files/space', (req, res) =>
|
| 77 | {
|
| 78 | const dir = req.query.dir;
|
| 79 | const stats = spaceFixture[dir] || { usedBytes: 0, freeBytes: null };
|
| 80 | res.json(stats);
|
| 81 | });
|
| 82 | app.get('/api/files/thumbnail', (req, res) =>
|
| 83 | {
|
| 84 | const file = String(req.query.file || '');
|
| 85 | const status = Number(thumbnailStatusFixture[file] || 200);
|
| 86 | if (status === 404)
|
| 87 | {
|
| 88 | return res.status(404).json({ error: 'Thumbnail not ready.' });
|
| 89 | }
|
| 90 | res.type('image/webp').send('thumb');
|
| 91 | });
|
| 92 | app.get('/api/files/download', (req, res) =>
|
| 93 | {
|
| 94 | const file = String(req.query.file || '');
|
| 95 | const payload = downloadFixture[file];
|
| 96 | if (!payload)
|
| 97 | {
|
| 98 | return res.status(404).json({ error: 'File not found.' });
|
| 99 | }
|
| 100 | res.type(payload.type || 'application/octet-stream').send(payload.body || 'x');
|
| 101 | });
|
| 102 | app.get('/api/files/meta', (req, res) =>
|
| 103 | {
|
| 104 | const file = String(req.query.file || '');
|
| 105 | const allItems = Object.values(listFixture).flat();
|
| 106 | const item = allItems.find((it) => it.path === file);
|
| 107 | if (!item)
|
| 108 | {
|
| 109 | return res.status(404).json({ error: 'File not found.' });
|
| 110 | }
|
| 111 | res.json({
|
| 112 | name: item.name,
|
| 113 | size: item.size || 0,
|
| 114 | mtime: new Date(item.mtime || Date.now()).toISOString(),
|
| 115 | uploader: '',
|
| 116 | downloaders: [],
|
| 117 | watchedBy: {},
|
| 118 | });
|
| 119 | });
|
| 120 | app.post('/api/files/video-stream', (req, res) =>
|
| 121 | {
|
| 122 | const filePath = String(req.body?.filePath || '');
|
| 123 | const payload = videoStreamFixture[filePath];
|
| 124 | if (!payload)
|
| 125 | {
|
| 126 | return res.status(404).json({ error: 'Stream not found.' });
|
| 127 | }
|
| 128 | res.json(payload);
|
| 129 | });
|
| 130 | app.post('/api/files/watch-progress', (req, res) =>
|
| 131 | {
|
| 132 | res.json({ ok: true, updated: true });
|
| 133 | });
|
| 134 | app.get('/api/files/root-access', (req, res) =>
|
| 135 | {
|
| 136 | const rootPath = String(req.query.rootPath || '');
|
| 137 | res.json({ users: rootAccessFixture[rootPath] || [] });
|
| 138 | });
|
| 139 | app.get('/api/files/folder-icon', (req, res) =>
|
| 140 | {
|
| 141 | const dir = String(req.query.dir || '');
|
| 142 | const icon = folderIconFixture[dir] || null;
|
| 143 | res.json({ icon });
|
| 144 | });
|
| 145 | app.get('/api/files/folder-images', (req, res) =>
|
| 146 | {
|
| 147 | res.json({ images: [] });
|
| 148 | });
|
| 149 | app.get('/api/admin/config', (req, res) => res.json(adminConfigFixture));
|
| 150 | app.get('/api/admin/users', (req, res) => res.json(adminUsersFixture));
|
| 151 | app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
|
| 152 | app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
|
| 153 |
|
| 154 | server = http.createServer(app);
|
| 155 | server.listen(0);
|
| 156 | await once(server, 'listening');
|
| 157 | baseUrl = `http://127.0.0.1:${server.address().port}`;
|
| 158 | });
|
| 159 |
|
| 160 | afterAll(() => server.close());
|
| 161 |
|
| 162 | afterEach(() =>
|
| 163 | {
|
| 164 | while (openDoms.length)
|
| 165 | {
|
| 166 | const dom = openDoms.pop();
|
| 167 | try { dom.window.close(); } catch { /* ignore */ }
|
| 168 | }
|
| 169 | });
|
| 170 |
|
| 171 | async function bootClient ({ mobile = false, savedSession } = {})
|
| 172 | {
|
| 173 | const virtualConsole = new VirtualConsole();
|
| 174 | const runtimeErrors = [];
|
| 175 |
|
| 176 | virtualConsole.on('jsdomError', (err) =>
|
| 177 | {
|
| 178 | runtimeErrors.push(err);
|
| 179 | });
|
| 180 |
|
| 181 | const dom = await JSDOM.fromURL(baseUrl + '/', {
|
| 182 | resources: 'usable',
|
| 183 | runScripts: 'dangerously',
|
| 184 | pretendToBeVisual: true,
|
| 185 | virtualConsole,
|
| 186 | beforeParse (window)
|
| 187 | {
|
| 188 | window.crypto = webcrypto;
|
| 189 | window.fetch = (input, init) =>
|
| 190 | {
|
| 191 | const url = typeof input === 'string' ? input : input.url;
|
| 192 | return fetch(new URL(url, baseUrl).toString(), init);
|
| 193 | };
|
| 194 | window.HTMLElement.prototype.focus = function focus () { };
|
| 195 | window.HTMLCanvasElement.prototype.getContext = () => null;
|
| 196 | window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
|
| 197 | window.scrollTo = () => { };
|
| 198 | let blobCounter = 0;
|
| 199 | window.URL.createObjectURL = () => `blob:mock-${blobCounter++}`;
|
| 200 | window.URL.revokeObjectURL = () => { };
|
| 201 | window.__lastVideoJsOptions = null;
|
| 202 | window.__lastVideoJsVolumeSet = null;
|
| 203 | window.videojs = (element, options) =>
|
| 204 | {
|
| 205 | window.__lastVideoJsOptions = options;
|
| 206 | let volumeValue = 1;
|
| 207 | return {
|
| 208 | ready (cb)
|
| 209 | {
|
| 210 | if (typeof cb === 'function') cb();
|
| 211 | },
|
| 212 | on () { },
|
| 213 | duration () { return 100; },
|
| 214 | currentTime () { return 0; },
|
| 215 | volume (next)
|
| 216 | {
|
| 217 | if (next === undefined) return volumeValue;
|
| 218 | volumeValue = Number(next);
|
| 219 | window.__lastVideoJsVolumeSet = volumeValue;
|
| 220 | return volumeValue;
|
| 221 | },
|
| 222 | dispose () { },
|
| 223 | };
|
| 224 | };
|
| 225 |
|
| 226 | const defaultSaved = {
|
| 227 | token: 'saved-token',
|
| 228 | dir: '/data',
|
| 229 | rootPath: '/data',
|
| 230 | lastOperationAt: Date.now(),
|
| 231 | };
|
| 232 | const effectiveSaved = savedSession === undefined ? defaultSaved : savedSession;
|
| 233 | if (effectiveSaved)
|
| 234 | {
|
| 235 | window.localStorage.setItem('filemanager.session.v1', JSON.stringify(effectiveSaved));
|
| 236 | }
|
| 237 | window.addEventListener('error', (event) => runtimeErrors.push(event.error || new Error(event.message)));
|
| 238 | window.addEventListener('unhandledrejection', (event) => runtimeErrors.push(event.reason || new Error('Unhandled rejection')));
|
| 239 | },
|
| 240 | });
|
| 241 |
|
| 242 | await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
|
| 243 | await new Promise((resolve) =>
|
| 244 | {
|
| 245 | const startedAt = Date.now();
|
| 246 | const maxWaitMs = 2000;
|
| 247 |
|
| 248 | function checkReady ()
|
| 249 | {
|
| 250 | const app = dom.window.document.getElementById('app');
|
| 251 | if (app && !app.classList.contains('hidden'))
|
| 252 | {
|
| 253 | resolve();
|
| 254 | return;
|
| 255 | }
|
| 256 |
|
| 257 | if (Date.now() - startedAt >= maxWaitMs)
|
| 258 | {
|
| 259 | resolve();
|
| 260 | return;
|
| 261 | }
|
| 262 |
|
| 263 | dom.window.setTimeout(checkReady, 25);
|
| 264 | }
|
| 265 |
|
| 266 | checkReady();
|
| 267 | });
|
| 268 |
|
| 269 | openDoms.push(dom);
|
| 270 |
|
| 271 | return { dom, runtimeErrors };
|
| 272 | }
|
| 273 |
|
| 274 | async function waitFor (dom, predicate, timeoutMs = 5000)
|
| 275 | {
|
| 276 | const startedAt = Date.now();
|
| 277 | while (Date.now() - startedAt < timeoutMs)
|
| 278 | {
|
| 279 | if (predicate()) return true;
|
| 280 | await new Promise(resolve => dom.window.setTimeout(resolve, 25));
|
| 281 | }
|
| 282 | return predicate();
|
| 283 | }
|
| 284 |
|
| 285 | test('requests / and boots the client without runtime errors', async () =>
|
| 286 | {
|
| 287 | const { dom, runtimeErrors } = await bootClient();
|
| 288 |
|
| 289 | expect(runtimeErrors).toEqual([]);
|
| 290 | expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
|
| 291 | expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(false);
|
| 292 |
|
| 293 | dom.window.close();
|
| 294 | });
|
| 295 |
|
| 296 | test('login overlay uses username and current-password autocomplete tokens', async () =>
|
| 297 | {
|
| 298 | const { dom, runtimeErrors } = await bootClient({ savedSession: null });
|
| 299 |
|
| 300 | expect(runtimeErrors).toEqual([]);
|
| 301 |
|
| 302 | const username = dom.window.document.getElementById('auth-username');
|
| 303 | const password = dom.window.document.getElementById('auth-password');
|
| 304 | expect(username.getAttribute('autocomplete')).toBe('username');
|
| 305 | expect(password.getAttribute('autocomplete')).toBe('current-password');
|
| 306 |
|
| 307 | dom.window.close();
|
| 308 | });
|
| 309 |
|
| 310 | test('first-run setup uses new-password autocomplete token', async () =>
|
| 311 | {
|
| 312 | setupNeededFixture = true;
|
| 313 |
|
| 314 | const { dom, runtimeErrors } = await bootClient({ savedSession: null });
|
| 315 |
|
| 316 | expect(runtimeErrors).toEqual([]);
|
| 317 |
|
| 318 | const password = dom.window.document.getElementById('auth-password');
|
| 319 | expect(password.getAttribute('autocomplete')).toBe('new-password');
|
| 320 |
|
| 321 | dom.window.close();
|
| 322 | });
|
| 323 |
|
| 324 | test('keeps sidebar folded on initial mobile boot', async () =>
|
| 325 | {
|
| 326 | const { dom, runtimeErrors } = await bootClient({ mobile: true });
|
| 327 |
|
| 328 | expect(runtimeErrors).toEqual([]);
|
| 329 | expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
|
| 330 | expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(true);
|
| 331 |
|
| 332 | dom.window.close();
|
| 333 | });
|
| 334 |
|
| 335 | test('suppresses default context menu on mobile file long-press', async () =>
|
| 336 | {
|
| 337 | const { dom, runtimeErrors } = await bootClient({ mobile: true });
|
| 338 |
|
| 339 | expect(runtimeErrors).toEqual([]);
|
| 340 |
|
| 341 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item'));
|
| 342 |
|
| 343 | const tile = dom.window.document.querySelector('.file-item');
|
| 344 | expect(tile).toBeTruthy();
|
| 345 |
|
| 346 | const evt = new dom.window.MouseEvent('contextmenu', {
|
| 347 | bubbles: true,
|
| 348 | cancelable: true,
|
| 349 | view: dom.window,
|
| 350 | });
|
| 351 |
|
| 352 | const dispatchResult = tile.dispatchEvent(evt);
|
| 353 | expect(dispatchResult).toBe(false);
|
| 354 | expect(evt.defaultPrevented).toBe(true);
|
| 355 |
|
| 356 | dom.window.close();
|
| 357 | });
|
| 358 |
|
| 359 | test('in Home, root tiles single-click focus and double-click open', async () =>
|
| 360 | {
|
| 361 | rootsFixture = [
|
| 362 | { label: 'Root A', path: '/data-a' },
|
| 363 | { label: 'Root B', path: '/data-b' },
|
| 364 | ];
|
| 365 | listFixture = {
|
| 366 | '/data-a': [
|
| 367 | {
|
| 368 | name: 'docs',
|
| 369 | path: '/data-a/docs',
|
| 370 | isDir: true,
|
| 371 | size: 0,
|
| 372 | mtime: Date.now(),
|
| 373 | },
|
| 374 | ],
|
| 375 | };
|
| 376 | spaceFixture = {
|
| 377 | '/data-a': { usedBytes: 2048, freeBytes: 4096 },
|
| 378 | '/data-b': { usedBytes: 1024, freeBytes: 8192 },
|
| 379 | };
|
| 380 | folderIconFixture = {
|
| 381 | '/data-a': { filePath: '/data-a/docs/cover.jpg' },
|
| 382 | };
|
| 383 |
|
| 384 | const { dom, runtimeErrors } = await bootClient({
|
| 385 | savedSession: {
|
| 386 | token: 'saved-token',
|
| 387 | dir: null,
|
| 388 | rootPath: null,
|
| 389 | lastOperationAt: Date.now(),
|
| 390 | },
|
| 391 | });
|
| 392 | expect(runtimeErrors).toEqual([]);
|
| 393 |
|
| 394 | const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
|
| 395 | expect(rootTile).toBeTruthy();
|
| 396 |
|
| 397 | rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 398 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 399 |
|
| 400 | expect(rootTile.classList.contains('selected')).toBe(true);
|
| 401 | expect(dom.window.document.querySelector('.file-item[data-path="/data-b"]')).toBeTruthy();
|
| 402 | expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
|
| 403 | expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
|
| 404 |
|
| 405 | let rootIconImage = null;
|
| 406 | for (let i = 0; i < 10; i++)
|
| 407 | {
|
| 408 | const rootIconSvg = rootTile.querySelector('.icon svg');
|
| 409 | rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
|
| 410 | if (rootIconImage) break;
|
| 411 | await new Promise(resolve => dom.window.setTimeout(resolve, 25));
|
| 412 | }
|
| 413 | // Root tiles should load folder icon thumbnails in Home view.
|
| 414 | expect(rootIconImage).toBeTruthy();
|
| 415 |
|
| 416 | rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 417 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 418 |
|
| 419 | expect(dom.window.document.querySelector('.file-item[data-path="/data-a/docs"]')).toBeTruthy();
|
| 420 |
|
| 421 | dom.window.close();
|
| 422 | });
|
| 423 |
|
| 424 | test('root sidebar shows alias and original name, and excludes Move to action', async () =>
|
| 425 | {
|
| 426 | rootsFixture = [
|
| 427 | { label: 'Shared', path: '/data-a', originalName: 'data-a', alias: 'Shared' },
|
| 428 | { label: 'Root B', path: '/data-b', originalName: 'data-b', alias: null },
|
| 429 | ];
|
| 430 | meFixture = {
|
| 431 | username: 'tester',
|
| 432 | isAdmin: false,
|
| 433 | permissions: {
|
| 434 | 'data-a': { read: true, write: true },
|
| 435 | 'data-b': { read: true, write: false },
|
| 436 | },
|
| 437 | };
|
| 438 | spaceFixture = {
|
| 439 | '/data-a': { usedBytes: 1024, freeBytes: 2048 },
|
| 440 | '/data-b': { usedBytes: 2048, freeBytes: 1024 },
|
| 441 | };
|
| 442 | rootAccessFixture = {
|
| 443 | '/data-a': [
|
| 444 | { username: 'alice', mode: 'R' },
|
| 445 | { username: 'bob', mode: 'R+W' },
|
| 446 | ],
|
| 447 | };
|
| 448 |
|
| 449 | const { dom, runtimeErrors } = await bootClient({
|
| 450 | savedSession: {
|
| 451 | token: 'saved-token',
|
| 452 | dir: null,
|
| 453 | rootPath: null,
|
| 454 | lastOperationAt: Date.now(),
|
| 455 | },
|
| 456 | });
|
| 457 |
|
| 458 | expect(runtimeErrors).toEqual([]);
|
| 459 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data-a"]'));
|
| 460 |
|
| 461 | const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
|
| 462 | expect(rootTile).toBeTruthy();
|
| 463 | rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 464 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 465 |
|
| 466 | const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
|
| 467 | expect(sidebarText).toContain('Alias');
|
| 468 | expect(sidebarText).toContain('Shared');
|
| 469 | expect(sidebarText).toContain('Original name');
|
| 470 | expect(sidebarText).toContain('data-a');
|
| 471 | expect(sidebarText).toContain('Access');
|
| 472 | expect(sidebarText).toContain('alice R');
|
| 473 | expect(sidebarText).toContain('bob R+W');
|
| 474 |
|
| 475 | const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
|
| 476 | expect(accessItems).toEqual(['bob R+W', 'alice R']);
|
| 477 |
|
| 478 | const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
|
| 479 | expect(actionButtons).toContain('Rename');
|
| 480 | expect(actionButtons).not.toContain('Move to');
|
| 481 | expect(actionButtons).not.toContain('Delete');
|
| 482 |
|
| 483 | dom.window.close();
|
| 484 | });
|
| 485 |
|
| 486 | test('base-level root sidebar shows access list with no item selected', async () =>
|
| 487 | {
|
| 488 | rootAccessFixture = {
|
| 489 | '/data': [
|
| 490 | { username: 'tim', mode: 'R+W' },
|
| 491 | { username: 'guest', mode: 'R' },
|
| 492 | ],
|
| 493 | };
|
| 494 |
|
| 495 | const { dom, runtimeErrors } = await bootClient();
|
| 496 | expect(runtimeErrors).toEqual([]);
|
| 497 |
|
| 498 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 499 | const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
|
| 500 | expect(sidebarText).toContain('Access');
|
| 501 | expect(sidebarText).toContain('tim R+W');
|
| 502 | expect(sidebarText).toContain('guest R');
|
| 503 |
|
| 504 | const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
|
| 505 | expect(accessItems).toEqual(['tim R+W', 'guest R']);
|
| 506 |
|
| 507 | dom.window.close();
|
| 508 | });
|
| 509 |
|
| 510 | test('shows pending icon spinner when image thumbnail cache is not ready', async () =>
|
| 511 | {
|
| 512 | listFixture = {
|
| 513 | '/data': [
|
| 514 | {
|
| 515 | name: 'photo.png',
|
| 516 | path: '/data/photo.png',
|
| 517 | isDir: false,
|
| 518 | size: 1024,
|
| 519 | mtime: Date.now(),
|
| 520 | },
|
| 521 | ],
|
| 522 | };
|
| 523 | thumbnailStatusFixture['/data/photo.png'] = 404;
|
| 524 |
|
| 525 | const { dom, runtimeErrors } = await bootClient();
|
| 526 | expect(runtimeErrors).toEqual([]);
|
| 527 |
|
| 528 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 529 | const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');
|
| 530 | expect(icon).toBeTruthy();
|
| 531 | expect(icon.classList.contains('thumb-pending')).toBe(true);
|
| 532 |
|
| 533 | dom.window.close();
|
| 534 | });
|
| 535 |
|
| 536 | test('admin user modal locks write checkbox while read is unchecked', async () =>
|
| 537 | {
|
| 538 | meFixture = { username: 'admin', isAdmin: true, permissions: {} };
|
| 539 | adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
|
| 540 | adminUsersFixture = {
|
| 541 | users: [
|
| 542 | {
|
| 543 | id: 9,
|
| 544 | username: 'guest',
|
| 545 | isAdmin: false,
|
| 546 | permissions: { data: { read: false, write: true } },
|
| 547 | },
|
| 548 | ],
|
| 549 | };
|
| 550 |
|
| 551 | const { dom, runtimeErrors } = await bootClient();
|
| 552 | expect(runtimeErrors).toEqual([]);
|
| 553 |
|
| 554 | dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 555 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 556 |
|
| 557 | const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
|
| 558 | expect(editBtn).toBeTruthy();
|
| 559 | editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 560 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 561 |
|
| 562 | const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
|
| 563 | const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
|
| 564 | expect(readCb).toBeTruthy();
|
| 565 | expect(writeCb).toBeTruthy();
|
| 566 | expect(readCb.checked).toBe(false);
|
| 567 | expect(writeCb.checked).toBe(false);
|
| 568 | expect(writeCb.disabled).toBe(true);
|
| 569 |
|
| 570 | readCb.checked = true;
|
| 571 | readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
| 572 | expect(writeCb.disabled).toBe(false);
|
| 573 |
|
| 574 | writeCb.checked = true;
|
| 575 | readCb.checked = false;
|
| 576 | readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
| 577 | expect(writeCb.checked).toBe(false);
|
| 578 | expect(writeCb.disabled).toBe(true);
|
| 579 |
|
| 580 | dom.window.close();
|
| 581 | });
|
| 582 |
|
| 583 | test('uses direct svg thumbnail when svg file is under 1MB', async () =>
|
| 584 | {
|
| 585 | listFixture = {
|
| 586 | '/data': [
|
| 587 | {
|
| 588 | name: 'icon.svg',
|
| 589 | path: '/data/icon.svg',
|
| 590 | isDir: false,
|
| 591 | size: 400 * 1024,
|
| 592 | mtime: Date.now(),
|
| 593 | },
|
| 594 | ],
|
| 595 | };
|
| 596 | thumbnailStatusFixture['/data/icon.svg'] = 404;
|
| 597 | downloadFixture['/data/icon.svg'] = {
|
| 598 | type: 'image/svg+xml',
|
| 599 | body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
|
| 600 | };
|
| 601 |
|
| 602 | const { dom, runtimeErrors } = await bootClient();
|
| 603 | expect(runtimeErrors).toEqual([]);
|
| 604 |
|
| 605 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 606 | const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
|
| 607 | expect(icon).toBeTruthy();
|
| 608 | expect(icon.classList.contains('thumb-pending')).toBe(false);
|
| 609 | expect(icon.dataset.thumbReady).toBe('1');
|
| 610 |
|
| 611 | dom.window.close();
|
| 612 | });
|
| 613 |
|
| 614 | test('expanded file preview shows a Share button next to Download', async () =>
|
| 615 | {
|
| 616 | downloadFixture['/data/readme.txt'] = {
|
| 617 | type: 'text/plain',
|
| 618 | body: 'hello preview',
|
| 619 | };
|
| 620 |
|
| 621 | const { dom, runtimeErrors } = await bootClient();
|
| 622 | expect(runtimeErrors).toEqual([]);
|
| 623 |
|
| 624 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]'));
|
| 625 |
|
| 626 | const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]');
|
| 627 | expect(fileTile).toBeTruthy();
|
| 628 |
|
| 629 | fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 630 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-expand-share'));
|
| 631 |
|
| 632 | const shareBtn = dom.window.document.querySelector('.preview-expand-share');
|
| 633 | const downloadBtn = dom.window.document.querySelector('.preview-expand-download');
|
| 634 | const actions = dom.window.document.querySelector('.preview-expand-actions');
|
| 635 | expect(shareBtn).toBeTruthy();
|
| 636 | expect(downloadBtn).toBeTruthy();
|
| 637 | expect(actions).toBeTruthy();
|
| 638 | expect(actions.contains(shareBtn)).toBe(true);
|
| 639 | expect(actions.contains(downloadBtn)).toBe(true);
|
| 640 | expect(shareBtn.textContent).toBe('Share');
|
| 641 |
|
| 642 | dom.window.close();
|
| 643 | });
|
| 644 |
|
| 645 | test('expanded video preview uses a stream session and video.js', async () =>
|
| 646 | {
|
| 647 | listFixture['/data'] = [
|
| 648 | {
|
| 649 | name: 'clip.mkv',
|
| 650 | path: '/data/clip.mkv',
|
| 651 | isDir: false,
|
| 652 | size: 64,
|
| 653 | mtime: Date.now(),
|
| 654 | },
|
| 655 | ];
|
| 656 | videoStreamFixture['/data/clip.mkv'] = {
|
| 657 | sessionId: 'video-session',
|
| 658 | playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
|
| 659 | subtitleTracks: [{ label: 'English', language: 'eng', default: true, src: '/api/files/video-stream/video-session/subtitle-0.vtt' }],
|
| 660 | };
|
| 661 |
|
| 662 | const { dom, runtimeErrors } = await bootClient();
|
| 663 | expect(runtimeErrors).toEqual([]);
|
| 664 |
|
| 665 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
|
| 666 |
|
| 667 | const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
|
| 668 | expect(fileTile).toBeTruthy();
|
| 669 |
|
| 670 | fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 671 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-video-js'));
|
| 672 |
|
| 673 | expect(dom.window.__lastVideoJsOptions).toBeTruthy();
|
| 674 | expect(dom.window.__lastVideoJsOptions.sources[0].src).toBe('/api/files/video-stream/video-session/master.m3u8');
|
| 675 | expect(dom.window.__lastVideoJsOptions.tracks).toEqual([
|
| 676 | {
|
| 677 | kind: 'subtitles',
|
| 678 | src: '/api/files/video-stream/video-session/subtitle-0.vtt',
|
| 679 | srclang: 'eng',
|
| 680 | label: 'English',
|
| 681 | default: true,
|
| 682 | },
|
| 683 | ]);
|
| 684 |
|
| 685 | dom.window.close();
|
| 686 | });
|
| 687 |
|
| 688 | test('video preview does not close on backdrop click and closes via X button', async () =>
|
| 689 | {
|
| 690 | listFixture['/data'] = [
|
| 691 | {
|
| 692 | name: 'clip.mkv',
|
| 693 | path: '/data/clip.mkv',
|
| 694 | isDir: false,
|
| 695 | size: 64,
|
| 696 | mtime: Date.now(),
|
| 697 | },
|
| 698 | ];
|
| 699 | videoStreamFixture['/data/clip.mkv'] = {
|
| 700 | sessionId: 'video-session',
|
| 701 | playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
|
| 702 | subtitleTracks: [],
|
| 703 | subtitleSummary: { total: 0, converted: 0, skipped: 0 },
|
| 704 | };
|
| 705 |
|
| 706 | const { dom, runtimeErrors } = await bootClient();
|
| 707 | expect(runtimeErrors).toEqual([]);
|
| 708 |
|
| 709 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
|
| 710 |
|
| 711 | const tile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
|
| 712 | tile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 713 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-backdrop'));
|
| 714 |
|
| 715 | const backdrop = dom.window.document.querySelector('.preview-backdrop');
|
| 716 | backdrop.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 717 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 718 |
|
| 719 | expect(dom.window.document.querySelector('.preview-backdrop')).toBeTruthy();
|
| 720 |
|
| 721 | const closeBtn = dom.window.document.querySelector('.preview-expand-close');
|
| 722 | closeBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 723 | await new Promise(resolve => dom.window.setTimeout(resolve, 280));
|
| 724 |
|
| 725 | expect(dom.window.document.querySelector('.preview-backdrop')).toBeNull();
|
| 726 |
|
| 727 | dom.window.close();
|
| 728 | });
|
| 729 |
|
| 730 | test('video preview restores per-user saved volume preference', async () =>
|
| 731 | {
|
| 732 | listFixture['/data'] = [
|
| 733 | {
|
| 734 | name: 'clip.mkv',
|
| 735 | path: '/data/clip.mkv',
|
| 736 | isDir: false,
|
| 737 | size: 64,
|
| 738 | mtime: Date.now(),
|
| 739 | },
|
| 740 | ];
|
| 741 | videoStreamFixture['/data/clip.mkv'] = {
|
| 742 | sessionId: 'video-session',
|
| 743 | playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
|
| 744 | subtitleTracks: [],
|
| 745 | subtitleSummary: { total: 0, converted: 0, skipped: 0 },
|
| 746 | };
|
| 747 |
|
| 748 | const { dom, runtimeErrors } = await bootClient();
|
| 749 | expect(runtimeErrors).toEqual([]);
|
| 750 |
|
| 751 | dom.window.localStorage.setItem('filemanager.video-prefs.v1.tester', JSON.stringify({ volume: 0.3 }));
|
| 752 |
|
| 753 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
|
| 754 |
|
| 755 | const tile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
|
| 756 | tile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 757 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-video-js'));
|
| 758 |
|
| 759 | expect(dom.window.__lastVideoJsVolumeSet).toBe(0.3);
|
| 760 |
|
| 761 | dom.window.close();
|
| 762 | });
|
| 763 | });
|