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
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Mock react-semantic-toasts-2
|
|
|
|
|
jest.mock('react-semantic-toasts-2', () => ({
|
|
|
|
|
toast: jest.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
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({});
|
2026-05-03 17:28:06 -06:00
|
|
|
// The TaggedDeleteConfirmModal's Delete button has the trash icon.
|
|
|
|
|
const confirmButton = screen.getAllByRole('button')
|
|
|
|
|
.find(b => b.classList.contains('red') && b.textContent.includes('Delete')
|
|
|
|
|
&& b.querySelector('.trash.icon'));
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
});
|