| 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 | });
|