2026-02-05 15:18:14 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
import {screen, waitFor, fireEvent} from '@testing-library/react';
|
|
|
|
|
import {renderWithProviders} from '../../test-utils';
|
|
|
|
|
import {ConflictResolutionModal} from './ConflictResolutionModal';
|
|
|
|
|
import * as api from '../../api';
|
|
|
|
|
|
|
|
|
|
// Mock the API functions
|
|
|
|
|
jest.mock('../../api', () => ({
|
2026-05-03 18:50:22 -06:00
|
|
|
deleteFileGroups: jest.fn(),
|
2026-02-05 15:18:14 -07:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('ConflictResolutionModal', () => {
|
|
|
|
|
const mockConflicts = [
|
|
|
|
|
{
|
|
|
|
|
destination_path: 'videos/2024-01-15/My Video.mp4',
|
|
|
|
|
conflicting_files: [
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 1,
|
|
|
|
|
current_path: 'videos/old/My Video.mp4',
|
|
|
|
|
title: 'My Video',
|
|
|
|
|
model_type: 'video',
|
|
|
|
|
size: 1024000,
|
|
|
|
|
archive_id: null,
|
|
|
|
|
poster_path: 'videos/old/My Video.jpg',
|
|
|
|
|
published_datetime: '2024-01-15T10:00:00Z',
|
|
|
|
|
source_id: 'abc123',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 2,
|
|
|
|
|
current_path: 'videos/new/My Video.mp4',
|
|
|
|
|
title: 'My Video',
|
|
|
|
|
model_type: 'video',
|
|
|
|
|
size: 2048000,
|
|
|
|
|
archive_id: null,
|
|
|
|
|
poster_path: null,
|
|
|
|
|
published_datetime: '2024-01-15T10:00:00Z',
|
|
|
|
|
source_id: 'abc123',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
|
open: true,
|
|
|
|
|
onClose: jest.fn(),
|
|
|
|
|
conflicts: mockConflicts,
|
|
|
|
|
collectionKind: 'channel',
|
|
|
|
|
onResolved: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
jest.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders the modal with conflicts', () => {
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/Resolve Conflicts Before Reorganizing/i)).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText(/Destination Path Conflicts Detected/i)).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText(/1 destination path has/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows conflict destination path', () => {
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/videos\/2024-01-15\/My Video.mp4/)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows file details for conflicting files', () => {
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
// Should show both file paths
|
|
|
|
|
expect(screen.getByText('videos/old/My Video.mp4')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('videos/new/My Video.mp4')).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
// Should show title
|
|
|
|
|
const titles = screen.getAllByText('My Video');
|
|
|
|
|
expect(titles.length).toBeGreaterThanOrEqual(2);
|
|
|
|
|
|
|
|
|
|
// Should show source_id
|
|
|
|
|
const sourceIds = screen.getAllByText('abc123');
|
|
|
|
|
expect(sourceIds.length).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows file size in human-readable format', () => {
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
// 1024000 bytes = ~1000 kB (uses humanFileSize from Common.js)
|
|
|
|
|
expect(screen.getByText('1000.0 kB')).toBeInTheDocument();
|
|
|
|
|
// 2048000 bytes = ~2 MB
|
|
|
|
|
expect(screen.getByText('2.0 MB')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-03 18:50:22 -06:00
|
|
|
it('calls deleteFileGroups when delete button is clicked for video', async () => {
|
|
|
|
|
api.deleteFileGroups.mockResolvedValue({});
|
2026-02-05 15:18:14 -07:00
|
|
|
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
// Find and click the first delete button
|
|
|
|
|
const deleteButtons = screen.getAllByTitle('Delete this file');
|
|
|
|
|
fireEvent.click(deleteButtons[0]);
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
2026-05-03 18:50:22 -06:00
|
|
|
expect(api.deleteFileGroups).toHaveBeenCalledWith([1], false);
|
2026-02-05 15:18:14 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// File should be removed from UI (conflict resolved since only 1 file remains)
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(screen.getByText(/All Conflicts Resolved/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// onResolved is NOT called until modal is closed
|
|
|
|
|
expect(defaultProps.onResolved).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
// Click Close/Done button - now onResolved should be called
|
|
|
|
|
fireEvent.click(screen.getByRole('button', {name: /Done/i}));
|
|
|
|
|
expect(defaultProps.onResolved).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-03 18:50:22 -06:00
|
|
|
it('calls deleteFileGroups when delete button is clicked for archive', async () => {
|
2026-02-05 15:18:14 -07:00
|
|
|
const archiveConflicts = [
|
|
|
|
|
{
|
|
|
|
|
destination_path: 'archives/example.com/page.html',
|
|
|
|
|
conflicting_files: [
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 10,
|
|
|
|
|
current_path: 'archives/old/page.html',
|
|
|
|
|
title: 'Example Page',
|
|
|
|
|
model_type: 'archive',
|
|
|
|
|
size: 50000,
|
|
|
|
|
archive_id: 201,
|
|
|
|
|
poster_path: null,
|
|
|
|
|
published_datetime: null,
|
|
|
|
|
source_id: null,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2026-05-03 18:50:22 -06:00
|
|
|
api.deleteFileGroups.mockResolvedValue({});
|
2026-02-05 15:18:14 -07:00
|
|
|
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal
|
|
|
|
|
{...defaultProps}
|
|
|
|
|
conflicts={archiveConflicts}
|
|
|
|
|
collectionKind='domain'
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const deleteButton = screen.getByTitle('Delete this file');
|
|
|
|
|
fireEvent.click(deleteButton);
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
2026-05-03 18:50:22 -06:00
|
|
|
// Unified endpoint always uses FileGroup IDs.
|
|
|
|
|
expect(api.deleteFileGroups).toHaveBeenCalledWith([10], false);
|
2026-02-05 15:18:14 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows success message when no conflicts remain', () => {
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal {...defaultProps} conflicts={[]} />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/All Conflicts Resolved/i)).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText(/You can now proceed with the reorganization/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows Done button when no conflicts', () => {
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal {...defaultProps} conflicts={[]} />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByRole('button', {name: /Done/i})).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows Close button when conflicts exist', () => {
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByRole('button', {name: /Close/i})).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onClose when Close button is clicked (without changes)', () => {
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByRole('button', {name: /Close/i}));
|
|
|
|
|
|
|
|
|
|
// onClose is called, but onResolved is NOT called since no changes were made
|
|
|
|
|
expect(defaultProps.onClose).toHaveBeenCalled();
|
|
|
|
|
expect(defaultProps.onResolved).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('displays multiple conflicts', () => {
|
|
|
|
|
const multipleConflicts = [
|
|
|
|
|
{
|
|
|
|
|
destination_path: 'videos/path1.mp4',
|
|
|
|
|
conflicting_files: [
|
2026-03-20 15:38:32 -06:00
|
|
|
{file_group_id: 1, current_path: 'a.mp4', title: 'Video 1', model_type: 'video'},
|
|
|
|
|
{file_group_id: 2, current_path: 'b.mp4', title: 'Video 1', model_type: 'video'},
|
2026-02-05 15:18:14 -07:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
destination_path: 'videos/path2.mp4',
|
|
|
|
|
conflicting_files: [
|
2026-03-20 15:38:32 -06:00
|
|
|
{file_group_id: 3, current_path: 'c.mp4', title: 'Video 2', model_type: 'video'},
|
|
|
|
|
{file_group_id: 4, current_path: 'd.mp4', title: 'Video 2', model_type: 'video'},
|
2026-02-05 15:18:14 -07:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal {...defaultProps} conflicts={multipleConflicts} />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/2 destination paths have/i)).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText(/videos\/path1.mp4/)).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText(/videos\/path2.mp4/)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows video type label for videos', () => {
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
const videoLabels = screen.getAllByText('video');
|
|
|
|
|
expect(videoLabels.length).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows archive type label for archives', () => {
|
|
|
|
|
const archiveConflicts = [
|
|
|
|
|
{
|
|
|
|
|
destination_path: 'archives/page.html',
|
|
|
|
|
conflicting_files: [
|
|
|
|
|
{file_group_id: 1, current_path: 'old.html', title: 'Page', model_type: 'archive', archive_id: 1},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal {...defaultProps} conflicts={archiveConflicts} collectionKind='domain' />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText('archive')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not render when closed', () => {
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal {...defaultProps} open={false} />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.queryByText(/Resolve Conflicts Before Reorganizing/i)).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('displays quality rank for videos', () => {
|
|
|
|
|
const conflictsWithRank = [
|
|
|
|
|
{
|
|
|
|
|
destination_path: 'videos/2024-01-15/My Video.mp4',
|
|
|
|
|
conflicting_files: [
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 1,
|
|
|
|
|
current_path: 'videos/old/My Video.mp4',
|
|
|
|
|
title: 'My Video',
|
|
|
|
|
model_type: 'video',
|
|
|
|
|
size: 1024000,
|
|
|
|
|
quality_rank: 12,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 2,
|
|
|
|
|
current_path: 'videos/new/My Video.mp4',
|
|
|
|
|
title: 'My Video',
|
|
|
|
|
model_type: 'video',
|
|
|
|
|
size: 2048000,
|
|
|
|
|
quality_rank: 5,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal {...defaultProps} conflicts={conflictsWithRank} />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Should show quality ranks
|
|
|
|
|
expect(screen.getByText('12')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('5')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows recommended badge on highest ranked video', () => {
|
|
|
|
|
const conflictsWithRank = [
|
|
|
|
|
{
|
|
|
|
|
destination_path: 'videos/2024-01-15/My Video.mp4',
|
|
|
|
|
conflicting_files: [
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 1,
|
|
|
|
|
current_path: 'videos/old/My Video.mp4',
|
|
|
|
|
title: 'My Video',
|
|
|
|
|
model_type: 'video',
|
|
|
|
|
quality_rank: 15,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 2,
|
|
|
|
|
current_path: 'videos/new/My Video.mp4',
|
|
|
|
|
title: 'My Video',
|
|
|
|
|
model_type: 'video',
|
|
|
|
|
quality_rank: 8,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal {...defaultProps} conflicts={conflictsWithRank} />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Should show "Recommended to Keep" badge (only on the first/highest ranked)
|
|
|
|
|
expect(screen.getByText(/Recommended to Keep/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-03 17:28:06 -06:00
|
|
|
it('shows tagged-delete confirmation modal when API returns FILE_GROUP_IS_TAGGED', async () => {
|
2026-05-03 18:50:22 -06:00
|
|
|
api.deleteFileGroups.mockResolvedValue({
|
2026-05-03 17:28:06 -06:00
|
|
|
tagged: true,
|
|
|
|
|
file_groups: [
|
|
|
|
|
{id: 1, primary_path: 'unique-tagged-path-12345.mp4', tags: ['unique-tag-zxcv']},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
|
|
|
|
|
|
|
|
|
const deleteButtons = screen.getAllByTitle('Delete this file');
|
|
|
|
|
fireEvent.click(deleteButtons[0]);
|
|
|
|
|
|
|
|
|
|
// Wait for the secondary confirmation modal to appear (use unique path/tag to avoid
|
|
|
|
|
// matching the parent ConflictResolutionModal's "Tagged" label).
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(screen.getByText('unique-tagged-path-12345.mp4')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
expect(screen.getByText('unique-tag-zxcv')).toBeInTheDocument();
|
|
|
|
|
|
2026-05-03 18:50:22 -06:00
|
|
|
// Confirming should re-call deleteFileGroups with force=true.
|
|
|
|
|
api.deleteFileGroups.mockResolvedValueOnce({});
|
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
|
|
|
// The TaggedDeleteConfirmModal (a Confirm) names its destructive action "Delete",
|
|
|
|
|
// distinct from the "Delete this file" icon buttons queried above.
|
|
|
|
|
const confirmButton = screen.getByRole('button', {name: 'Delete'});
|
2026-05-03 17:28:06 -06:00
|
|
|
fireEvent.click(confirmButton);
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
2026-05-03 18:50:22 -06:00
|
|
|
expect(api.deleteFileGroups).toHaveBeenLastCalledWith([1], true);
|
2026-05-03 17:28:06 -06:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-05 15:18:14 -07:00
|
|
|
it('does not show rank display for archives', () => {
|
|
|
|
|
const archiveConflicts = [
|
|
|
|
|
{
|
|
|
|
|
destination_path: 'archives/page.html',
|
|
|
|
|
conflicting_files: [
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 1,
|
|
|
|
|
current_path: 'old.html',
|
|
|
|
|
title: 'Page',
|
|
|
|
|
model_type: 'archive',
|
|
|
|
|
archive_id: 1,
|
|
|
|
|
quality_rank: null,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
file_group_id: 2,
|
|
|
|
|
current_path: 'new.html',
|
|
|
|
|
title: 'Page',
|
|
|
|
|
model_type: 'archive',
|
|
|
|
|
archive_id: 2,
|
|
|
|
|
quality_rank: null,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<ConflictResolutionModal {...defaultProps} conflicts={archiveConflicts} collectionKind='domain' />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Should NOT show "Recommended to Keep" badge for archives
|
|
|
|
|
expect(screen.queryByText(/Recommended to Keep/i)).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|