80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
|
|
/**
|
||
|
|
* PhotoDetailModal Integration Test
|
||
|
|
* Feature: personal-user-enhancements
|
||
|
|
* Tests: Comments integration in photo detail view
|
||
|
|
*/
|
||
|
|
|
||
|
|
import React from 'react';
|
||
|
|
import { render, screen, waitFor } from '@testing-library/react';
|
||
|
|
import '@testing-library/jest-dom';
|
||
|
|
import PhotoDetailModal from '../PhotoDetailModal';
|
||
|
|
import { ImageItem } from '@/pages/gallery/typings';
|
||
|
|
|
||
|
|
// Mock dependencies
|
||
|
|
jest.mock('@/hooks/useComments', () => ({
|
||
|
|
__esModule: true,
|
||
|
|
default: () => ({
|
||
|
|
comments: [],
|
||
|
|
loading: false,
|
||
|
|
createLoading: false,
|
||
|
|
updateLoading: false,
|
||
|
|
deleteLoading: false,
|
||
|
|
addComment: jest.fn(),
|
||
|
|
updateComment: jest.fn(),
|
||
|
|
deleteComment: jest.fn(),
|
||
|
|
}),
|
||
|
|
}));
|
||
|
|
|
||
|
|
jest.mock('@/utils/userUtils', () => ({
|
||
|
|
getAuthization: () => 'mock-token',
|
||
|
|
}));
|
||
|
|
|
||
|
|
describe('PhotoDetailModal - Comments Integration', () => {
|
||
|
|
const mockPhoto: ImageItem = {
|
||
|
|
instanceId: 'photo-123',
|
||
|
|
imageName: 'test-photo.jpg',
|
||
|
|
size: 1024000,
|
||
|
|
createTime: '2024-01-15T10:30:00Z',
|
||
|
|
};
|
||
|
|
|
||
|
|
const defaultProps = {
|
||
|
|
visible: true,
|
||
|
|
photo: mockPhoto,
|
||
|
|
onClose: jest.fn(),
|
||
|
|
};
|
||
|
|
|
||
|
|
it('should render Comments component when modal is visible', async () => {
|
||
|
|
render(<PhotoDetailModal {...defaultProps} />);
|
||
|
|
|
||
|
|
await waitFor(() => {
|
||
|
|
// Check if Comments section is rendered
|
||
|
|
expect(screen.getByText('评论')).toBeInTheDocument();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should display photo information', async () => {
|
||
|
|
render(<PhotoDetailModal {...defaultProps} />);
|
||
|
|
|
||
|
|
await waitFor(() => {
|
||
|
|
expect(screen.getByText('test-photo.jpg')).toBeInTheDocument();
|
||
|
|
expect(screen.getByText('0.98 MB')).toBeInTheDocument();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should not render when photo is null', () => {
|
||
|
|
render(<PhotoDetailModal {...defaultProps} photo={null} />);
|
||
|
|
|
||
|
|
// Modal should not render
|
||
|
|
expect(screen.queryByText('评论')).not.toBeInTheDocument();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should pass correct entityType and entityId to Comments', async () => {
|
||
|
|
const { container } = render(<PhotoDetailModal {...defaultProps} />);
|
||
|
|
|
||
|
|
await waitFor(() => {
|
||
|
|
// Verify the modal is rendered
|
||
|
|
expect(container.querySelector('.ant-modal')).toBeInTheDocument();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|