| 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.post('/api/files/video-stream', (req, res) =>
|
| 103 | {
|
| 104 | const filePath = String(req.body?.filePath || '');
|
| 105 | const payload = videoStreamFixture[filePath];
|
| 106 | if (!payload)
|
| 107 | {
|
| 108 | return res.status(404).json({ error: 'Stream not found.' });
|
| 109 | }
|
| 110 | res.json(payload);
|
| 111 | });
|
| 112 | app.get('/api/files/root-access', (req, res) =>
|
| 113 | {
|
| 114 | const rootPath = String(req.query.rootPath || '');
|
| 115 | res.json({ users: rootAccessFixture[rootPath] || [] });
|
| 116 | });
|
| 117 | app.get('/api/files/folder-icon', (req, res) =>
|
| 118 | {
|
| 119 | const dir = String(req.query.dir || '');
|
| 120 | const icon = folderIconFixture[dir] || null;
|
| 121 | res.json({ icon });
|
| 122 | });
|
| 123 | app.get('/api/files/folder-images', (req, res) =>
|
| 124 | {
|
| 125 | res.json({ images: [] });
|
| 126 | });
|
| 127 | app.get('/api/admin/config', (req, res) => res.json(adminConfigFixture));
|
| 128 | app.get('/api/admin/users', (req, res) => res.json(adminUsersFixture));
|
| 129 | app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
|
| 130 | app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
|
| 131 |
|
| 132 | server = http.createServer(app);
|
| 133 | server.listen(0);
|
| 134 | await once(server, 'listening');
|
| 135 | baseUrl = `http://127.0.0.1:${server.address().port}`;
|
| 136 | });
|
| 137 |
|
| 138 | afterAll(() => server.close());
|
| 139 |
|
| 140 | afterEach(() =>
|
| 141 | {
|
| 142 | while (openDoms.length)
|
| 143 | {
|
| 144 | const dom = openDoms.pop();
|
| 145 | try { dom.window.close(); } catch { /* ignore */ }
|
| 146 | }
|
| 147 | });
|
| 148 |
|
| 149 | async function bootClient ({ mobile = false, savedSession } = {})
|
| 150 | {
|
| 151 | const virtualConsole = new VirtualConsole();
|
| 152 | const runtimeErrors = [];
|
| 153 |
|
| 154 | virtualConsole.on('jsdomError', (err) =>
|
| 155 | {
|
| 156 | runtimeErrors.push(err);
|
| 157 | });
|
| 158 |
|
| 159 | const dom = await JSDOM.fromURL(baseUrl + '/', {
|
| 160 | resources: 'usable',
|
| 161 | runScripts: 'dangerously',
|
| 162 | pretendToBeVisual: true,
|
| 163 | virtualConsole,
|
| 164 | beforeParse (window)
|
| 165 | {
|
| 166 | window.crypto = webcrypto;
|
| 167 | window.fetch = (input, init) =>
|
| 168 | {
|
| 169 | const url = typeof input === 'string' ? input : input.url;
|
| 170 | return fetch(new URL(url, baseUrl).toString(), init);
|
| 171 | };
|
| 172 | window.HTMLElement.prototype.focus = function focus () { };
|
| 173 | window.HTMLCanvasElement.prototype.getContext = () => null;
|
| 174 | window.matchMedia = () => ({ matches: mobile, addListener () { }, removeListener () { }, addEventListener () { }, removeEventListener () { } });
|
| 175 | window.scrollTo = () => { };
|
| 176 | let blobCounter = 0;
|
| 177 | window.URL.createObjectURL = () => `blob:mock-${blobCounter++}`;
|
| 178 | window.URL.revokeObjectURL = () => { };
|
| 179 | window.__lastVideoJsOptions = null;
|
| 180 | window.videojs = (element, options) =>
|
| 181 | {
|
| 182 | window.__lastVideoJsOptions = options;
|
| 183 | return {
|
| 184 | dispose () { },
|
| 185 | };
|
| 186 | };
|
| 187 |
|
| 188 | const defaultSaved = {
|
| 189 | token: 'saved-token',
|
| 190 | dir: '/data',
|
| 191 | rootPath: '/data',
|
| 192 | lastOperationAt: Date.now(),
|
| 193 | };
|
| 194 | const effectiveSaved = savedSession === undefined ? defaultSaved : savedSession;
|
| 195 | if (effectiveSaved)
|
| 196 | {
|
| 197 | window.localStorage.setItem('filemanager.session.v1', JSON.stringify(effectiveSaved));
|
| 198 | }
|
| 199 | window.addEventListener('error', (event) => runtimeErrors.push(event.error || new Error(event.message)));
|
| 200 | window.addEventListener('unhandledrejection', (event) => runtimeErrors.push(event.reason || new Error('Unhandled rejection')));
|
| 201 | },
|
| 202 | });
|
| 203 |
|
| 204 | await new Promise((resolve) => dom.window.addEventListener('load', resolve, { once: true }));
|
| 205 | await new Promise((resolve) =>
|
| 206 | {
|
| 207 | const startedAt = Date.now();
|
| 208 | const maxWaitMs = 2000;
|
| 209 |
|
| 210 | function checkReady ()
|
| 211 | {
|
| 212 | const app = dom.window.document.getElementById('app');
|
| 213 | if (app && !app.classList.contains('hidden'))
|
| 214 | {
|
| 215 | resolve();
|
| 216 | return;
|
| 217 | }
|
| 218 |
|
| 219 | if (Date.now() - startedAt >= maxWaitMs)
|
| 220 | {
|
| 221 | resolve();
|
| 222 | return;
|
| 223 | }
|
| 224 |
|
| 225 | dom.window.setTimeout(checkReady, 25);
|
| 226 | }
|
| 227 |
|
| 228 | checkReady();
|
| 229 | });
|
| 230 |
|
| 231 | openDoms.push(dom);
|
| 232 |
|
| 233 | return { dom, runtimeErrors };
|
| 234 | }
|
| 235 |
|
| 236 | async function waitFor (dom, predicate, timeoutMs = 5000)
|
| 237 | {
|
| 238 | const startedAt = Date.now();
|
| 239 | while (Date.now() - startedAt < timeoutMs)
|
| 240 | {
|
| 241 | if (predicate()) return true;
|
| 242 | await new Promise(resolve => dom.window.setTimeout(resolve, 25));
|
| 243 | }
|
| 244 | return predicate();
|
| 245 | }
|
| 246 |
|
| 247 | test('requests / and boots the client without runtime errors', async () =>
|
| 248 | {
|
| 249 | const { dom, runtimeErrors } = await bootClient();
|
| 250 |
|
| 251 | expect(runtimeErrors).toEqual([]);
|
| 252 | expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
|
| 253 | expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(false);
|
| 254 |
|
| 255 | dom.window.close();
|
| 256 | });
|
| 257 |
|
| 258 | test('login overlay uses username and current-password autocomplete tokens', async () =>
|
| 259 | {
|
| 260 | const { dom, runtimeErrors } = await bootClient({ savedSession: null });
|
| 261 |
|
| 262 | expect(runtimeErrors).toEqual([]);
|
| 263 |
|
| 264 | const username = dom.window.document.getElementById('auth-username');
|
| 265 | const password = dom.window.document.getElementById('auth-password');
|
| 266 | expect(username.getAttribute('autocomplete')).toBe('username');
|
| 267 | expect(password.getAttribute('autocomplete')).toBe('current-password');
|
| 268 |
|
| 269 | dom.window.close();
|
| 270 | });
|
| 271 |
|
| 272 | test('first-run setup uses new-password autocomplete token', async () =>
|
| 273 | {
|
| 274 | setupNeededFixture = true;
|
| 275 |
|
| 276 | const { dom, runtimeErrors } = await bootClient({ savedSession: null });
|
| 277 |
|
| 278 | expect(runtimeErrors).toEqual([]);
|
| 279 |
|
| 280 | const password = dom.window.document.getElementById('auth-password');
|
| 281 | expect(password.getAttribute('autocomplete')).toBe('new-password');
|
| 282 |
|
| 283 | dom.window.close();
|
| 284 | });
|
| 285 |
|
| 286 | test('keeps sidebar folded on initial mobile boot', async () =>
|
| 287 | {
|
| 288 | const { dom, runtimeErrors } = await bootClient({ mobile: true });
|
| 289 |
|
| 290 | expect(runtimeErrors).toEqual([]);
|
| 291 | expect(dom.window.document.getElementById('app').classList.contains('hidden')).toBe(false);
|
| 292 | expect(dom.window.document.getElementById('sidebar').classList.contains('hidden')).toBe(true);
|
| 293 |
|
| 294 | dom.window.close();
|
| 295 | });
|
| 296 |
|
| 297 | test('suppresses default context menu on mobile file long-press', async () =>
|
| 298 | {
|
| 299 | const { dom, runtimeErrors } = await bootClient({ mobile: true });
|
| 300 |
|
| 301 | expect(runtimeErrors).toEqual([]);
|
| 302 |
|
| 303 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item'));
|
| 304 |
|
| 305 | const tile = dom.window.document.querySelector('.file-item');
|
| 306 | expect(tile).toBeTruthy();
|
| 307 |
|
| 308 | const evt = new dom.window.MouseEvent('contextmenu', {
|
| 309 | bubbles: true,
|
| 310 | cancelable: true,
|
| 311 | view: dom.window,
|
| 312 | });
|
| 313 |
|
| 314 | const dispatchResult = tile.dispatchEvent(evt);
|
| 315 | expect(dispatchResult).toBe(false);
|
| 316 | expect(evt.defaultPrevented).toBe(true);
|
| 317 |
|
| 318 | dom.window.close();
|
| 319 | });
|
| 320 |
|
| 321 | test('in Home, root tiles single-click focus and double-click open', async () =>
|
| 322 | {
|
| 323 | rootsFixture = [
|
| 324 | { label: 'Root A', path: '/data-a' },
|
| 325 | { label: 'Root B', path: '/data-b' },
|
| 326 | ];
|
| 327 | listFixture = {
|
| 328 | '/data-a': [
|
| 329 | {
|
| 330 | name: 'docs',
|
| 331 | path: '/data-a/docs',
|
| 332 | isDir: true,
|
| 333 | size: 0,
|
| 334 | mtime: Date.now(),
|
| 335 | },
|
| 336 | ],
|
| 337 | };
|
| 338 | spaceFixture = {
|
| 339 | '/data-a': { usedBytes: 2048, freeBytes: 4096 },
|
| 340 | '/data-b': { usedBytes: 1024, freeBytes: 8192 },
|
| 341 | };
|
| 342 | folderIconFixture = {
|
| 343 | '/data-a': { filePath: '/data-a/docs/cover.jpg' },
|
| 344 | };
|
| 345 |
|
| 346 | const { dom, runtimeErrors } = await bootClient({
|
| 347 | savedSession: {
|
| 348 | token: 'saved-token',
|
| 349 | dir: null,
|
| 350 | rootPath: null,
|
| 351 | lastOperationAt: Date.now(),
|
| 352 | },
|
| 353 | });
|
| 354 | expect(runtimeErrors).toEqual([]);
|
| 355 |
|
| 356 | const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
|
| 357 | expect(rootTile).toBeTruthy();
|
| 358 |
|
| 359 | rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 360 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 361 |
|
| 362 | expect(rootTile.classList.contains('selected')).toBe(true);
|
| 363 | expect(dom.window.document.querySelector('.file-item[data-path="/data-b"]')).toBeTruthy();
|
| 364 | expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
|
| 365 | expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
|
| 366 |
|
| 367 | let rootIconImage = null;
|
| 368 | for (let i = 0; i < 10; i++)
|
| 369 | {
|
| 370 | const rootIconSvg = rootTile.querySelector('.icon svg');
|
| 371 | rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
|
| 372 | if (rootIconImage) break;
|
| 373 | await new Promise(resolve => dom.window.setTimeout(resolve, 25));
|
| 374 | }
|
| 375 | // Root tiles should load folder icon thumbnails in Home view.
|
| 376 | expect(rootIconImage).toBeTruthy();
|
| 377 |
|
| 378 | rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 379 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 380 |
|
| 381 | expect(dom.window.document.querySelector('.file-item[data-path="/data-a/docs"]')).toBeTruthy();
|
| 382 |
|
| 383 | dom.window.close();
|
| 384 | });
|
| 385 |
|
| 386 | test('root sidebar shows alias and original name, and excludes Move to action', async () =>
|
| 387 | {
|
| 388 | rootsFixture = [
|
| 389 | { label: 'Shared', path: '/data-a', originalName: 'data-a', alias: 'Shared' },
|
| 390 | { label: 'Root B', path: '/data-b', originalName: 'data-b', alias: null },
|
| 391 | ];
|
| 392 | meFixture = {
|
| 393 | username: 'tester',
|
| 394 | isAdmin: false,
|
| 395 | permissions: {
|
| 396 | 'data-a': { read: true, write: true },
|
| 397 | 'data-b': { read: true, write: false },
|
| 398 | },
|
| 399 | };
|
| 400 | spaceFixture = {
|
| 401 | '/data-a': { usedBytes: 1024, freeBytes: 2048 },
|
| 402 | '/data-b': { usedBytes: 2048, freeBytes: 1024 },
|
| 403 | };
|
| 404 | rootAccessFixture = {
|
| 405 | '/data-a': [
|
| 406 | { username: 'alice', mode: 'R' },
|
| 407 | { username: 'bob', mode: 'R+W' },
|
| 408 | ],
|
| 409 | };
|
| 410 |
|
| 411 | const { dom, runtimeErrors } = await bootClient({
|
| 412 | savedSession: {
|
| 413 | token: 'saved-token',
|
| 414 | dir: null,
|
| 415 | rootPath: null,
|
| 416 | lastOperationAt: Date.now(),
|
| 417 | },
|
| 418 | });
|
| 419 |
|
| 420 | expect(runtimeErrors).toEqual([]);
|
| 421 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data-a"]'));
|
| 422 |
|
| 423 | const rootTile = dom.window.document.querySelector('.file-item[data-path="/data-a"]');
|
| 424 | expect(rootTile).toBeTruthy();
|
| 425 | rootTile.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 426 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 427 |
|
| 428 | const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
|
| 429 | expect(sidebarText).toContain('Alias');
|
| 430 | expect(sidebarText).toContain('Shared');
|
| 431 | expect(sidebarText).toContain('Original name');
|
| 432 | expect(sidebarText).toContain('data-a');
|
| 433 | expect(sidebarText).toContain('Access');
|
| 434 | expect(sidebarText).toContain('alice R');
|
| 435 | expect(sidebarText).toContain('bob R+W');
|
| 436 |
|
| 437 | const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
|
| 438 | expect(accessItems).toEqual(['bob R+W', 'alice R']);
|
| 439 |
|
| 440 | const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
|
| 441 | expect(actionButtons).toContain('Rename');
|
| 442 | expect(actionButtons).not.toContain('Move to');
|
| 443 | expect(actionButtons).not.toContain('Delete');
|
| 444 |
|
| 445 | dom.window.close();
|
| 446 | });
|
| 447 |
|
| 448 | test('base-level root sidebar shows access list with no item selected', async () =>
|
| 449 | {
|
| 450 | rootAccessFixture = {
|
| 451 | '/data': [
|
| 452 | { username: 'tim', mode: 'R+W' },
|
| 453 | { username: 'guest', mode: 'R' },
|
| 454 | ],
|
| 455 | };
|
| 456 |
|
| 457 | const { dom, runtimeErrors } = await bootClient();
|
| 458 | expect(runtimeErrors).toEqual([]);
|
| 459 |
|
| 460 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 461 | const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
|
| 462 | expect(sidebarText).toContain('Access');
|
| 463 | expect(sidebarText).toContain('tim R+W');
|
| 464 | expect(sidebarText).toContain('guest R');
|
| 465 |
|
| 466 | const accessItems = Array.from(dom.window.document.querySelectorAll('#sidebar-meta .root-access-list li')).map(li => li.textContent.trim());
|
| 467 | expect(accessItems).toEqual(['tim R+W', 'guest R']);
|
| 468 |
|
| 469 | dom.window.close();
|
| 470 | });
|
| 471 |
|
| 472 | test('shows pending icon spinner when image thumbnail cache is not ready', async () =>
|
| 473 | {
|
| 474 | listFixture = {
|
| 475 | '/data': [
|
| 476 | {
|
| 477 | name: 'photo.png',
|
| 478 | path: '/data/photo.png',
|
| 479 | isDir: false,
|
| 480 | size: 1024,
|
| 481 | mtime: Date.now(),
|
| 482 | },
|
| 483 | ],
|
| 484 | };
|
| 485 | thumbnailStatusFixture['/data/photo.png'] = 404;
|
| 486 |
|
| 487 | const { dom, runtimeErrors } = await bootClient();
|
| 488 | expect(runtimeErrors).toEqual([]);
|
| 489 |
|
| 490 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 491 | const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');
|
| 492 | expect(icon).toBeTruthy();
|
| 493 | expect(icon.classList.contains('thumb-pending')).toBe(true);
|
| 494 |
|
| 495 | dom.window.close();
|
| 496 | });
|
| 497 |
|
| 498 | test('admin user modal locks write checkbox while read is unchecked', async () =>
|
| 499 | {
|
| 500 | meFixture = { username: 'admin', isAdmin: true, permissions: {} };
|
| 501 | adminConfigFixture = { port: 3000, paths: ['/data'], effectivePaths: ['/data'] };
|
| 502 | adminUsersFixture = {
|
| 503 | users: [
|
| 504 | {
|
| 505 | id: 9,
|
| 506 | username: 'guest',
|
| 507 | isAdmin: false,
|
| 508 | permissions: { data: { read: false, write: true } },
|
| 509 | },
|
| 510 | ],
|
| 511 | };
|
| 512 |
|
| 513 | const { dom, runtimeErrors } = await bootClient();
|
| 514 | expect(runtimeErrors).toEqual([]);
|
| 515 |
|
| 516 | dom.window.document.getElementById('btn-admin').dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 517 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 518 |
|
| 519 | const editBtn = dom.window.document.querySelector('#admin-users-list [data-action="edit"]');
|
| 520 | expect(editBtn).toBeTruthy();
|
| 521 | editBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
|
| 522 | await new Promise(resolve => dom.window.setTimeout(resolve, 40));
|
| 523 |
|
| 524 | const readCb = dom.window.document.querySelector('input[data-label="data"][data-type="read"]');
|
| 525 | const writeCb = dom.window.document.querySelector('input[data-label="data"][data-type="write"]');
|
| 526 | expect(readCb).toBeTruthy();
|
| 527 | expect(writeCb).toBeTruthy();
|
| 528 | expect(readCb.checked).toBe(false);
|
| 529 | expect(writeCb.checked).toBe(false);
|
| 530 | expect(writeCb.disabled).toBe(true);
|
| 531 |
|
| 532 | readCb.checked = true;
|
| 533 | readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
| 534 | expect(writeCb.disabled).toBe(false);
|
| 535 |
|
| 536 | writeCb.checked = true;
|
| 537 | readCb.checked = false;
|
| 538 | readCb.dispatchEvent(new dom.window.Event('change', { bubbles: true }));
|
| 539 | expect(writeCb.checked).toBe(false);
|
| 540 | expect(writeCb.disabled).toBe(true);
|
| 541 |
|
| 542 | dom.window.close();
|
| 543 | });
|
| 544 |
|
| 545 | test('uses direct svg thumbnail when svg file is under 1MB', async () =>
|
| 546 | {
|
| 547 | listFixture = {
|
| 548 | '/data': [
|
| 549 | {
|
| 550 | name: 'icon.svg',
|
| 551 | path: '/data/icon.svg',
|
| 552 | isDir: false,
|
| 553 | size: 400 * 1024,
|
| 554 | mtime: Date.now(),
|
| 555 | },
|
| 556 | ],
|
| 557 | };
|
| 558 | thumbnailStatusFixture['/data/icon.svg'] = 404;
|
| 559 | downloadFixture['/data/icon.svg'] = {
|
| 560 | type: 'image/svg+xml',
|
| 561 | body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><rect width="10" height="10" fill="red"/></svg>',
|
| 562 | };
|
| 563 |
|
| 564 | const { dom, runtimeErrors } = await bootClient();
|
| 565 | expect(runtimeErrors).toEqual([]);
|
| 566 |
|
| 567 | await new Promise(resolve => dom.window.setTimeout(resolve, 80));
|
| 568 | const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/icon.svg"]');
|
| 569 | expect(icon).toBeTruthy();
|
| 570 | expect(icon.classList.contains('thumb-pending')).toBe(false);
|
| 571 | expect(icon.dataset.thumbReady).toBe('1');
|
| 572 |
|
| 573 | dom.window.close();
|
| 574 | });
|
| 575 |
|
| 576 | test('expanded file preview shows a Share button next to Download', async () =>
|
| 577 | {
|
| 578 | downloadFixture['/data/readme.txt'] = {
|
| 579 | type: 'text/plain',
|
| 580 | body: 'hello preview',
|
| 581 | };
|
| 582 |
|
| 583 | const { dom, runtimeErrors } = await bootClient();
|
| 584 | expect(runtimeErrors).toEqual([]);
|
| 585 |
|
| 586 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]'));
|
| 587 |
|
| 588 | const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]');
|
| 589 | expect(fileTile).toBeTruthy();
|
| 590 |
|
| 591 | fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 592 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-expand-share'));
|
| 593 |
|
| 594 | const shareBtn = dom.window.document.querySelector('.preview-expand-share');
|
| 595 | const downloadBtn = dom.window.document.querySelector('.preview-expand-download');
|
| 596 | const actions = dom.window.document.querySelector('.preview-expand-actions');
|
| 597 | expect(shareBtn).toBeTruthy();
|
| 598 | expect(downloadBtn).toBeTruthy();
|
| 599 | expect(actions).toBeTruthy();
|
| 600 | expect(actions.contains(shareBtn)).toBe(true);
|
| 601 | expect(actions.contains(downloadBtn)).toBe(true);
|
| 602 | expect(shareBtn.textContent).toBe('Share');
|
| 603 |
|
| 604 | dom.window.close();
|
| 605 | });
|
| 606 |
|
| 607 | test('expanded video preview uses a stream session and video.js', async () =>
|
| 608 | {
|
| 609 | listFixture['/data'] = [
|
| 610 | {
|
| 611 | name: 'clip.mkv',
|
| 612 | path: '/data/clip.mkv',
|
| 613 | isDir: false,
|
| 614 | size: 64,
|
| 615 | mtime: Date.now(),
|
| 616 | },
|
| 617 | ];
|
| 618 | videoStreamFixture['/data/clip.mkv'] = {
|
| 619 | sessionId: 'video-session',
|
| 620 | playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
|
| 621 | subtitleTracks: [{ label: 'English', language: 'eng', default: true, src: '/api/files/video-stream/video-session/subtitle-0.vtt' }],
|
| 622 | };
|
| 623 |
|
| 624 | const { dom, runtimeErrors } = await bootClient();
|
| 625 | expect(runtimeErrors).toEqual([]);
|
| 626 |
|
| 627 | await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
|
| 628 |
|
| 629 | const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
|
| 630 | expect(fileTile).toBeTruthy();
|
| 631 |
|
| 632 | fileTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
|
| 633 | await waitFor(dom, () => !!dom.window.document.querySelector('.preview-video-js'));
|
| 634 |
|
| 635 | expect(dom.window.__lastVideoJsOptions).toBeTruthy();
|
| 636 | expect(dom.window.__lastVideoJsOptions.sources[0].src).toBe('/api/files/video-stream/video-session/master.m3u8');
|
| 637 | expect(dom.window.__lastVideoJsOptions.tracks).toEqual([
|
| 638 | {
|
| 639 | kind: 'subtitles',
|
| 640 | src: '/api/files/video-stream/video-session/subtitle-0.vtt',
|
| 641 | srclang: 'eng',
|
| 642 | label: 'English',
|
| 643 | default: true,
|
| 644 | },
|
| 645 | ]);
|
| 646 |
|
| 647 | dom.window.close();
|
| 648 | });
|
| 649 | });
|