ui: the Files filter's clear button rejoins its input (#650)
The clear button sat detached from the filter field and 11px below it, and it
dragged the collapse-all button out of line with both.
One stale rule did all of that. `.search-clear { margin: 0.625rem }` is left
over from the Semantic-era filter, where the clear button was a sibling of the
input and needed the gap. It is now ActionInput's action, which joins the two
by dropping the input's right border -- so the margin reopened the seam the
component exists to close, pushed the button down by its own top margin, and,
because a flex line is as tall as its tallest item plus that item's margins,
stretched the wrapper to 62px around a 40px field. The collapse-all button
beside it was centred in that 62px, which is why it looked wrong too.
Removing the rule fixes all three: the button abuts the field and shares its
outline, like the filters on Videos and Archives, and the row is one height.
The class had exactly one user left, so the rule goes with it.
The test asserts the button is inside ActionInput's wrapper, and that no rule
reintroduces a margin on it -- jsdom applies no stylesheet, so the geometry
itself cannot be measured there. Confirmed it fails when the rule is put back.
2026-08-08 17:16:00 -06:00
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
2025-12-25 09:14:00 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
import {act, fireEvent, screen, waitFor} from '@testing-library/react';
|
2026-07-03 11:17:11 -06:00
|
|
|
import {FileBrowser, filterBrowseFiles} from './FileBrowser';
|
2025-12-25 09:14:00 -07:00
|
|
|
import {renderWithProviders} from '../test-utils';
|
|
|
|
|
import {SettingsContext} from '../contexts/contexts';
|
|
|
|
|
import {FilePreviewContext} from './FilePreview';
|
|
|
|
|
|
|
|
|
|
// Mock the API functions
|
|
|
|
|
jest.mock('../api', () => ({
|
|
|
|
|
deleteFile: jest.fn(),
|
|
|
|
|
ignoreDirectory: jest.fn(),
|
|
|
|
|
makeDirectory: jest.fn(),
|
|
|
|
|
movePaths: jest.fn(),
|
|
|
|
|
renamePath: jest.fn(),
|
|
|
|
|
unignoreDirectory: jest.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Mock the custom hooks
|
|
|
|
|
const mockUseUploadFile = {
|
|
|
|
|
setFiles: jest.fn(),
|
|
|
|
|
progresses: {},
|
|
|
|
|
setDestination: jest.fn(),
|
|
|
|
|
doClear: jest.fn(),
|
|
|
|
|
tagsSelector: null,
|
|
|
|
|
overwrite: false,
|
|
|
|
|
setOverwrite: jest.fn(),
|
|
|
|
|
overallProgress: 0,
|
|
|
|
|
inProgress: false,
|
|
|
|
|
};
|
|
|
|
|
|
test: the theme drives the colour scheme, and mockModule takes the module
Both of Greptile's findings on #591 were real, and the first was a plain miss:
mockModule shipped with no caller, so its documented usage had never once been
executed and could not have worked. It called jest.requireActual on a path
passed in by the spec, which resolves relative to test-utils.js rather than to
the caller -- for any spec in a subdirectory the documented
'../hooks/customHooks' pointed outside src altogether. It now takes the module
the spec has already resolved, and throws on a string rather than quietly
resolving to the wrong one, which was the original failure.
It also has a caller now. FileBrowser.test.js listed six hooks in a hand-written
factory and returned only those, so every other export of customHooks was
undefined for anything it rendered -- the exact landmine the helper exists to
remove.
The second: `inverted` drove Mantine's colour scheme on its own, so asking for
night or amber through the new theme option produced a tree that reported a dark
theme while Mantine rendered its light one. Production cannot reach that
combination, and a harness that invents states the app never has is worse than
one that is merely incomplete -- what a test proves about such a tree is true of
nothing. The scheme is now derived from the theme name via isDarkTheme, and
data-theme is stamped on <html>, without which a component test cannot exercise
any token table or the night-mode treatment at all. isDark remains overridable
so a spec can still make the two disagree deliberately.
test-utils.test.js covers the harness itself, which had none. Eight of its
twelve assertions were red against the code above.
986 jest, 46 e2e, clean cache-busted build, tsc clean.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 16:39:30 -06:00
|
|
|
/*
|
|
|
|
|
* Every other export of customHooks used to be dropped here -- the factory listed six hooks and
|
|
|
|
|
* returned only those, so the rest of the module was undefined for anything this spec rendered.
|
|
|
|
|
* mockModule spreads the real module first, so the next hook a component reaches for still
|
|
|
|
|
* exists.
|
|
|
|
|
*/
|
|
|
|
|
jest.mock('../hooks/customHooks', () => require('../test-utils').mockModule(
|
|
|
|
|
jest.requireActual('../hooks/customHooks'),
|
|
|
|
|
{
|
|
|
|
|
useBrowseFiles: jest.fn(),
|
|
|
|
|
useMediaDirectory: jest.fn(() => '/media/wrolpi'),
|
|
|
|
|
useWROLMode: jest.fn(() => false),
|
|
|
|
|
useStatusFlag: jest.fn(() => false),
|
|
|
|
|
useUploadFile: () => mockUseUploadFile,
|
|
|
|
|
useElementWidth: jest.fn(() => [() => {}, 0]),
|
|
|
|
|
},
|
|
|
|
|
));
|
2025-12-25 09:14:00 -07:00
|
|
|
|
|
|
|
|
// Mock react-dropzone
|
|
|
|
|
jest.mock('react-dropzone', () => ({
|
|
|
|
|
useDropzone: () => ({
|
|
|
|
|
getRootProps: () => ({}),
|
|
|
|
|
getInputProps: () => ({}),
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Import mocked hooks for manipulation
|
2026-07-01 19:52:15 -06:00
|
|
|
import {useBrowseFiles, useElementWidth, useWROLMode} from '../hooks/customHooks';
|
2025-12-25 09:14:00 -07:00
|
|
|
|
|
|
|
|
// Create wrapper with all required contexts
|
|
|
|
|
const AllContextsWrapper = ({children}) => {
|
|
|
|
|
const settingsValue = {
|
|
|
|
|
settings: {ignored_directories: []},
|
|
|
|
|
fetchSettings: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
const filePreviewValue = {
|
|
|
|
|
setPreviewFile: jest.fn(),
|
|
|
|
|
setCallbacks: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SettingsContext.Provider value={settingsValue}>
|
|
|
|
|
<FilePreviewContext.Provider value={filePreviewValue}>
|
|
|
|
|
{children}
|
|
|
|
|
</FilePreviewContext.Provider>
|
|
|
|
|
</SettingsContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Custom render with all contexts
|
|
|
|
|
const renderFileBrowser = (ui, options = {}) => {
|
|
|
|
|
return renderWithProviders(
|
|
|
|
|
<AllContextsWrapper>{ui}</AllContextsWrapper>,
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
describe('FileBrowser', () => {
|
|
|
|
|
// Note: Files are sorted alphabetically by path, so file.txt comes before testdir/
|
|
|
|
|
const mockBrowseFiles = [
|
|
|
|
|
{path: 'file.txt', size: 1024},
|
|
|
|
|
{path: 'testdir/', children: null, is_empty: true},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
jest.clearAllMocks();
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: mockBrowseFiles,
|
|
|
|
|
openFolders: [],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
useWROLMode.mockReturnValue(false);
|
2026-07-01 19:52:15 -06:00
|
|
|
// [callbackRef, width]; width 0 keeps footer buttons icon-only in tests.
|
|
|
|
|
useElementWidth.mockReturnValue([() => {}, 0]);
|
2025-12-25 09:14:00 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Directory Selection', () => {
|
|
|
|
|
it('renders without crashing', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
// Should render the file browser table
|
|
|
|
|
expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('handles selecting and unselecting a directory without error', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Find the directory - text includes trailing slash
|
|
|
|
|
const directoryRow = screen.getByText('testdir/');
|
|
|
|
|
expect(directoryRow).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
// Find the checkbox in the same row - file.txt is first (index 0), testdir/ is second (index 1)
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
const directoryCheckbox = checkboxes[1]; // Second checkbox is for the directory
|
|
|
|
|
|
|
|
|
|
// Select the directory
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(directoryCheckbox);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Unselect the directory - this should NOT throw an error
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(directoryCheckbox);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// If we get here without error, the test passes
|
|
|
|
|
expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('upload button is enabled when nothing is selected', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Find the upload button (green button with upload icon)
|
|
|
|
|
const buttons = screen.getAllByRole('button');
|
|
|
|
|
const uploadButton = buttons.find(btn =>
|
|
|
|
|
btn.classList.contains('green') || btn.querySelector('[class*="upload"]')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Button should exist and not be disabled
|
|
|
|
|
expect(uploadButton).toBeInTheDocument();
|
|
|
|
|
expect(uploadButton).not.toBeDisabled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('upload button is enabled when single directory is selected', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Select the directory (second checkbox - testdir/)
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
const directoryCheckbox = checkboxes[1];
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(directoryCheckbox);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Find the upload button
|
|
|
|
|
const buttons = screen.getAllByRole('button');
|
ui: FileBrowser.js and FilePreview.js off Semantic
Migrated both files onto the token-driven ./ui component library: Table,
Modal, Button/IconButton, Checkbox, Header, Panel, Progress, Placeholder,
Skeleton, ActionInput/TextInput, IconStack, Menu/ButtonGroup for the slicer
split-button, and native <img>/<form> in place of Semantic's Image/Form.
Notable adaptations:
- Semantic's per-row `disabled` styling (no visual equivalent in the new
Table) is reproduced with inline opacity/pointer-events instead.
- DirectorySearch's autoFocus now passes straight through as a prop instead
of a nested `input={{autoFocus}}` object, matching SearchBox's API.
- The responsive icon+label footer buttons keep a single Button and toggle
children instead of swapping component type.
- FileBrowser.test.js: two upload-button assertions keyed off a literal
Semantic `.green` class; broadened to also match on the icon, mirroring
the sibling assertion already using that fallback.
Preserved as-is (reported, not fixed): getVideoPreviewModal's
`<Header as='h5'>{path['path']}</Header>` indexes a string with `['path']`,
which was already dead/undefined before this migration.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 13:11:01 -06:00
|
|
|
const uploadButton = buttons.find(btn =>
|
|
|
|
|
btn.classList.contains('green') || btn.querySelector('[class*="upload"]')
|
|
|
|
|
);
|
2025-12-25 09:14:00 -07:00
|
|
|
|
|
|
|
|
expect(uploadButton).not.toBeDisabled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('upload button is disabled when file is selected', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Select the file (first checkbox - file.txt)
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
const fileCheckbox = checkboxes[0];
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(fileCheckbox);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Find the upload button
|
|
|
|
|
const buttons = screen.getAllByRole('button');
|
ui: FileBrowser.js and FilePreview.js off Semantic
Migrated both files onto the token-driven ./ui component library: Table,
Modal, Button/IconButton, Checkbox, Header, Panel, Progress, Placeholder,
Skeleton, ActionInput/TextInput, IconStack, Menu/ButtonGroup for the slicer
split-button, and native <img>/<form> in place of Semantic's Image/Form.
Notable adaptations:
- Semantic's per-row `disabled` styling (no visual equivalent in the new
Table) is reproduced with inline opacity/pointer-events instead.
- DirectorySearch's autoFocus now passes straight through as a prop instead
of a nested `input={{autoFocus}}` object, matching SearchBox's API.
- The responsive icon+label footer buttons keep a single Button and toggle
children instead of swapping component type.
- FileBrowser.test.js: two upload-button assertions keyed off a literal
Semantic `.green` class; broadened to also match on the icon, mirroring
the sibling assertion already using that fallback.
Preserved as-is (reported, not fixed): getVideoPreviewModal's
`<Header as='h5'>{path['path']}</Header>` indexes a string with `['path']`,
which was already dead/undefined before this migration.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 13:11:01 -06:00
|
|
|
const uploadButton = buttons.find(btn =>
|
|
|
|
|
btn.classList.contains('green') || btn.querySelector('[class*="upload"]')
|
|
|
|
|
);
|
2025-12-25 09:14:00 -07:00
|
|
|
|
|
|
|
|
expect(uploadButton).toBeDisabled();
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-12-25 09:44:11 -07:00
|
|
|
|
2025-12-25 10:05:00 -07:00
|
|
|
describe('Auto-select directory contents', () => {
|
|
|
|
|
it('selects all children when opening a selected directory', async () => {
|
|
|
|
|
const mockSetOpenFolders = jest.fn();
|
|
|
|
|
const mockFetchFiles = jest.fn();
|
|
|
|
|
|
|
|
|
|
// Start with folder not open (no children loaded)
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'testdir/', children: null, is_empty: false},
|
|
|
|
|
],
|
|
|
|
|
openFolders: [],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: mockFetchFiles,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const {rerender} = renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Select the directory checkbox
|
|
|
|
|
const checkbox = screen.getByRole('checkbox');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkbox);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify directory is selected
|
|
|
|
|
expect(checkbox).toBeChecked();
|
|
|
|
|
|
|
|
|
|
// Click to expand the directory (clicking on the folder name cell)
|
|
|
|
|
const folderCell = screen.getByText('testdir/');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(folderCell);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify setOpenFolders was called to open the directory
|
|
|
|
|
expect(mockSetOpenFolders).toHaveBeenCalledWith(['testdir/']);
|
|
|
|
|
|
|
|
|
|
// Simulate browseFiles update with children (as would happen after fetch)
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'testdir/', children: [
|
|
|
|
|
{path: 'testdir/file1.txt', size: 100},
|
|
|
|
|
{path: 'testdir/file2.txt', size: 200},
|
|
|
|
|
], is_empty: false},
|
|
|
|
|
],
|
|
|
|
|
openFolders: ['testdir/'],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: mockFetchFiles,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Rerender to trigger the useEffect with new browseFiles
|
|
|
|
|
await act(async () => {
|
|
|
|
|
rerender(
|
|
|
|
|
<AllContextsWrapper>
|
|
|
|
|
<FileBrowser/>
|
|
|
|
|
</AllContextsWrapper>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify all checkboxes are checked (parent + 2 children)
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
expect(checkboxes.length).toBe(3);
|
|
|
|
|
checkboxes.forEach(cb => expect(cb).toBeChecked());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('children remain selected when parent is unselected', async () => {
|
|
|
|
|
// Setup: directory with children, parent and children are all selected
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'testdir/', children: [
|
|
|
|
|
{path: 'testdir/file1.txt', size: 100},
|
|
|
|
|
{path: 'testdir/file2.txt', size: 200},
|
|
|
|
|
], is_empty: false},
|
|
|
|
|
],
|
|
|
|
|
openFolders: ['testdir/'],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Select all items (parent + children)
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
expect(checkboxes.length).toBe(3);
|
|
|
|
|
|
|
|
|
|
// Select parent first
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]); // testdir/
|
|
|
|
|
});
|
|
|
|
|
// Select children
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[1]); // file1.txt
|
|
|
|
|
});
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[2]); // file2.txt
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify all are selected
|
|
|
|
|
checkboxes.forEach(cb => expect(cb).toBeChecked());
|
|
|
|
|
|
|
|
|
|
// Unselect the parent directory
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Parent should be unchecked, but children should remain checked
|
|
|
|
|
expect(checkboxes[0]).not.toBeChecked();
|
|
|
|
|
expect(checkboxes[1]).toBeChecked();
|
|
|
|
|
expect(checkboxes[2]).toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('unselects children when parent directory is closed', async () => {
|
|
|
|
|
// Setup: directory with children, already open
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'testdir/', children: [
|
|
|
|
|
{path: 'testdir/file1.txt', size: 100},
|
|
|
|
|
{path: 'testdir/file2.txt', size: 200},
|
|
|
|
|
], is_empty: false},
|
|
|
|
|
],
|
|
|
|
|
openFolders: ['testdir/'],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Select parent and children
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
expect(checkboxes.length).toBe(3);
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]); // testdir/
|
|
|
|
|
});
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[1]); // file1.txt
|
|
|
|
|
});
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[2]); // file2.txt
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify all are selected
|
|
|
|
|
checkboxes.forEach(cb => expect(cb).toBeChecked());
|
|
|
|
|
|
|
|
|
|
// Click to close the directory
|
|
|
|
|
const folderCell = screen.getByText('testdir/');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(folderCell);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Parent should still be selected, but children should be unselected
|
|
|
|
|
// (children are no longer visible after closing)
|
|
|
|
|
expect(checkboxes[0]).toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not auto-select children when opening unselected directory', async () => {
|
|
|
|
|
const mockSetOpenFolders = jest.fn();
|
|
|
|
|
const mockFetchFiles = jest.fn();
|
|
|
|
|
|
|
|
|
|
// Start with folder not open
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'testdir/', children: null, is_empty: false},
|
|
|
|
|
],
|
|
|
|
|
openFolders: [],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: mockFetchFiles,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const {rerender} = renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Click to expand WITHOUT selecting first
|
|
|
|
|
const folderCell = screen.getByText('testdir/');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(folderCell);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Simulate browseFiles update with children
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'testdir/', children: [
|
|
|
|
|
{path: 'testdir/file1.txt', size: 100},
|
|
|
|
|
{path: 'testdir/file2.txt', size: 200},
|
|
|
|
|
], is_empty: false},
|
|
|
|
|
],
|
|
|
|
|
openFolders: ['testdir/'],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: mockFetchFiles,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
rerender(
|
|
|
|
|
<AllContextsWrapper>
|
|
|
|
|
<FileBrowser/>
|
|
|
|
|
</AllContextsWrapper>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify NO checkboxes are checked
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
expect(checkboxes.length).toBe(3);
|
|
|
|
|
checkboxes.forEach(cb => expect(cb).not.toBeChecked());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-25 09:44:11 -07:00
|
|
|
describe('Delete functionality', () => {
|
|
|
|
|
it('removes deleted directory from openFolders', async () => {
|
|
|
|
|
const mockSetOpenFolders = jest.fn();
|
|
|
|
|
const mockFetchFiles = jest.fn();
|
|
|
|
|
const mockDeleteFile = require('../api').deleteFile;
|
|
|
|
|
mockDeleteFile.mockResolvedValue();
|
|
|
|
|
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'testdir/', children: [{path: 'testdir/file.txt', size: 100}], is_empty: false},
|
|
|
|
|
],
|
|
|
|
|
openFolders: ['testdir/'],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: mockFetchFiles,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Select the directory (first checkbox - testdir/)
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Click delete button (red trash button) - uses APIButton which has confirm modal
|
ui: Common.js and thirteen more files off Semantic
Phase 2, part 3. Baseline 63 -> 50.
Common.js is the one that mattered: 51 files import it, so its Semantic usage
was propping up the rest of the migration. Everything in it now comes from the
library -- Paginator, the two search inputs, DirectorySearch, TabLinks, the
toggles, the messages, APIButton, Breadcrumbs, SimpleAccordion, IframeViewer,
CardPoster, FileIcon, LoadStatistic, the theme menu, and the hotspot icons.
Also migrated: Placeholder, Apps, ArchivePreview, CbzViewer, AddToPlaylist,
TaggedDeleteConfirmModal, the collection edit/tag forms, and four inventory
components.
New in the library, all in the gallery and tested:
SearchBox Semantic's `<Search category>` with its grouped results shape
kept, because four call sites already build it. A real
combobox rather than a div that listens for clicks.
Pagination Semantic's prop names; onPageChange gets the page number.
TabBar the strip only -- routing stays with the caller.
IconStack Semantic's IconGroup, named once for assistive technology.
Table.HeaderCell sorted/onSort -- a real button carrying aria-sort.
Button/IconButton translate Semantic's size names.
That last one is defensive: unmigrated callers still pass size='tiny', and
Mantine drops a size it does not recognise without a word, so the button
quietly renders at the wrong size. Mapping here keeps the mixed state honest.
Three real bugs found and fixed on the way, none of them cosmetic:
* `fileSuffixIconName` returned fourteen icon names the map did not have, so
opening a folder with a PDF, a Word document or an archive in it logged an
error and drew a fallback glyph. All fourteen mapped, with a test that
walks the mapper's own return values, and another asserting every mapped
name resolves to a Tabler component that exists.
* `Statistic` relied on Semantic's `Statistic.Group` for its spacing, so on
the dashboard the load averages ran together into "1 MIN. LOAD5 MIN.
LOAD15 MIN. LOAD". It carries its own spacing now.
* Semantic's inverted stylesheet colors every descendant of an inverted
segment, so Toggle labels inherited #dddddd -- white pixels in night mode,
on the Settings page, which is exactly where someone adjusts their WROLPi
in the dark. Restated from tokens.
The baseline ratchet gained a third assertion: a migrated file may still lean
on Semantic's CSS classes without importing the library, which the import check
cannot see and which would collapse silently when Phase 4 deletes the
stylesheet. There is one such bridge today and it is now declared.
2026-07-30 10:00:48 -06:00
|
|
|
const deleteButton = document.querySelector('.tabler-icon-trash').closest('button');
|
2025-12-25 09:44:11 -07:00
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(deleteButton);
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-25 16:03:09 -07:00
|
|
|
// Confirm deletion in modal - getAllByText because Confirm renders both mobile/desktop versions
|
2025-12-25 09:44:11 -07:00
|
|
|
await waitFor(() => {
|
2025-12-25 16:03:09 -07:00
|
|
|
expect(screen.getAllByText('Delete').length).toBeGreaterThan(0);
|
2025-12-25 09:44:11 -07:00
|
|
|
});
|
2025-12-25 16:03:09 -07:00
|
|
|
const confirmButton = screen.getAllByText('Delete')[0];
|
2025-12-25 09:44:11 -07:00
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(confirmButton);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify setOpenFolders was called to remove the deleted directory
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(mockSetOpenFolders).toHaveBeenCalledWith(null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not modify openFolders when deleting files only', async () => {
|
|
|
|
|
const mockSetOpenFolders = jest.fn();
|
|
|
|
|
const mockFetchFiles = jest.fn();
|
|
|
|
|
const mockDeleteFile = require('../api').deleteFile;
|
|
|
|
|
mockDeleteFile.mockResolvedValue();
|
|
|
|
|
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'file.txt', size: 1024},
|
|
|
|
|
{path: 'testdir/', children: null, is_empty: true},
|
|
|
|
|
],
|
|
|
|
|
openFolders: ['testdir/'],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: mockFetchFiles,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Select the file (first checkbox - file.txt)
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Click delete button
|
ui: Common.js and thirteen more files off Semantic
Phase 2, part 3. Baseline 63 -> 50.
Common.js is the one that mattered: 51 files import it, so its Semantic usage
was propping up the rest of the migration. Everything in it now comes from the
library -- Paginator, the two search inputs, DirectorySearch, TabLinks, the
toggles, the messages, APIButton, Breadcrumbs, SimpleAccordion, IframeViewer,
CardPoster, FileIcon, LoadStatistic, the theme menu, and the hotspot icons.
Also migrated: Placeholder, Apps, ArchivePreview, CbzViewer, AddToPlaylist,
TaggedDeleteConfirmModal, the collection edit/tag forms, and four inventory
components.
New in the library, all in the gallery and tested:
SearchBox Semantic's `<Search category>` with its grouped results shape
kept, because four call sites already build it. A real
combobox rather than a div that listens for clicks.
Pagination Semantic's prop names; onPageChange gets the page number.
TabBar the strip only -- routing stays with the caller.
IconStack Semantic's IconGroup, named once for assistive technology.
Table.HeaderCell sorted/onSort -- a real button carrying aria-sort.
Button/IconButton translate Semantic's size names.
That last one is defensive: unmigrated callers still pass size='tiny', and
Mantine drops a size it does not recognise without a word, so the button
quietly renders at the wrong size. Mapping here keeps the mixed state honest.
Three real bugs found and fixed on the way, none of them cosmetic:
* `fileSuffixIconName` returned fourteen icon names the map did not have, so
opening a folder with a PDF, a Word document or an archive in it logged an
error and drew a fallback glyph. All fourteen mapped, with a test that
walks the mapper's own return values, and another asserting every mapped
name resolves to a Tabler component that exists.
* `Statistic` relied on Semantic's `Statistic.Group` for its spacing, so on
the dashboard the load averages ran together into "1 MIN. LOAD5 MIN.
LOAD15 MIN. LOAD". It carries its own spacing now.
* Semantic's inverted stylesheet colors every descendant of an inverted
segment, so Toggle labels inherited #dddddd -- white pixels in night mode,
on the Settings page, which is exactly where someone adjusts their WROLPi
in the dark. Restated from tokens.
The baseline ratchet gained a third assertion: a migrated file may still lean
on Semantic's CSS classes without importing the library, which the import check
cannot see and which would collapse silently when Phase 4 deletes the
stylesheet. There is one such bridge today and it is now declared.
2026-07-30 10:00:48 -06:00
|
|
|
const deleteButton = document.querySelector('.tabler-icon-trash').closest('button');
|
2025-12-25 09:44:11 -07:00
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(deleteButton);
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-25 16:03:09 -07:00
|
|
|
// Confirm deletion in modal - getAllByText because Confirm renders both mobile/desktop versions
|
2025-12-25 09:44:11 -07:00
|
|
|
await waitFor(() => {
|
2025-12-25 16:03:09 -07:00
|
|
|
expect(screen.getAllByText('Delete').length).toBeGreaterThan(0);
|
2025-12-25 09:44:11 -07:00
|
|
|
});
|
2025-12-25 16:03:09 -07:00
|
|
|
const confirmButton = screen.getAllByText('Delete')[0];
|
2025-12-25 09:44:11 -07:00
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(confirmButton);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Wait for delete to complete
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(mockDeleteFile).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// setOpenFolders should NOT have been called since we only deleted a file
|
|
|
|
|
expect(mockSetOpenFolders).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-12-26 11:28:10 -07:00
|
|
|
|
2026-07-03 11:17:11 -06:00
|
|
|
describe('Filter', () => {
|
ui: the Files filter's clear button rejoins its input (#650)
The clear button sat detached from the filter field and 11px below it, and it
dragged the collapse-all button out of line with both.
One stale rule did all of that. `.search-clear { margin: 0.625rem }` is left
over from the Semantic-era filter, where the clear button was a sibling of the
input and needed the gap. It is now ActionInput's action, which joins the two
by dropping the input's right border -- so the margin reopened the seam the
component exists to close, pushed the button down by its own top margin, and,
because a flex line is as tall as its tallest item plus that item's margins,
stretched the wrapper to 62px around a 40px field. The collapse-all button
beside it was centred in that 62px, which is why it looked wrong too.
Removing the rule fixes all three: the button abuts the field and shares its
outline, like the filters on Videos and Archives, and the row is one height.
The class had exactly one user left, so the rule goes with it.
The test asserts the button is inside ActionInput's wrapper, and that no rule
reintroduces a margin on it -- jsdom applies no stylesheet, so the geometry
itself cannot be measured there. Confirmed it fails when the rule is put back.
2026-08-08 17:16:00 -06:00
|
|
|
it('joins the clear button to the input, and keeps the row aligned', () => {
|
|
|
|
|
/*
|
|
|
|
|
* The clear button belongs INSIDE ActionInput's wrapper, which is what removes
|
|
|
|
|
* the input's right border so the pair reads as one control -- the same joined
|
|
|
|
|
* look the Videos and Archives filters have.
|
|
|
|
|
*
|
|
|
|
|
* It used to carry `search-clear`, a class left over from Semantic whose
|
|
|
|
|
* `margin: 0.625rem` did three things at once: opened a gap so the button read
|
|
|
|
|
* as detached, pushed it 11px below the input, and stretched the wrapper to
|
|
|
|
|
* 62px against a 40px field, which threw the collapse-all button out of line
|
|
|
|
|
* too. jsdom applies no stylesheet, so the guard is that no rule reintroduces
|
|
|
|
|
* a margin on a control inside the wrapper.
|
|
|
|
|
*/
|
|
|
|
|
renderFileBrowser(<FileBrowser browseFiles={mockBrowseFiles}/>);
|
|
|
|
|
|
|
|
|
|
const clear = screen.getByRole('button', {name: 'Clear filter'});
|
|
|
|
|
expect(clear.closest('.wrolpi-action-input')).not.toBeNull();
|
|
|
|
|
|
|
|
|
|
const css = fs.readFileSync(path.join(__dirname, '..', 'App.css'), 'utf8');
|
|
|
|
|
expect(css).not.toMatch(/\.search-clear\s*{/);
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-03 11:17:11 -06:00
|
|
|
// foo/ and bar/ are open, their children are loaded.
|
|
|
|
|
const nestedBrowseFiles = [
|
|
|
|
|
{
|
|
|
|
|
path: 'foo/', is_empty: false, children: [
|
|
|
|
|
{path: 'foo/foo1.txt', size: 100},
|
|
|
|
|
{path: 'foo/foo2.txt', size: 200},
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'bar/', is_empty: false, children: [
|
|
|
|
|
{path: 'bar/bar.1.txt', size: 300},
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
describe('filterBrowseFiles', () => {
|
|
|
|
|
it('returns files unchanged when filter is empty', () => {
|
|
|
|
|
expect(filterBrowseFiles(nestedBrowseFiles, '')).toBe(nestedBrowseFiles);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('keeps a matching folder and its entire subtree', () => {
|
|
|
|
|
const result = filterBrowseFiles(nestedBrowseFiles, 'bar');
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].path).toBe('bar/');
|
|
|
|
|
expect(result[0].children).toHaveLength(1);
|
|
|
|
|
expect(result[0].children[0].path).toBe('bar/bar.1.txt');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('keeps the parent folders of a matching file', () => {
|
|
|
|
|
const result = filterBrowseFiles(nestedBrowseFiles, 'foo1');
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].path).toBe('foo/');
|
|
|
|
|
expect(result[0].children).toHaveLength(1);
|
|
|
|
|
expect(result[0].children[0].path).toBe('foo/foo1.txt');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('matches case-insensitively', () => {
|
|
|
|
|
const result = filterBrowseFiles(nestedBrowseFiles, 'FOO1');
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].children[0].path).toBe('foo/foo1.txt');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('handles the dict format returned by the API', () => {
|
|
|
|
|
const dictFiles = {
|
|
|
|
|
'foo/': {
|
|
|
|
|
path: 'foo/', is_empty: false, children: {
|
|
|
|
|
'foo1.txt': {path: 'foo/foo1.txt', size: 100},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'bar.txt': {path: 'bar.txt', size: 300},
|
|
|
|
|
};
|
|
|
|
|
const result = filterBrowseFiles(dictFiles, 'bar');
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].path).toBe('bar.txt');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns no rows when nothing matches', () => {
|
|
|
|
|
expect(filterBrowseFiles(nestedBrowseFiles, 'does-not-exist')).toHaveLength(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('reduces the rows to matches and their tree', async () => {
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: nestedBrowseFiles,
|
|
|
|
|
openFolders: ['foo/', 'bar/'],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// All rows are visible before filtering.
|
|
|
|
|
expect(screen.getByText('foo1.txt')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('bar.1.txt')).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const filterInput = screen.getByPlaceholderText('Filter files...');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.change(filterInput, {target: {value: 'bar'}});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Only bar/ and its child remain.
|
|
|
|
|
expect(screen.getByText('bar/')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('bar.1.txt')).toBeInTheDocument();
|
|
|
|
|
expect(screen.queryByText('foo/')).not.toBeInTheDocument();
|
|
|
|
|
expect(screen.queryByText('foo1.txt')).not.toBeInTheDocument();
|
|
|
|
|
expect(screen.queryByText('foo2.txt')).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('restores all rows when the filter is cleared', async () => {
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: nestedBrowseFiles,
|
|
|
|
|
openFolders: ['foo/', 'bar/'],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
const filterInput = screen.getByPlaceholderText('Filter files...');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.change(filterInput, {target: {value: 'bar'}});
|
|
|
|
|
});
|
|
|
|
|
expect(screen.queryByText('foo1.txt')).not.toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.change(filterInput, {target: {value: ''}});
|
|
|
|
|
});
|
|
|
|
|
expect(screen.getByText('foo1.txt')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('bar.1.txt')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not filter the contents of an opened folder that matches the filter', async () => {
|
|
|
|
|
const mockSetOpenFolders = jest.fn();
|
|
|
|
|
|
|
|
|
|
// ebooks/ is closed, no children loaded yet.
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'ebooks/', children: null, is_empty: false},
|
|
|
|
|
{path: 'other.txt', size: 100},
|
|
|
|
|
],
|
|
|
|
|
openFolders: [],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const {rerender} = renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Filter for the folder's name.
|
|
|
|
|
const filterInput = screen.getByPlaceholderText('Filter files...');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.change(filterInput, {target: {value: 'ebooks'}});
|
|
|
|
|
});
|
|
|
|
|
expect(screen.queryByText('other.txt')).not.toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
// Open the matching folder.
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(screen.getByText('ebooks/'));
|
|
|
|
|
});
|
|
|
|
|
expect(mockSetOpenFolders).toHaveBeenCalledWith(['ebooks/']);
|
|
|
|
|
|
|
|
|
|
// Simulate the folder's children loading; their names do NOT match the filter.
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: [
|
|
|
|
|
{path: 'ebooks/', children: [
|
|
|
|
|
{path: 'ebooks/novel.epub', size: 100},
|
|
|
|
|
{path: 'ebooks/cover.jpg', size: 200},
|
|
|
|
|
], is_empty: false},
|
|
|
|
|
{path: 'other.txt', size: 100},
|
|
|
|
|
],
|
|
|
|
|
openFolders: ['ebooks/'],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
await act(async () => {
|
|
|
|
|
rerender(
|
|
|
|
|
<AllContextsWrapper>
|
|
|
|
|
<FileBrowser/>
|
|
|
|
|
</AllContextsWrapper>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The matching folder's contents are shown unfiltered.
|
|
|
|
|
expect(screen.getByText('ebooks/')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('novel.epub')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('cover.jpg')).toBeInTheDocument();
|
|
|
|
|
// Non-matching rows outside the folder stay hidden.
|
|
|
|
|
expect(screen.queryByText('other.txt')).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('focuses the filter input when f is pressed', async () => {
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: nestedBrowseFiles,
|
|
|
|
|
openFolders: ['foo/', 'bar/'],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
const filterInput = screen.getByPlaceholderText('Filter files...');
|
|
|
|
|
expect(filterInput).not.toHaveFocus();
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.keyDown(document.body, {key: 'f', code: 'KeyF'});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(filterInput).toHaveFocus();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('clear button clears the filter and shows all rows again', async () => {
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: nestedBrowseFiles,
|
|
|
|
|
openFolders: ['foo/', 'bar/'],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
const clearButton = screen.getByLabelText('Clear filter');
|
|
|
|
|
expect(clearButton).toBeDisabled();
|
|
|
|
|
|
|
|
|
|
const filterInput = screen.getByPlaceholderText('Filter files...');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.change(filterInput, {target: {value: 'bar'}});
|
|
|
|
|
});
|
|
|
|
|
expect(screen.queryByText('foo1.txt')).not.toBeInTheDocument();
|
|
|
|
|
expect(clearButton).not.toBeDisabled();
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(clearButton);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(filterInput).toHaveValue('');
|
|
|
|
|
expect(screen.getByText('foo1.txt')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('foo2.txt')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('bar.1.txt')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('collapse-all button is disabled when no folders are open', async () => {
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: nestedBrowseFiles,
|
|
|
|
|
openFolders: [],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByLabelText('Close all folders')).toBeDisabled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('collapse-all button closes all folders and deselects their hidden contents', async () => {
|
|
|
|
|
const mockSetOpenFolders = jest.fn();
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: nestedBrowseFiles,
|
|
|
|
|
openFolders: ['foo/', 'bar/'],
|
|
|
|
|
setOpenFolders: mockSetOpenFolders,
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// Select the foo/ folder and a file inside it.
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]); // foo/
|
|
|
|
|
});
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[1]); // foo/foo1.txt
|
|
|
|
|
});
|
|
|
|
|
expect(checkboxes[0]).toBeChecked();
|
|
|
|
|
expect(checkboxes[1]).toBeChecked();
|
|
|
|
|
|
|
|
|
|
const collapseButton = screen.getByLabelText('Close all folders');
|
|
|
|
|
expect(collapseButton).not.toBeDisabled();
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(collapseButton);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// All folders are closed (clears the ?folders= query param).
|
|
|
|
|
expect(mockSetOpenFolders).toHaveBeenCalledWith(null);
|
|
|
|
|
// The folder stays selected, but its now-hidden child does not.
|
|
|
|
|
expect(checkboxes[0]).toBeChecked();
|
|
|
|
|
expect(checkboxes[1]).not.toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows no results when nothing matches', async () => {
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: nestedBrowseFiles,
|
|
|
|
|
openFolders: ['foo/', 'bar/'],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
const filterInput = screen.getByPlaceholderText('Filter files...');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.change(filterInput, {target: {value: 'does-not-exist'}});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('No results')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-26 11:28:10 -07:00
|
|
|
describe('Drag Selection', () => {
|
|
|
|
|
const mockBrowseFilesMultiple = [
|
|
|
|
|
{path: 'file1.txt', size: 100},
|
|
|
|
|
{path: 'file2.txt', size: 200},
|
|
|
|
|
{path: 'file3.txt', size: 300},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
useBrowseFiles.mockReturnValue({
|
|
|
|
|
browseFiles: mockBrowseFilesMultiple,
|
|
|
|
|
openFolders: [],
|
|
|
|
|
setOpenFolders: jest.fn(),
|
|
|
|
|
fetchFiles: jest.fn(),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not enable drag selection on touch devices', async () => {
|
|
|
|
|
// Mock matchMedia to simulate touch device
|
|
|
|
|
window.matchMedia = jest.fn().mockImplementation(query => ({
|
|
|
|
|
matches: query === '(pointer: coarse)', // true for touch devices
|
|
|
|
|
media: query,
|
|
|
|
|
onchange: null,
|
|
|
|
|
addListener: jest.fn(),
|
|
|
|
|
removeListener: jest.fn(),
|
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
const rows = screen.getAllByRole('row');
|
|
|
|
|
// Skip header row (index 0)
|
|
|
|
|
const firstRow = rows[1];
|
|
|
|
|
|
|
|
|
|
// Simulate mousedown - on touch device, this should not start drag
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseDown(firstRow, {button: 0, clientX: 100, clientY: 100});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Move mouse and mouseup - items should NOT be selected via drag
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseMove(document, {clientX: 100, clientY: 200});
|
|
|
|
|
fireEvent.mouseUp(document);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify no items are selected (checkboxes unchecked)
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
checkboxes.forEach(cb => expect(cb).not.toBeChecked());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('selects rows when dragging across them', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
const rows = screen.getAllByRole('row');
|
|
|
|
|
// Skip header row
|
|
|
|
|
const firstDataRow = rows[1];
|
|
|
|
|
const secondDataRow = rows[2];
|
|
|
|
|
const thirdDataRow = rows[3];
|
|
|
|
|
|
|
|
|
|
// Start drag on first row
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseDown(firstDataRow, {button: 0, clientX: 100, clientY: 100});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Move mouse enough to trigger drag threshold (5px)
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseMove(document, {clientX: 100, clientY: 110});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Enter subsequent rows
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseEnter(secondDataRow);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseEnter(thirdDataRow);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// End drag
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseUp(document);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// All three files should be selected
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
expect(checkboxes.length).toBe(3);
|
|
|
|
|
checkboxes.forEach(cb => expect(cb).toBeChecked());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('adds to existing selection when dragging', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// First, select the first file via checkbox
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify first file is selected
|
|
|
|
|
expect(checkboxes[0]).toBeChecked();
|
|
|
|
|
expect(checkboxes[1]).not.toBeChecked();
|
|
|
|
|
expect(checkboxes[2]).not.toBeChecked();
|
|
|
|
|
|
|
|
|
|
const rows = screen.getAllByRole('row');
|
|
|
|
|
const secondDataRow = rows[2];
|
|
|
|
|
const thirdDataRow = rows[3];
|
|
|
|
|
|
|
|
|
|
// Start drag on second row
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseDown(secondDataRow, {button: 0, clientX: 100, clientY: 100});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Move enough to trigger drag
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseMove(document, {clientX: 100, clientY: 110});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseEnter(thirdDataRow);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseUp(document);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// All three should now be selected (first via checkbox, second and third via drag)
|
|
|
|
|
const updatedCheckboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
updatedCheckboxes.forEach(cb => expect(cb).toBeChecked());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not start drag when clicking on checkbox', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
|
|
|
|
|
// Click checkbox - should toggle selection, not start drag
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(checkboxes[0]).toBeChecked();
|
|
|
|
|
expect(checkboxes[1]).not.toBeChecked();
|
|
|
|
|
expect(checkboxes[2]).not.toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not start drag with right mouse button', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
const rows = screen.getAllByRole('row');
|
|
|
|
|
const firstDataRow = rows[1];
|
|
|
|
|
const secondDataRow = rows[2];
|
|
|
|
|
|
|
|
|
|
// Try to start drag with right button
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseDown(firstDataRow, {button: 2, clientX: 100, clientY: 100});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseMove(document, {clientX: 100, clientY: 110});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseEnter(secondDataRow);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseUp(document);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// No items should be selected
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
checkboxes.forEach(cb => expect(cb).not.toBeChecked());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('deselects rows when dragging from a selected item', async () => {
|
|
|
|
|
renderFileBrowser(<FileBrowser/>);
|
|
|
|
|
|
|
|
|
|
// First, select all three files via checkboxes
|
|
|
|
|
const checkboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[0]);
|
|
|
|
|
});
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[1]);
|
|
|
|
|
});
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.click(checkboxes[2]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Verify all are selected
|
|
|
|
|
expect(checkboxes[0]).toBeChecked();
|
|
|
|
|
expect(checkboxes[1]).toBeChecked();
|
|
|
|
|
expect(checkboxes[2]).toBeChecked();
|
|
|
|
|
|
|
|
|
|
const rows = screen.getAllByRole('row');
|
|
|
|
|
const firstDataRow = rows[1];
|
|
|
|
|
const secondDataRow = rows[2];
|
|
|
|
|
|
|
|
|
|
// Start drag from first row (which is selected) - should trigger deselect mode
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseDown(firstDataRow, {button: 0, clientX: 100, clientY: 100});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Move enough to trigger drag
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseMove(document, {clientX: 100, clientY: 110});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseEnter(secondDataRow);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
fireEvent.mouseUp(document);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// First two should now be deselected, third should remain selected
|
|
|
|
|
const updatedCheckboxes = screen.getAllByRole('checkbox');
|
|
|
|
|
expect(updatedCheckboxes[0]).not.toBeChecked();
|
|
|
|
|
expect(updatedCheckboxes[1]).not.toBeChecked();
|
|
|
|
|
expect(updatedCheckboxes[2]).toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-12-25 09:14:00 -07:00
|
|
|
});
|