| 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.__lastVideoJsPlayer = null; |
| 204 | window.videojs = (element, options) => |
| 205 | { |
| 206 | window.__lastVideoJsOptions = options; |
| 207 | let volumeValue = 1; |
| 208 | let durationValue = 20; |
| 209 | const player = { |
| 210 | ready (cb) |
| 211 | { |
| 212 | if (typeof cb === 'function') cb(); |
| 213 | }, |
| 214 | on () { }, |
| 215 | trigger () { }, |
| 216 | duration (next) |
| 217 | { |
| 218 | if (next === undefined) return durationValue; |
| 219 | durationValue = Number(next); |
| 220 | return durationValue; |
| 221 | }, |
| 222 | currentTime () { return 0; }, |
| 223 | volume (next) |
| 224 | { |
| 225 | if (next === undefined) return volumeValue;
|
| 226 | volumeValue = Number(next);
|
| 227 | window.__lastVideoJsVolumeSet = volumeValue;
|
| 228 | return volumeValue;
|
| 229 | }, |
| 230 | dispose () { }, |
| 231 | }; |
| 232 | window.__lastVideoJsPlayer = player; |
| 233 | return player; |
| 234 | }; |
| 235 |
|
| 236 | const defaultSaved = {
|
| 237 | token: 'saved-token',
|
| 238 | dir: '/data',
|
| 239 | rootPath: '/data',
|
| 240 | lastOperationAt: Date.now(),
|
| 241 | };
|
| 242 | const effectiveSaved = savedSession === undefined ? defaultSaved : savedSession;
|
| 243 | if (effectiveSaved)
|
| 244 | {
|
| 245 | window.localStorage.setItem('filemanager.session.v1', JSON.stringify(effectiveSaved));
|
| 246 | }
|
| 247 | window.addEventListener('error', (event) => runtimeErrors.push(event.error || new Error(event.message)));
|
| 248 | window.addEventListener('unhandledrejection', (event) => runtimeErrors.push(event.reason || new Error('Unhandled rejection')));
|
| 249 | },
|
| 250 | });
|
| 251 |
|
| 252 | await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
|
| 253 | await new Promise((resolve) =>
|
| 254 | {
|
| 255 | const startedAt = Date.now();
|
| 256 | const maxWaitMs = 2000;
|
| 257 |
|
| 258 | function checkReady ()
|
| 259 | {
|
| 260 | const app = dom.window.document.getElementById('app');
|
| 261 | if (app && !app.classList.contains('hidden'))
|
| 262 | {
|
| 263 | resolve();
|
| 264 | return;
|
| 265 | }
|
| 266 |
|
| 267 | if (Date.now() - startedAt >= maxWaitMs)
|
| 268 | {
|
| 269 | resolve();
|
| 270 | return;
|
| 271 | }
|
| 272 |
|
| 273 | dom.window.setTimeout(checkReady, 25);
|
| 274 | }
|
| 275 |
|
| 276 | checkReady();
|
| 277 | });
|
| 278 |
|
| 279 | openDoms.push(dom);
|
| 280 |
|
| 281 | return { dom, runtimeErrors };
|
| 282 | }
|
| 283 |
|
| 284 | async function waitFor (dom, predicate, timeoutMs = 5000)
|
| 285 | {
|
| 286 | const startedAt = Date.now();
|
| 287 | while (Date.now() - startedAt < timeoutMs)
|
| 288 | {
|
| 289 | if (predicate()) return true;
|
| 290 | await new Promise(resolve => dom.window.setTimeout(resolve, 25));
|
| 291 | }
|
| 292 | return predicate();
|
| 293 | }
|
| 294 |
|
| 295 | test('requests / and boots the client without runtime errors', async () =>
|
| 296 | {
|
| 297 | const { dom, runtimeErrors } = await bootClient();
|
| 298 |
|
| 299 | expect(runtimeErrors).toEqual([]);
|
| 300 | expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
|
| 301 | expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(false);
|
| 302 |
|
| 303 | dom.window.close();
|
| 304 | });
|
| 305 |
|
| 306 | test('login overlay uses username and current-password autocomplete tokens', async () =>
|
| 307 | {
|
| 308 | const { dom, runtimeErrors } = await bootClient({ savedSession: null });
|
| 309 |
|
| 310 | expect(runtimeErrors).toEqual([]);
|
| 311 |
|
| 312 | const username = dom.window.document.getElementById('auth-username');
|
| 313 | const password = dom.window.document.getElementById('auth-password');
|
| 314 | expect(username.getAttribute('autocomplete')).toBe('username');
|
| 315 | expect(password.getAttribute('autocomplete')).toBe('current-password');
|
| 316 |
|
| 317 | dom.window.close();
|
| 318 | });
|
| 319 |
|
| 320 | test('first-run setup uses new-password autocomplete token', async () =>
|
| 321 | {
|
| 322 | setupNeededFixture = true;
|
| 323 |
|
| 324 | const { dom, runtimeErrors } = await bootClient({ savedSession: null });
|
| 325 |
|
| 326 | expect(runtimeErrors).toEqual([]);
|
| 327 |
|
| 328 | const password = dom.window.document.getElementById('auth-password');
|
| 329 | expect(password.getAttribute('autocomplete')).toBe('new-password');
|
| 330 |
|
| 331 | dom.window.close();
|
| 332 | });
|
| 333 |
|
| 334 | test('keeps sidebar folded on initial mobile boot', async () =>
|
| 335 | {
|
| 336 | const { dom, runtimeErrors } = await bootClient({ mobile: true });
|
| 337 |
|
| 338 | expect(runtimeErrors).toEqual([]);
|
| 339 | expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
|
| 340 | expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(true);
|
| 341 |
|
| 342 | dom.window.close();
|
| 343 | });
|
| 344 |
|
| 345 | test('suppresses default context menu on mobile file long-press', async () =>
|
| 346 | {
|
| 347 | const { dom, runtimeErrors } = await bootClient({ mobile: true });
|
| 348 |
|
| 349 | expect(runtimeErrors).toEqual([]);
|
| 350 |
|
| 351 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item'));
|
| 352 |
|
| 353 | const tile = dom.window.document.querySelector('.file-item');
|
| 354 | expect(tile).toBeTruthy();
|
| 355 |
|
| 356 | const evt = new dom.window.MouseEvent('contextmenu', {
|
| 357 | bubbles: true,
|
| 358 | cancelable: true,
|
| 359 | view: dom.window,
|
| 360 | });
|
| 361 |
|
| 362 | const dispatchResult = tile.dispatchEvent(evt);
|
| 363 | expect(dispatchResult).toBe(false);
|
| 364 | expect(evt.defaultPrevented).toBe(true);
|
| 365 |
|
| 366 | dom.window.close();
|
| 367 | });
|
| 368 |
|
| 369 | test('in Home, root tiles single-click focus and double-click open', async () =>
|
| 370 | {
|
| 371 | rootsFixture = [
|
| 372 | { label: 'Root A', path: '/data-a' },
|
| 373 | { label: 'Root B', path: '/data-b' },
|
| 374 | ];
|
| 375 | listFixture = {
|
| 376 | '/data-a': [
|
| 377 | {
|
| 378 | name: 'docs',
|
| 379 | path: '/data-a/docs',
|
| 380 | isDir: true,
|
| 381 | size: 0,
|
| 382 | mtime: Date.now(),
|
| 383 | },
|
| 384 | ],
|
| 385 | };
|
| 386 | spaceFixture = {
|
| 387 | '/data-a': { usedBytes: 2048, freeBytes: 4096 },
|
| 388 | '/data-b': { usedBytes: 1024, freeBytes: 8192 },
|
| 389 | };
|
| 390 | folderIconFixture = {
|
| 391 | '/data-a': { filePath: '/data-a/docs/cover.jpg' },
|
| 392 | };
|
| 393 |
|
| 394 | const { dom, runtimeErrors } = await bootClient({
|
| 395 | savedSession: {
|
| 396 | token: 'saved-token',
|
| 397 | dir: null,
|
| 398 | rootPath: null,
|
| 399 | lastOperationAt: Date.now(),
|
| 400 | },
|
| 401 | });
|
| 402 | expect(runtimeErrors).toEqual([]);
|
| 403 |
|
| 404 | const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
|
| 405 | expect(rootTile).toBeTruthy();
|
| 406 |
|
| 407 | rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 408 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 409 |
|
| 410 | expect(rootTile.classList.contains('selected')).toBe(true);
|
| 411 | expect(dom.window.document.querySelector('.file-item[data-path="/data-b"]')).toBeTruthy();
|
| 412 | expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
|
| 413 | expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
|
| 414 |
|
| 415 | let rootIconImage = null;
|
| 416 | for (let i = 0; i < 10; i++)
|
| 417 | {
|
| 418 | const rootIconSvg = rootTile.querySelector('.icon svg');
|
| 419 | rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
|
| 420 | if (rootIconImage) break;
|
| 421 | await new Promise(resolve => dom.window.setTimeout(resolve, 25));
|
| 422 | }
|
| 423 | // Root tiles should load folder icon thumbnails in Home view.
|
| 424 | expect(rootIconImage).toBeTruthy();
|
| 425 |
|
| 426 | rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 427 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 428 |
|
| 429 | expect(dom.window.document.querySelector('.file-item[data-path="/data-a/docs"]')).toBeTruthy();
|
| 430 |
|
| 431 | dom.window.close();
|
| 432 | });
|
| 433 |
|
| 434 | test('root sidebar shows alias and original name, and excludes Move to action', async () =>
|
| 435 | {
|
| 436 | rootsFixture = [
|
| 437 | { label: 'Shared', path: '/data-a', originalName: 'data-a', alias: 'Shared' },
|
| 438 | { label: 'Root B', path: '/data-b', originalName: 'data-b', alias: null },
|
| 439 | ];
|
| 440 | meFixture = {
|
| 441 | username: 'tester',
|
| 442 | isAdmin: false,
|
| 443 | permissions: {
|
| 444 | 'data-a': { read: true, write: true },
|
| 445 | 'data-b': { read: true, write: false },
|
| 446 | },
|
| 447 | };
|
| 448 | spaceFixture = {
|
| 449 | '/data-a': { usedBytes: 1024, freeBytes: 2048 },
|
| 450 | '/data-b': { usedBytes: 2048, freeBytes: 1024 },
|
| 451 | };
|
| 452 | rootAccessFixture = {
|
| 453 | '/data-a': [
|
| 454 | { username: 'alice', mode: 'R' },
|
| 455 | { username: 'bob', mode: 'R+W' },
|
| 456 | ],
|
| 457 | };
|
| 458 |
|
| 459 | const { dom, runtimeErrors } = await bootClient({
|
| 460 | savedSession: {
|
| 461 | token: 'saved-token',
|
| 462 | dir: null,
|
| 463 | rootPath: null,
|
| 464 | lastOperationAt: Date.now(),
|
| 465 | },
|
| 466 | });
|
| 467 |
|
| 468 | expect(runtimeErrors).toEqual([]);
|
| 469 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data-a"]'));
|
| 470 |
|
| 471 | const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
|
| 472 | expect(rootTile).toBeTruthy();
|
| 473 | rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 474 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 475 |
|
| 476 | const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
|
| 477 | expect(sidebarText).toContain('Alias');
|
| 478 | expect(sidebarText).toContain('Shared');
|
| 479 | expect(sidebarText).toContain('Original name');
|
| 480 | expect(sidebarText).toContain('data-a');
|
| 481 | expect(sidebarText).toContain('Access');
|
| 482 | expect(sidebarText).toContain('alice R');
|
| 483 | expect(sidebarText).toContain('bob R+W');
|
| 484 |
|
| 485 | const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
|
| 486 | expect(accessItems).toEqual(['bob R+W', 'alice R']);
|
| 487 |
|
| 488 | const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
|
| 489 | expect(actionButtons).toContain('Rename');
|
| 490 | expect(actionButtons).not.toContain('Move to');
|
| 491 | expect(actionButtons).not.toContain('Delete');
|
| 492 |
|
| 493 | dom.window.close();
|
| 494 | });
|
| 495 |
|
| 496 | test('base-level root sidebar shows access list with no item selected', async () =>
|
| 497 | {
|
| 498 | rootAccessFixture = {
|
| 499 | '/data': [
|
| 500 | { username: 'tim', mode: 'R+W' },
|
| 501 | { username: 'guest', mode: 'R' },
|
| 502 | ],
|
| 503 | };
|
| 504 |
|
| 505 | const { dom, runtimeErrors } = await bootClient();
|
| 506 | expect(runtimeErrors).toEqual([]);
|
| 507 |
|
| 508 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 509 | const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
|
| 510 | expect(sidebarText).toContain('Access');
|
| 511 | expect(sidebarText).toContain('tim R+W');
|
| 512 | expect(sidebarText).toContain('guest R');
|
| 513 |
|
| 514 | const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
|
| 515 | expect(accessItems).toEqual(['tim R+W', 'guest R']);
|
| 516 |
|
| 517 | dom.window.close();
|
| 518 | });
|
| 519 |
|
| 520 | test('shows pending icon spinner when image thumbnail cache is not ready', async () =>
|
| 521 | {
|
| 522 | listFixture = {
|
| 523 | '/data': [
|
| 524 | {
|
| 525 | name: 'photo.png',
|
| 526 | path: '/data/photo.png',
|
| 527 | isDir: false,
|
| 528 | size: 1024,
|
| 529 | mtime: Date.now(),
|
| 530 | },
|
| 531 | ],
|
| 532 | };
|
| 533 | thumbnailStatusFixture['/data/photo.png'] = 404;
|
| 534 |
|
| 535 | const { dom, runtimeErrors } = await bootClient();
|
| 536 | expect(runtimeErrors).toEqual([]);
|
| 537 |
|
| 538 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 539 | const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');
|
| 540 | expect(icon).toBeTruthy();
|
| 541 | expect(icon.classList.contains('thumb-pending')).toBe(true);
|
| 542 |
|
| 543 | dom.window.close();
|
| 544 | });
|
| 545 |
|
| 546 | test('admin user modal locks write checkbox while read is unchecked', async () =>
|
| 547 | {
|
| 548 | meFixture = { username: 'admin', isAdmin: true, permissions: {} };
|
| 549 | adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
|
| 550 | adminUsersFixture = {
|
| 551 | users: [
|
| 552 | {
|
| 553 | id: 9,
|
| 554 | username: 'guest',
|
| 555 | isAdmin: false,
|
| 556 | permissions: { data: { read: false, write: true } },
|
| 557 | },
|
| 558 | ],
|
| 559 | };
|
| 560 |
|
| 561 | const { dom, runtimeErrors } = await bootClient();
|
| 562 | expect(runtimeErrors).toEqual([]);
|
| 563 |
|
| 564 | dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 565 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 566 |
|
| 567 | const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
|
| 568 | expect(editBtn).toBeTruthy();
|
| 569 | editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 570 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 571 |
|
| 572 | const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
|
| 573 | const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
|
| 574 | expect(readCb).toBeTruthy();
|
| 575 | expect(writeCb).toBeTruthy();
|
| 576 | expect(readCb.checked).toBe(false);
|
| 577 | expect(writeCb.checked).toBe(false);
|
| 578 | expect(writeCb.disabled).toBe(true);
|
| 579 |
|
| 580 | readCb.checked = true;
|
| 581 | readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
| 582 | expect(writeCb.disabled).toBe(false);
|
| 583 |
|
| 584 | writeCb.checked = true;
|
| 585 | readCb.checked = false;
|
| 586 | readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
| 587 | expect(writeCb.checked).toBe(false);
|
| 588 | expect(writeCb.disabled).toBe(true);
|
| 589 |
|
| 590 | dom.window.close();
|
| 591 | });
|
| 592 |
|
| 593 | test('uses direct svg thumbnail when svg file is under 1MB', async () =>
|
| 594 | {
|
| 595 | listFixture = {
|
| 596 | '/data': [
|
| 597 | {
|
| 598 | name: 'icon.svg',
|
| 599 | path: '/data/icon.svg',
|
| 600 | isDir: false,
|
| 601 | size: 400 * 1024,
|
| 602 | mtime: Date.now(),
|
| 603 | },
|
| 604 | ],
|
| 605 | };
|
| 606 | thumbnailStatusFixture['/data/icon.svg'] = 404;
|
| 607 | downloadFixture['/data/icon.svg'] = {
|
| 608 | type: 'image/svg+xml',
|
| 609 | body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
|
| 610 | };
|
| 611 |
|
| 612 | const { dom, runtimeErrors } = await bootClient();
|
| 613 | expect(runtimeErrors).toEqual([]);
|
| 614 |
|
| 615 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 616 | const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
|
| 617 | expect(icon).toBeTruthy();
|
| 618 | expect(icon.classList.contains('thumb-pending')).toBe(false);
|
| 619 | expect(icon.dataset.thumbReady).toBe('1');
|
| 620 |
|
| 621 | dom.window.close();
|
| 622 | });
|
| 623 |
|
| 624 | test('expanded file preview shows a Share button next to Download', async () =>
|
| 625 | {
|
| 626 | downloadFixture['/data/readme.txt'] = {
|
| 627 | type: 'text/plain',
|
| 628 | body: 'hello preview',
|
| 629 | };
|
| 630 |
|
| 631 | const { dom, runtimeErrors } = await bootClient();
|
| 632 | expect(runtimeErrors).toEqual([]);
|
| 633 |
|
| 634 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]'));
|
| 635 |
|
| 636 | const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]');
|
| 637 | expect(fileTile).toBeTruthy();
|
| 638 |
|
| 639 | fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 640 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-expand-share'));
|
| 641 |
|
| 642 | const shareBtn = dom.window.document.querySelector('.preview-expand-share');
|
| 643 | const downloadBtn = dom.window.document.querySelector('.preview-expand-download');
|
| 644 | const actions = dom.window.document.querySelector('.preview-expand-actions');
|
| 645 | expect(shareBtn).toBeTruthy();
|
| 646 | expect(downloadBtn).toBeTruthy();
|
| 647 | expect(actions).toBeTruthy();
|
| 648 | expect(actions.contains(shareBtn)).toBe(true);
|
| 649 | expect(actions.contains(downloadBtn)).toBe(true);
|
| 650 | expect(shareBtn.textContent).toBe('Share');
|
| 651 |
|
| 652 | dom.window.close();
|
| 653 | });
|
| 654 |
|
| 655 | test('expanded video preview uses a stream session and video.js', async () =>
|
| 656 | {
|
| 657 | listFixture['/data'] = [
|
| 658 | {
|
| 659 | name: 'clip.mkv',
|
| 660 | path: '/data/clip.mkv',
|
| 661 | isDir: false,
|
| 662 | size: 64,
|
| 663 | mtime: Date.now(),
|
| 664 | },
|
| 665 | ];
|
| 666 | videoStreamFixture['/data/clip.mkv'] = { |
| 667 | sessionId: 'video-session', |
| 668 | playlistUrl: '/api/files/video-stream/video-session/master.m3u8', |
| 669 | durationSeconds: 120, |
| 670 | subtitleTracks: [{ label: 'English', language: 'eng', default: true, src: '/api/files/video-stream/video-session/subtitle-0.vtt' }], |
| 671 | }; |
| 672 |
|
| 673 | const { dom, runtimeErrors } = await bootClient();
|
| 674 | expect(runtimeErrors).toEqual([]);
|
| 675 |
|
| 676 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
|
| 677 |
|
| 678 | const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
|
| 679 | expect(fileTile).toBeTruthy();
|
| 680 |
|
| 681 | fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 682 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-video-js'));
|
| 683 |
|
| 684 | expect(dom.window.__lastVideoJsOptions).toBeTruthy();
|
| 685 | expect(dom.window.__lastVideoJsOptions.sources[0].src).toBe('/api/files/video-stream/video-session/master.m3u8'); |
| 686 | expect(dom.window.__lastVideoJsOptions.fluid).toBe(false); |
| 687 | expect(dom.window.__lastVideoJsOptions.fill).toBe(true); |
| 688 | expect(dom.window.__lastVideoJsOptions.controlBar).toMatchObject({ |
| 689 | currentTimeDisplay: true, |
| 690 | timeDivider: true, |
| 691 | durationDisplay: true, |
| 692 | remainingTimeDisplay: false, |
| 693 | }); |
| 694 | expect(dom.window.__lastVideoJsPlayer.duration()).toBe(120); |
| 695 | expect(dom.window.__lastVideoJsOptions.tracks).toEqual([ |
| 696 | {
|
| 697 | kind: 'subtitles',
|
| 698 | src: '/api/files/video-stream/video-session/subtitle-0.vtt',
|
| 699 | srclang: 'eng',
|
| 700 | label: 'English',
|
| 701 | default: true,
|
| 702 | },
|
| 703 | ]);
|
| 704 |
|
| 705 | dom.window.close();
|
| 706 | });
|
| 707 |
|
| 708 | test('video preview does not close on backdrop click and closes via X button', async () =>
|
| 709 | {
|
| 710 | listFixture['/data'] = [
|
| 711 | {
|
| 712 | name: 'clip.mkv',
|
| 713 | path: '/data/clip.mkv',
|
| 714 | isDir: false,
|
| 715 | size: 64,
|
| 716 | mtime: Date.now(),
|
| 717 | },
|
| 718 | ];
|
| 719 | videoStreamFixture['/data/clip.mkv'] = {
|
| 720 | sessionId: 'video-session',
|
| 721 | playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
|
| 722 | subtitleTracks: [],
|
| 723 | subtitleSummary: { total: 0, converted: 0, skipped: 0 },
|
| 724 | };
|
| 725 |
|
| 726 | const { dom, runtimeErrors } = await bootClient();
|
| 727 | expect(runtimeErrors).toEqual([]);
|
| 728 |
|
| 729 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
|
| 730 |
|
| 731 | const tile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
|
| 732 | tile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 733 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-backdrop'));
|
| 734 |
|
| 735 | const backdrop = dom.window.document.querySelector('.preview-backdrop');
|
| 736 | backdrop.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 737 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 738 |
|
| 739 | expect(dom.window.document.querySelector('.preview-backdrop')).toBeTruthy();
|
| 740 |
|
| 741 | const closeBtn = dom.window.document.querySelector('.preview-expand-close');
|
| 742 | closeBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 743 | await new Promise(resolve => dom.window.setTimeout(resolve, 280));
|
| 744 |
|
| 745 | expect(dom.window.document.querySelector('.preview-backdrop')).toBeNull();
|
| 746 |
|
| 747 | dom.window.close();
|
| 748 | });
|
| 749 |
|
| 750 | test('video preview restores per-user saved volume preference', async () =>
|
| 751 | {
|
| 752 | listFixture['/data'] = [
|
| 753 | {
|
| 754 | name: 'clip.mkv',
|
| 755 | path: '/data/clip.mkv',
|
| 756 | isDir: false,
|
| 757 | size: 64,
|
| 758 | mtime: Date.now(),
|
| 759 | },
|
| 760 | ];
|
| 761 | videoStreamFixture['/data/clip.mkv'] = {
|
| 762 | sessionId: 'video-session',
|
| 763 | playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
|
| 764 | subtitleTracks: [],
|
| 765 | subtitleSummary: { total: 0, converted: 0, skipped: 0 },
|
| 766 | };
|
| 767 |
|
| 768 | const { dom, runtimeErrors } = await bootClient();
|
| 769 | expect(runtimeErrors).toEqual([]);
|
| 770 |
|
| 771 | dom.window.localStorage.setItem('filemanager.video-prefs.v1.tester', JSON.stringify({ volume: 0.3 }));
|
| 772 |
|
| 773 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
|
| 774 |
|
| 775 | const tile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
|
| 776 | tile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 777 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-video-js'));
|
| 778 |
|
| 779 | expect(dom.window.__lastVideoJsVolumeSet).toBe(0.3);
|
| 780 |
|
| 781 | dom.window.close();
|
| 782 | });
|
| 783 |
|
| 784 | test('video preview saves caption style settings per user on close', async () =>
|
| 785 | {
|
| 786 | listFixture['/data'] = [
|
| 787 | {
|
| 788 | name: 'clip.mkv',
|
| 789 | path: '/data/clip.mkv',
|
| 790 | isDir: false,
|
| 791 | size: 64,
|
| 792 | mtime: Date.now(),
|
| 793 | },
|
| 794 | ];
|
| 795 | videoStreamFixture['/data/clip.mkv'] = {
|
| 796 | sessionId: 'video-session',
|
| 797 | playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
|
| 798 | subtitleTracks: [{ label: 'English', language: 'eng', default: true, src: '/api/files/video-stream/video-session/subtitle-0.vtt' }],
|
| 799 | subtitleSummary: { total: 1, converted: 1, skipped: 0 },
|
| 800 | };
|
| 801 |
|
| 802 | const { dom, runtimeErrors } = await bootClient();
|
| 803 | expect(runtimeErrors).toEqual([]);
|
| 804 |
|
| 805 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
|
| 806 | const tile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
|
| 807 | tile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 808 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-video-js'));
|
| 809 |
|
| 810 | // Simulate updated caption style persisted by Video.js internals.
|
| 811 | dom.window.localStorage.setItem('vjs-text-track-settings', '{"color":"#ffffff"}');
|
| 812 |
|
| 813 | const closeBtn = dom.window.document.querySelector('.preview-expand-close');
|
| 814 | closeBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 815 | await new Promise(resolve => dom.window.setTimeout(resolve, 280));
|
| 816 |
|
| 817 | const stored = JSON.parse(dom.window.localStorage.getItem('filemanager.video-prefs.v1.tester'));
|
| 818 | expect(stored.textTrackSettings).toBe('{"color":"#ffffff"}');
|
| 819 |
|
| 820 | dom.window.close();
|
| 821 | });
|
| 822 | });
|