| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556 |
- /**
- * Tests for the FileManagerPage component.
- */
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
- import { screen, waitFor, within } from '@testing-library/react';
- import userEvent from '@testing-library/user-event';
- import { render } from '../utils';
- import { FileManagerPage } from '../../pages/FileManagerPage';
- import { openInSlicer } from '../../utils/slicer';
- import { setAuthToken } from '../../api/client';
- import { http, HttpResponse } from 'msw';
- import { server } from '../mocks/server';
- // Only the protocol-handler launch is stubbed — it would navigate the jsdom
- // window. Everything else in the module is a pure predicate, so keep the real
- // implementations: isSliceableFilename decides which rows even offer the
- // action these tests click.
- vi.mock('../../utils/slicer', async (importOriginal) => ({
- ...(await importOriginal<typeof import('../../utils/slicer')>()),
- openInSlicer: vi.fn(),
- }));
- vi.mock('../../components/SliceModal', () => ({
- SliceModal: ({ source }: { source: { filename: string } }) => (
- <div data-testid="slice-modal">{source.filename}</div>
- ),
- }));
- // Mock data
- const mockFolders = [
- {
- id: 1,
- name: 'Functional Parts',
- parent_id: null,
- file_count: 5,
- project_id: null,
- archive_id: null,
- project_name: null,
- archive_name: null,
- // #2680: distinctive year so the folder-pane display test can assert on it
- // without colliding with the file mtimes below.
- latest_activity_at: '2031-04-05T10:00:00Z',
- children: [
- {
- id: 2,
- name: 'Brackets',
- parent_id: 1,
- file_count: 3,
- project_id: null,
- archive_id: null,
- project_name: null,
- archive_name: null,
- latest_activity_at: '2032-06-07T10:00:00Z',
- children: [],
- },
- ],
- },
- {
- id: 3,
- name: 'Art Projects',
- parent_id: null,
- file_count: 2,
- project_id: 1,
- archive_id: null,
- project_name: 'My Art Project',
- archive_name: null,
- // No activity timestamp — must render no date line rather than an
- // "Invalid Date" placeholder.
- latest_activity_at: null,
- children: [],
- },
- ];
- const mockFiles = [
- {
- id: 1,
- filename: 'benchy.gcode.3mf',
- file_path: '/library/benchy.gcode.3mf',
- file_size: 1048576,
- file_type: '3mf',
- folder_id: null,
- thumbnail_path: '/thumbnails/1.png',
- print_name: 'Benchy',
- print_time_seconds: 3600,
- print_count: 5,
- duplicate_count: 0,
- created_at: '2024-01-01T00:00:00Z',
- // #2680: real on-disk mtime in a distinctive year so the display test can
- // prove fs_modified_at is preferred over created_at (2024).
- fs_modified_at: '2030-06-15T12:00:00Z',
- },
- {
- id: 2,
- filename: 'bracket.stl',
- file_path: '/library/bracket.stl',
- file_size: 524288,
- file_type: 'stl',
- folder_id: null,
- thumbnail_path: null,
- print_name: null,
- print_time_seconds: null,
- print_count: 0,
- duplicate_count: 2,
- created_at: '2024-01-02T00:00:00Z',
- },
- {
- id: 3,
- filename: 'cube.gcode.3mf',
- file_path: '/library/cube.gcode.3mf',
- file_size: 2048576,
- file_type: '3mf',
- folder_id: null,
- thumbnail_path: '/thumbnails/3.png',
- print_name: 'Cube',
- print_time_seconds: 1800,
- print_count: 2,
- duplicate_count: 0,
- created_at: '2024-01-03T00:00:00Z',
- },
- ];
- const mockStats = {
- total_files: 10,
- total_folders: 3,
- total_size_bytes: 104857600,
- disk_free_bytes: 10737418240,
- disk_total_bytes: 107374182400,
- };
- describe('FileManagerPage', () => {
- beforeEach(() => {
- // Clear localStorage to ensure consistent view mode
- localStorage.clear();
- server.use(
- http.get('/api/v1/library/folders', () => {
- return HttpResponse.json(mockFolders);
- }),
- http.get('/api/v1/library/files', () => {
- return HttpResponse.json(mockFiles);
- }),
- http.get('/api/v1/library/stats', () => {
- return HttpResponse.json(mockStats);
- }),
- http.get('/api/v1/settings/', () => {
- return HttpResponse.json({
- check_updates: false,
- check_printer_firmware: false,
- library_disk_warning_gb: 5,
- });
- }),
- http.post('/api/v1/library/folders', async ({ request }) => {
- const body = await request.json() as { name: string };
- return HttpResponse.json({ id: 4, name: body.name, parent_id: null, children: [] });
- }),
- http.delete('/api/v1/library/folders/:id', () => {
- return HttpResponse.json({ success: true });
- }),
- http.delete('/api/v1/library/files/:id', () => {
- return HttpResponse.json({ success: true });
- }),
- http.post('/api/v1/library/files/move', () => {
- return HttpResponse.json({ success: true });
- }),
- http.post('/api/v1/library/files/add-to-queue', () => {
- return HttpResponse.json({ added: [{ file_id: 1, queue_id: 1 }], errors: [] });
- }),
- http.get('/api/v1/projects/', () => {
- return HttpResponse.json([{ id: 1, name: 'Test Project', color: '#00ae42' }]);
- }),
- http.get('/api/v1/archives/', () => {
- return HttpResponse.json([{ id: 1, print_name: 'Test Archive', filename: 'test.3mf' }]);
- })
- );
- });
- describe('rendering', () => {
- it('renders the page title', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('File Manager')).toBeInTheDocument();
- });
- });
- it('renders the page description', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Organize and manage your print files')).toBeInTheDocument();
- });
- });
- it('shows New Folder button', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('New Folder')).toBeInTheDocument();
- });
- });
- it('shows Upload button', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Upload')).toBeInTheDocument();
- });
- });
- });
- describe('stats display', () => {
- it('shows file count', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Files:')).toBeInTheDocument();
- expect(screen.getByText('10')).toBeInTheDocument();
- });
- });
- it('shows folder count', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Folders:')).toBeInTheDocument();
- // Folder count appears multiple places, just verify the label is present
- const foldersLabel = screen.getByText('Folders:');
- expect(foldersLabel.nextElementSibling?.textContent).toBe('3');
- });
- });
- it('shows total size', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Size:')).toBeInTheDocument();
- expect(screen.getByText('100.0 MB')).toBeInTheDocument();
- });
- });
- it('shows free space', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Free:')).toBeInTheDocument();
- });
- });
- });
- describe('folder sidebar', () => {
- it('shows All Files option', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('All Files')).toBeInTheDocument();
- });
- });
- it('shows folder tree', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Functional Parts')).toBeInTheDocument();
- expect(screen.getByText('Art Projects')).toBeInTheDocument();
- });
- });
- it('shows nested folders', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Brackets')).toBeInTheDocument();
- });
- });
- it('shows linked folder indicator', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- // Art Projects has a project_id
- expect(screen.getByText('Art Projects')).toBeInTheDocument();
- });
- });
- });
- describe('file display', () => {
- it('shows files in grid', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Benchy')).toBeInTheDocument();
- });
- });
- it('shows file type badges', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- // File type badges show uppercase type
- expect(screen.getAllByText('3MF').length).toBeGreaterThan(0);
- expect(screen.getAllByText('STL').length).toBeGreaterThan(0);
- });
- });
- it('shows print count', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Printed 5x')).toBeInTheDocument();
- });
- });
- it('shows duplicate badge', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- // Duplicate badge shows count, there may be multiple "2"s on the page
- // so we check that at least one element with "2" exists
- const elements = screen.getAllByText('2');
- expect(elements.length).toBeGreaterThan(0);
- });
- });
- });
- describe('view modes', () => {
- it('has grid view button', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByTitle('Grid view')).toBeInTheDocument();
- });
- });
- it('has list view button', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByTitle('List view')).toBeInTheDocument();
- });
- });
- it('can switch to list view', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- // Wait for files to load first
- await waitFor(() => {
- expect(screen.getByText('Benchy')).toBeInTheDocument();
- });
- // Both view mode buttons should be present and clickable
- const gridButton = screen.getByTitle('Grid view');
- const listButton = screen.getByTitle('List view');
- expect(gridButton).toBeInTheDocument();
- expect(listButton).toBeInTheDocument();
- // Click list view button - verify no errors occur
- await user.click(listButton);
- // Clicking grid button should also work
- await user.click(gridButton);
- // Verify files are still displayed after toggling
- expect(screen.getByText('Benchy')).toBeInTheDocument();
- });
- });
- describe('search and filter', () => {
- it('has search input', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByPlaceholderText('Search files...')).toBeInTheDocument();
- });
- });
- it('has type filter', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('All types')).toBeInTheDocument();
- });
- });
- it('has sort options', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- // Sort dropdown should show Name as default option (persisted to localStorage)
- expect(screen.getByDisplayValue('Name')).toBeInTheDocument();
- });
- });
- });
- describe('selection', () => {
- it('shows select all button', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Select All')).toBeInTheDocument();
- });
- });
- it('can select files', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Benchy')).toBeInTheDocument();
- });
- // Click on the file card to select it
- const fileCard = screen.getByText('Benchy').closest('div[class*="cursor-pointer"]');
- if (fileCard) {
- await user.click(fileCard);
- }
- await waitFor(() => {
- expect(screen.getByText('1 selected')).toBeInTheDocument();
- });
- });
- it('shows bulk actions when files selected', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Select All')).toBeInTheDocument();
- });
- await user.click(screen.getByText('Select All'));
- await waitFor(() => {
- expect(screen.getByText('Move')).toBeInTheDocument();
- expect(screen.getByText('Delete')).toBeInTheDocument();
- });
- });
- });
- describe('new folder modal', () => {
- it('opens new folder modal', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('New Folder')).toBeInTheDocument();
- });
- await user.click(screen.getByText('New Folder'));
- await waitFor(() => {
- expect(screen.getByText('Folder Name')).toBeInTheDocument();
- expect(screen.getByPlaceholderText('e.g., Functional Parts')).toBeInTheDocument();
- });
- });
- it('can create a folder', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('New Folder')).toBeInTheDocument();
- });
- await user.click(screen.getByText('New Folder'));
- await waitFor(() => {
- expect(screen.getByPlaceholderText('e.g., Functional Parts')).toBeInTheDocument();
- });
- const input = screen.getByPlaceholderText('e.g., Functional Parts');
- await user.type(input, 'My New Folder');
- const createButton = screen.getByRole('button', { name: 'Create' });
- await user.click(createButton);
- // Modal should close after creation
- await waitFor(() => {
- expect(screen.queryByText('Folder Name')).not.toBeInTheDocument();
- });
- });
- });
- describe('empty state', () => {
- it('shows empty state when no files', async () => {
- server.use(
- http.get('/api/v1/library/files', () => {
- return HttpResponse.json([]);
- })
- );
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('No files yet')).toBeInTheDocument();
- expect(screen.getByText('Upload Files')).toBeInTheDocument();
- });
- });
- });
- describe('bulk-action print button', () => {
- // PR #1625 consolidated print actions: the old single-file-selected
- // "Schedule" button now opens the unified PrintModal (which carries
- // schedule options inside). The bulk-action toolbar shows a single
- // "Print" button only when exactly one sliced file is selected, and
- // hides it for multi-selection. The button is targeted by its accessible
- // name ("Print") + role to disambiguate from the file-card dropdown's
- // own Print entry, which stays collapsed unless its kebab is opened.
- it('shows a Print button in the bulk toolbar when one sliced file is selected', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Benchy')).toBeInTheDocument();
- });
- // Select a sliced file (benchy.gcode.3mf) by clicking on its card
- const fileCard = screen.getByText('Benchy').closest('div[class*="cursor-pointer"]');
- if (fileCard) {
- await user.click(fileCard);
- }
- await waitFor(() => {
- expect(screen.getByRole('button', { name: /^Print$/ })).toBeInTheDocument();
- });
- });
- it('hides the bulk Print button when multiple files are selected', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Select All')).toBeInTheDocument();
- });
- // Select all files
- await user.click(screen.getByText('Select All'));
- await waitFor(() => {
- expect(screen.queryByRole('button', { name: /^Print$/ })).not.toBeInTheDocument();
- });
- });
- });
- describe('STL thumbnail generation', () => {
- it('shows Generate Thumbnails button', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Generate Thumbnails')).toBeInTheDocument();
- });
- });
- it('Generate Thumbnails button has correct title', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- const button = screen.getByTitle('Generate thumbnails for STL and PDF files missing them');
- expect(button).toBeInTheDocument();
- });
- });
- it('can click Generate Thumbnails button', async () => {
- const user = userEvent.setup();
- server.use(
- http.post('/api/v1/library/generate-stl-thumbnails', () => {
- return HttpResponse.json({
- processed: 1,
- succeeded: 1,
- failed: 0,
- results: [{ file_id: 2, success: true }],
- });
- })
- );
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Generate Thumbnails')).toBeInTheDocument();
- });
- const button = screen.getByText('Generate Thumbnails');
- await user.click(button);
- // Button should work without error
- await waitFor(() => {
- expect(screen.getByText('Generate Thumbnails')).toBeInTheDocument();
- });
- });
- it('shows STL file without thumbnail in file list', async () => {
- render(<FileManagerPage />);
- await waitFor(() => {
- // bracket.stl has no thumbnail_path
- expect(screen.getByText('bracket.stl')).toBeInTheDocument();
- expect(screen.getAllByText('STL').length).toBeGreaterThan(0);
- });
- });
- // Since #2976 the server renders PDF thumbnails too, so the per-file
- // action is offered for PDFs and stays hidden for types it cannot render.
- describe('per-file action for PDFs', () => {
- const pdfFile = {
- id: 40,
- filename: 'drawing.pdf',
- file_path: '/library/drawing.pdf',
- file_size: 4096,
- file_type: 'pdf',
- folder_id: null,
- thumbnail_path: null,
- print_name: null,
- print_time_seconds: null,
- print_count: 0,
- duplicate_count: 0,
- created_at: '2024-01-04T00:00:00Z',
- };
- const stepFile = { ...pdfFile, id: 41, filename: 'part.step', file_path: '/library/part.step', file_type: 'step' };
- beforeEach(() => {
- server.use(
- http.get('/api/v1/library/files', () => HttpResponse.json([...mockFiles, pdfFile, stepFile])),
- );
- });
- const openMenu = async (user: ReturnType<typeof userEvent.setup>, filename: string) => {
- const card = screen.getByText(filename).closest('.group') as HTMLElement;
- const kebab = card.querySelector('.lucide-ellipsis-vertical')?.closest('button') as HTMLButtonElement;
- await user.click(kebab);
- return card;
- };
- it('offers Generate Thumbnail in the card menu of a PDF', async () => {
- const user = userEvent.setup();
- server.use(
- http.post('/api/v1/library/generate-stl-thumbnails', async ({ request }) => {
- const body = (await request.json()) as { file_ids?: number[] };
- return HttpResponse.json({
- processed: 1,
- succeeded: 1,
- failed: 0,
- results: [{ file_id: body.file_ids?.[0], success: true }],
- });
- })
- );
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('drawing.pdf')).toBeInTheDocument());
- const card = await openMenu(user, 'drawing.pdf');
- await user.click(within(card).getByText('Generate Thumbnail'));
- expect(await screen.findByText('Thumbnail generated')).toBeInTheDocument();
- });
- it('does not offer it for STEP, which only the browser can render', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('part.step')).toBeInTheDocument());
- const card = await openMenu(user, 'part.step');
- expect(within(card).queryByText('Generate Thumbnail')).not.toBeInTheDocument();
- });
- it('offers the action in the list view strip of a PDF', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('drawing.pdf')).toBeInTheDocument());
- await user.click(screen.getByRole('button', { name: /list/i }));
- // List rows are CSS grids; the row is the nearest grid ancestor.
- await waitFor(() => {
- const row = screen.getByText('drawing.pdf').closest('.grid') as HTMLElement;
- expect(within(row).getByTitle('Generate Thumbnail')).toBeInTheDocument();
- });
- const stepRow = screen.getByText('part.step').closest('.grid') as HTMLElement;
- expect(within(stepRow).queryByTitle('Generate Thumbnail')).not.toBeInTheDocument();
- });
- });
- });
- describe('upload modal (FileUploadModal)', () => {
- it('opens upload modal when Upload button is clicked', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Upload')).toBeInTheDocument();
- });
- await user.click(screen.getByText('Upload'));
- await waitFor(() => {
- expect(screen.getByText('Upload Files')).toBeInTheDocument();
- expect(screen.getByText(/Drag & drop/)).toBeInTheDocument();
- });
- });
- it('closes upload modal when Cancel is clicked', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Upload')).toBeInTheDocument();
- });
- await user.click(screen.getByText('Upload'));
- await waitFor(() => {
- expect(screen.getByText('Upload Files')).toBeInTheDocument();
- });
- await user.click(screen.getByRole('button', { name: 'Cancel' }));
- await waitFor(() => {
- expect(screen.queryByText('Upload Files')).not.toBeInTheDocument();
- });
- });
- it('shows 3MF extraction info when 3MF file is added', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Upload')).toBeInTheDocument();
- });
- await user.click(screen.getByText('Upload'));
- await waitFor(() => {
- expect(screen.getByText('Upload Files')).toBeInTheDocument();
- });
- const threemfFile = new File(['content'], 'model.gcode.3mf', { type: 'application/octet-stream' });
- const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
- expect(fileInput).toBeInTheDocument();
- await user.upload(fileInput, threemfFile);
- await waitFor(() => {
- expect(screen.getByText('3MF files detected')).toBeInTheDocument();
- expect(screen.getByText(/Printer model.*will be automatically extracted/i)).toBeInTheDocument();
- });
- });
- it('shows STL thumbnail option when STL file is added', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Upload')).toBeInTheDocument();
- });
- await user.click(screen.getByText('Upload'));
- await waitFor(() => {
- expect(screen.getByText('Upload Files')).toBeInTheDocument();
- });
- const stlFile = new File(['solid test'], 'model.stl', { type: 'application/sla' });
- const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
- expect(fileInput).toBeInTheDocument();
- await user.upload(fileInput, stlFile);
- await waitFor(() => {
- expect(screen.getByText('STL thumbnail generation')).toBeInTheDocument();
- expect(screen.getByText(/Thumbnails can be generated/i)).toBeInTheDocument();
- });
- });
- it('shows ZIP options when ZIP file is added', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Upload')).toBeInTheDocument();
- });
- await user.click(screen.getByText('Upload'));
- await waitFor(() => {
- expect(screen.getByText('Upload Files')).toBeInTheDocument();
- });
- const zipFile = new File(['pk'], 'models.zip', { type: 'application/zip' });
- const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
- await user.upload(fileInput, zipFile);
- await waitFor(() => {
- expect(screen.getByText('ZIP files detected')).toBeInTheDocument();
- expect(screen.getByText(/Preserve folder structure/)).toBeInTheDocument();
- });
- });
- it('can add a file via the file input', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Upload')).toBeInTheDocument();
- });
- await user.click(screen.getByText('Upload'));
- await waitFor(() => {
- expect(screen.getByText('Upload Files')).toBeInTheDocument();
- });
- const file = new File(['content'], 'model.3mf', { type: 'application/octet-stream' });
- const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
- await user.upload(fileInput, file);
- await waitFor(() => {
- expect(screen.getByText('model.3mf')).toBeInTheDocument();
- expect(screen.getByRole('button', { name: /Upload \(1\)/i })).toBeInTheDocument();
- });
- });
- it('uploads file and refreshes file list', async () => {
- server.use(
- http.post('/api/v1/library/files', () => {
- return HttpResponse.json({
- id: 10,
- filename: 'uploaded.3mf',
- file_type: '3mf',
- file_size: 1024,
- thumbnail_path: null,
- duplicate_of: null,
- metadata: null,
- });
- })
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Upload')).toBeInTheDocument();
- });
- await user.click(screen.getByText('Upload'));
- await waitFor(() => {
- expect(screen.getByText('Upload Files')).toBeInTheDocument();
- });
- const file = new File(['content'], 'uploaded.3mf', { type: 'application/octet-stream' });
- const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
- await user.upload(fileInput, file);
- const uploadButton = screen.getByRole('button', { name: /Upload \(1\)/i });
- await user.click(uploadButton);
- // Modal should auto-close after upload completes
- await waitFor(() => {
- expect(screen.queryByText('Upload Files')).not.toBeInTheDocument();
- });
- });
- });
- describe('authentication-based UI changes', () => {
- it('hides "Uploaded By" column and user filter when auth is disabled', async () => {
- // Mock auth disabled (default)
- server.use(
- http.get('*/api/v1/auth/status', () => {
- return HttpResponse.json({
- auth_enabled: false,
- requires_setup: false,
- });
- }),
- http.get('/api/v1/library/files', () => {
- return HttpResponse.json([
- {
- id: 1,
- filename: 'test.3mf',
- file_path: '/library/test.3mf',
- file_size: 1048576,
- file_type: '3mf',
- folder_id: null,
- thumbnail_path: null,
- print_name: 'Test File',
- print_time_seconds: 3600,
- print_count: 0,
- duplicate_count: 0,
- created_at: '2024-01-01T00:00:00Z',
- created_by_username: 'testuser',
- },
- ]);
- })
- );
- render(<FileManagerPage />);
- // Switch to list view to see the column headers
- await waitFor(() => {
- expect(screen.getByText('Test File')).toBeInTheDocument();
- });
- const user = userEvent.setup();
- const listViewButton = screen.getByRole('button', { name: /list/i });
- await user.click(listViewButton);
- // "Uploaded By" column header should not be present
- await waitFor(() => {
- expect(screen.queryByText('Uploaded By')).not.toBeInTheDocument();
- });
- // User filter dropdown should not be present
- expect(screen.queryByPlaceholderText('Filter by user')).not.toBeInTheDocument();
- });
- it('shows "Uploaded By" column and user filter when auth is enabled', async () => {
- // Mock auth enabled
- server.use(
- http.get('*/api/v1/auth/status', () => {
- return HttpResponse.json({
- auth_enabled: true,
- requires_setup: false,
- });
- }),
- http.get('/api/v1/library/files', () => {
- return HttpResponse.json([
- {
- id: 1,
- filename: 'test.3mf',
- file_path: '/library/test.3mf',
- file_size: 1048576,
- file_type: '3mf',
- folder_id: null,
- thumbnail_path: null,
- print_name: 'Test File',
- print_time_seconds: 3600,
- print_count: 0,
- duplicate_count: 0,
- created_at: '2024-01-01T00:00:00Z',
- created_by_username: 'testuser',
- },
- ]);
- }),
- http.get('/api/v1/users/', () => {
- return HttpResponse.json([
- { id: 1, username: 'testuser' },
- { id: 2, username: 'admin' },
- ]);
- })
- );
- render(<FileManagerPage />);
- // Switch to list view to see the column headers
- await waitFor(() => {
- expect(screen.getByText('Test File')).toBeInTheDocument();
- });
- const user = userEvent.setup();
- const listViewButton = screen.getByRole('button', { name: /list/i });
- await user.click(listViewButton);
- // "Uploaded By" column header should be present
- await waitFor(() => {
- expect(screen.getByText('Uploaded By')).toBeInTheDocument();
- });
- // User filter dropdown should be present
- expect(screen.getByPlaceholderText('Filter by user')).toBeInTheDocument();
- // Username should be displayed in the column
- expect(screen.getByText('testuser')).toBeInTheDocument();
- });
- });
- describe('folder tree collapse preference (#996)', () => {
- // localStorage is globally mocked in setup.ts (returns undefined by default),
- // so we program each test's getItem return value explicitly.
- const getItemMock = localStorage.getItem as ReturnType<typeof vi.fn>;
- const setItemMock = localStorage.setItem as ReturnType<typeof vi.fn>;
- beforeEach(() => {
- getItemMock.mockReset();
- setItemMock.mockReset();
- });
- // The mock is module-global, so an implementation left behind here would
- // silently change every later describe (e.g. collapsing the folder tree).
- afterEach(() => {
- getItemMock.mockReset();
- setItemMock.mockReset();
- });
- it('defaults to expanded (nested folders visible) when library-collapse-folders is unset', async () => {
- getItemMock.mockReturnValue(null);
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Functional Parts')).toBeInTheDocument();
- });
- expect(screen.getByText('Brackets')).toBeInTheDocument();
- });
- it('honors library-collapse-folders=true on load (nested folders hidden)', async () => {
- getItemMock.mockImplementation((key: string) =>
- key === 'library-collapse-folders' ? 'true' : null
- );
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Functional Parts')).toBeInTheDocument();
- });
- expect(screen.queryByText('Brackets')).not.toBeInTheDocument();
- });
- it('collapses nested folders and persists preference when Collapse is clicked', async () => {
- getItemMock.mockReturnValue(null);
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Brackets')).toBeInTheDocument();
- });
- // The Collapse button sits next to Wrap in the sidebar header.
- // Its text content is "Collapse" (from fileManager.collapse).
- await user.click(screen.getByRole('button', { name: 'Collapse' }));
- await waitFor(() => {
- expect(screen.queryByText('Brackets')).not.toBeInTheDocument();
- });
- expect(setItemMock).toHaveBeenCalledWith('library-collapse-folders', 'true');
- });
- it('re-expands nested folders and persists preference when Collapse is toggled off', async () => {
- getItemMock.mockImplementation((key: string) =>
- key === 'library-collapse-folders' ? 'true' : null
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Functional Parts')).toBeInTheDocument();
- });
- expect(screen.queryByText('Brackets')).not.toBeInTheDocument();
- await user.click(screen.getByRole('button', { name: 'Collapse' }));
- await waitFor(() => {
- expect(screen.getByText('Brackets')).toBeInTheDocument();
- });
- expect(setItemMock).toHaveBeenCalledWith('library-collapse-folders', 'false');
- });
- });
- describe('Internal / External top-level views (#1621)', () => {
- const externalMockFolders = [
- ...mockFolders,
- {
- id: 99,
- name: 'NAS Library',
- parent_id: null,
- file_count: 200,
- project_id: null,
- archive_id: null,
- project_name: null,
- archive_name: null,
- is_external: true,
- external_readonly: false,
- external_path: '/mnt/nas',
- children: [],
- },
- ];
- it('shows the External sidebar entry only when at least one external folder is linked', async () => {
- // Default mockFolders have no is_external entries → no External row.
- const { unmount } = render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('All Files')).toBeInTheDocument();
- });
- expect(screen.queryByText('External')).not.toBeInTheDocument();
- unmount();
- // With an external folder linked, the row appears.
- server.use(
- http.get('/api/v1/library/folders', () => HttpResponse.json(externalMockFolders)),
- );
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('External')).toBeInTheDocument();
- });
- });
- it('sends internal_only=true by default ("All Files" = managed storage only)', async () => {
- const scopes: string[] = [];
- server.use(
- http.get('/api/v1/library/folders', () => HttpResponse.json(externalMockFolders)),
- http.get('/api/v1/library/files', ({ request }) => {
- const url = new URL(request.url);
- scopes.push(
- url.searchParams.get('internal_only') === 'true'
- ? 'internal'
- : url.searchParams.get('external_only') === 'true'
- ? 'external'
- : 'all',
- );
- return HttpResponse.json(mockFiles);
- }),
- );
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(scopes).toContain('internal');
- });
- });
- it('switches to external_only=true when the External sidebar entry is clicked', async () => {
- const scopes: string[] = [];
- server.use(
- http.get('/api/v1/library/folders', () => HttpResponse.json(externalMockFolders)),
- http.get('/api/v1/library/files', ({ request }) => {
- const url = new URL(request.url);
- scopes.push(
- url.searchParams.get('internal_only') === 'true'
- ? 'internal'
- : url.searchParams.get('external_only') === 'true'
- ? 'external'
- : 'all',
- );
- return HttpResponse.json([]);
- }),
- );
- const { default: userEvent } = await import('@testing-library/user-event');
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('External')).toBeInTheDocument());
- await user.click(screen.getByText('External'));
- await waitFor(() => {
- expect(scopes).toContain('external');
- });
- });
- });
- describe('"All Files" view (#1499)', () => {
- it('requests every file (include_root=false) so subfolder contents are visible', async () => {
- const rootFile = {
- id: 10,
- filename: 'root-file.3mf',
- file_path: '/library/root-file.3mf',
- file_size: 1024,
- file_type: '3mf',
- folder_id: null,
- thumbnail_path: null,
- print_name: 'Root File',
- print_time_seconds: 0,
- print_count: 0,
- duplicate_count: 0,
- created_at: '2024-01-01T00:00:00Z',
- };
- const nestedFile = {
- ...rootFile,
- id: 11,
- filename: 'nested-file.3mf',
- file_path: '/library/Functional Parts/nested-file.3mf',
- folder_id: 1,
- print_name: 'Nested File',
- };
- const includeRootValues: string[] = [];
- server.use(
- http.get('/api/v1/library/files', ({ request }) => {
- const url = new URL(request.url);
- const includeRoot = url.searchParams.get('include_root');
- includeRootValues.push(includeRoot ?? '');
- // Mirror the backend: include_root=false returns everything; true
- // returns only files with folder_id IS NULL.
- if (includeRoot === 'false') {
- return HttpResponse.json([rootFile, nestedFile]);
- }
- return HttpResponse.json([rootFile]);
- }),
- );
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Root File')).toBeInTheDocument();
- expect(screen.getByText('Nested File')).toBeInTheDocument();
- });
- // Sanity-check: the buggy call would have sent include_root=true here.
- expect(includeRootValues).toContain('false');
- });
- });
- describe('last-modified date display (#2680)', () => {
- it('is hidden by default and revealed by the toolbar toggle', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Benchy')).toBeInTheDocument();
- });
- // Hidden by default.
- expect(screen.queryByText(/2030/)).not.toBeInTheDocument();
- // Toggle on via the toolbar button.
- await user.click(screen.getByTitle('Show modified dates'));
- // benchy carries fs_modified_at in 2030, which must be preferred over its
- // created_at (2024) — proving the real on-disk mtime drives the display.
- await waitFor(() => {
- expect(screen.getByText(/2030/)).toBeInTheDocument();
- });
- // Toggling off hides it again.
- await user.click(screen.getByTitle('Hide modified dates'));
- await waitFor(() => {
- expect(screen.queryByText(/2030/)).not.toBeInTheDocument();
- });
- });
- it('the same toggle reveals latest activity on folder rows, including nested ones', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => {
- expect(screen.getByText('Functional Parts')).toBeInTheDocument();
- });
- expect(screen.queryByText(/2031/)).not.toBeInTheDocument();
- await user.click(screen.getByTitle('Show modified dates'));
- await waitFor(() => {
- expect(screen.getByText(/2031/)).toBeInTheDocument();
- });
- // Nested folders get it too — the prop must survive the recursion.
- expect(screen.getByText(/2032/)).toBeInTheDocument();
- // A folder with no activity timestamp renders nothing rather than an
- // "Invalid Date" string.
- const artRow = screen.getByText('Art Projects').closest('div.group')!;
- expect(artRow.textContent).not.toMatch(/Invalid/);
- await user.click(screen.getByTitle('Hide modified dates'));
- await waitFor(() => {
- expect(screen.queryByText(/2031/)).not.toBeInTheDocument();
- });
- });
- });
- describe('slice action', () => {
- beforeEach(() => {
- vi.mocked(openInSlicer).mockClear();
- server.use(
- http.post('/api/v1/library/files/:id/slicer-token', () => HttpResponse.json({ token: 'test-token' })),
- // The only sliceable fixture is an STL, and since #3029 the desktop
- // handoff is only offered to a slicer whose protocol handler will
- // actually load one -- Bambu Studio's takes 3MF only. These tests are
- // about the handoff mechanics and the permission gate, not about which
- // slicer, so they run against OrcaSlicer. The Bambu Studio side is
- // covered by its own tests below.
- http.get('/api/v1/settings/', () => HttpResponse.json({ preferred_slicer: 'orcaslicer' })),
- );
- });
- afterEach(() => {
- // Permission tests set a token; clear it so it can't leak into the
- // list-view tests that follow (mirrors FileManagerFolderDelete.test.tsx).
- setAuthToken(null);
- });
- const openMenu = async (user: ReturnType<typeof userEvent.setup>, filename: string) => {
- const card = screen.getByText(filename).closest('.group') as HTMLElement;
- // Target the kebab (ellipsis) toggle specifically rather than the card's
- // first button — a button added ahead of the kebab would otherwise
- // break the menu-opening assumption.
- const kebab = card.querySelector('.lucide-ellipsis-vertical')?.closest('button') as HTMLButtonElement;
- await user.click(kebab);
- return card;
- };
- it('opens the desktop slicer when the slicer API is disabled', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- await user.click(within(card).getByText('Slice'));
- await waitFor(() => {
- expect(openInSlicer).toHaveBeenCalledWith(
- expect.stringContaining('/library/files/2/dl/test-token/'),
- 'orcaslicer',
- );
- });
- });
- it('opens the in-app SliceModal when the slicer API is enabled', async () => {
- server.use(
- http.get('/api/v1/settings/', () => HttpResponse.json({ use_slicer_api: true })),
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- await user.click(within(card).getByText('Slice'));
- expect(await screen.findByTestId('slice-modal')).toBeInTheDocument();
- expect(openInSlicer).not.toHaveBeenCalled();
- });
- // #2846: the menu used to be an absolutely-positioned child of the card,
- // and the card clipped its own overflow. A bare STL card is only about
- // 270px tall -- thumbnail plus name and size -- which is shorter than the
- // seven-entry menu, so the top entry was cut off. That entry is Slice,
- // because Print is suppressed for an unsliced file. A 3MF card carries two
- // more metadata rows and was tall enough, which is why the report said 3MF
- // worked. Nothing about STL was special; the card was just the shortest.
- it('keeps the first menu entry out of the card so it cannot be clipped (#2846)', async () => {
- server.use(
- http.get('/api/v1/settings/', () => HttpResponse.json({ use_slicer_api: true })),
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- const menu = within(card).getByText('Slice').closest('.fixed');
- // Viewport-positioned, so no ancestor's overflow can cut it down.
- expect(menu).not.toBeNull();
- expect(within(menu as HTMLElement).getAllByRole('button')[0]).toHaveTextContent('Slice');
- // And the card itself no longer clips what its children draw.
- expect(card.className).not.toContain('overflow-hidden');
- });
- // #3029: Bambu Studio's protocol handler refuses anything that is not a
- // 3MF before it even fetches the URL -- "Download failed, unknown file
- // format." Offering the handoff anyway put an action on an STL card that
- // could only fail, with an error that blamed the file.
- it('hides the desktop handoff for an STL when the target is Bambu Studio', async () => {
- server.use(
- http.get('/api/v1/settings/', () => HttpResponse.json({ preferred_slicer: 'bambu_studio' })),
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- expect(within(card).queryByText('Slice')).not.toBeInTheDocument();
- });
- it('honours the open_in_slicer override over the preferred slicer', async () => {
- // The desktop target is its own setting (#1329), so it -- not
- // preferred_slicer, which drives the sidecar -- decides whether an STL
- // can be handed over at all.
- server.use(
- http.get('/api/v1/settings/', () =>
- HttpResponse.json({ preferred_slicer: 'bambu_studio', open_in_slicer: 'orcaslicer' }),
- ),
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- await user.click(within(card).getByText('Slice'));
- await waitFor(() => {
- expect(openInSlicer).toHaveBeenCalledWith(expect.any(String), 'orcaslicer');
- });
- });
- it('still offers an STL to the in-app slicer with Bambu Studio as the desktop target', async () => {
- // The restriction is on the URL handoff, not on the file: the sidecar
- // slices an STL regardless of which desktop slicer is configured.
- server.use(
- http.get('/api/v1/settings/', () =>
- HttpResponse.json({ use_slicer_api: true, preferred_slicer: 'bambu_studio' }),
- ),
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- await user.click(within(card).getByText('Slice'));
- expect(await screen.findByTestId('slice-modal')).toBeInTheDocument();
- });
- it('hides the slice item for already-sliced files', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('Benchy')).toBeInTheDocument());
- const card = await openMenu(user, 'Benchy');
- expect(within(card).queryByText('Slice')).not.toBeInTheDocument();
- });
- // Permission gating is the security-relevant half of the slice action: the
- // in-app API path needs library:upload, and the desktop handoff mirrors the
- // ownership check the slicer-token endpoint runs — library:read_all or
- // library:read_own. The legacy library:read is deliberately not accepted;
- // it satisfies neither the token endpoint nor the folder listing that gets
- // a user to this page at all.
- const mockAuthUser = (permissions: string[]) => {
- setAuthToken('test-token', 'session');
- server.use(
- http.get('*/api/v1/auth/status', () =>
- HttpResponse.json({ auth_enabled: true, requires_setup: false }),
- ),
- http.get('*/api/v1/auth/me', () =>
- HttpResponse.json({
- id: 7,
- username: 'operator1',
- is_admin: false,
- permissions,
- }),
- ),
- http.get('/api/v1/users/', () => HttpResponse.json([])),
- );
- };
- it('disables the Slice menu item without library:upload when the slicer API is enabled', async () => {
- mockAuthUser([]);
- server.use(
- http.get('/api/v1/settings/', () => HttpResponse.json({ use_slicer_api: true })),
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- const sliceItem = within(card).getByText('Slice').closest('button');
- expect(sliceItem).toBeDisabled();
- await user.click(sliceItem!);
- expect(openInSlicer).not.toHaveBeenCalled();
- });
- it('enables the Slice menu item with library:upload when the slicer API is enabled', async () => {
- mockAuthUser(['library:upload']);
- server.use(
- http.get('/api/v1/settings/', () => HttpResponse.json({ use_slicer_api: true })),
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- const sliceItem = within(card).getByText('Slice').closest('button');
- expect(sliceItem).not.toBeDisabled();
- });
- it('disables the Slice menu item without any library read permission for the desktop handoff', async () => {
- mockAuthUser(['library:upload']);
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- const sliceItem = within(card).getByText('Slice').closest('button');
- expect(sliceItem).toBeDisabled();
- await user.click(sliceItem!);
- expect(openInSlicer).not.toHaveBeenCalled();
- });
- it('enables the Slice menu item with library:read_own for the desktop handoff', async () => {
- mockAuthUser(['library:read_own']);
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- const sliceItem = within(card).getByText('Slice').closest('button');
- expect(sliceItem).not.toBeDisabled();
- });
- it('does not accept the legacy library:read for the desktop handoff', async () => {
- // require_ownership_permission(LIBRARY_READ_ALL, LIBRARY_READ_OWN) does no
- // legacy expansion, so this group 403s on the slicer-token endpoint.
- // Enabling the item would offer an action the server refuses, and the
- // failure would look like "no slicer installed" once the fallback URL is
- // handed over.
- mockAuthUser(['library:read']);
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const card = await openMenu(user, 'bracket.stl');
- const sliceItem = within(card).getByText('Slice').closest('button');
- expect(sliceItem).toBeDisabled();
- await user.click(sliceItem!);
- expect(openInSlicer).not.toHaveBeenCalled();
- });
- it('slices from the list-view button when the slicer API is disabled', async () => {
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- await user.click(screen.getByTitle('List view'));
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const row = screen.getByText('bracket.stl').closest('div[class*="cursor-pointer"]') as HTMLElement;
- await user.click(within(row).getByTitle('Slice'));
- await waitFor(() => {
- expect(openInSlicer).toHaveBeenCalledWith(
- expect.stringContaining('/library/files/2/dl/test-token/'),
- 'orcaslicer',
- );
- });
- });
- it('slices from the list-view button into the in-app modal when the slicer API is enabled', async () => {
- server.use(
- http.get('/api/v1/settings/', () => HttpResponse.json({ use_slicer_api: true })),
- );
- const user = userEvent.setup();
- render(<FileManagerPage />);
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- await user.click(screen.getByTitle('List view'));
- await waitFor(() => expect(screen.getByText('bracket.stl')).toBeInTheDocument());
- const row = screen.getByText('bracket.stl').closest('div[class*="cursor-pointer"]') as HTMLElement;
- await user.click(within(row).getByTitle('Slice'));
- expect(await screen.findByTestId('slice-modal')).toBeInTheDocument();
- expect(openInSlicer).not.toHaveBeenCalled();
- });
- });
- });
|