diff --git a/frontend/src/components/AdvancedSearchPanel/__tests__/AdvancedSearchPanel.test.tsx b/frontend/src/components/AdvancedSearchPanel/__tests__/AdvancedSearchPanel.test.tsx index ea59ac7..98c3a22 100644 --- a/frontend/src/components/AdvancedSearchPanel/__tests__/AdvancedSearchPanel.test.tsx +++ b/frontend/src/components/AdvancedSearchPanel/__tests__/AdvancedSearchPanel.test.tsx @@ -46,7 +46,7 @@ describe('AdvancedSearchPanel', () => { vi.clearAllMocks(); }); - test('renders collapsed state by default', () => { + test('renders collapsed state by default', async () => { render( { expect(screen.getByText('Advanced Search Options')).toBeInTheDocument(); expect(screen.getByText('Customize search behavior and result display')).toBeInTheDocument(); expect(screen.getByText('SIMPLE')).toBeInTheDocument(); - expect(screen.queryByText('Search Behavior')).not.toBeInTheDocument(); + + // Wait for MUI Collapse animation to complete + await waitFor(() => { + // The section buttons should not be visible when collapsed + expect(screen.queryByRole('button', { name: 'Search Behavior' })).not.toBeInTheDocument(); + }); + + expect(screen.queryByRole('button', { name: 'Results Display' })).not.toBeInTheDocument(); + expect(screen.queryByRole('button', { name: 'Performance' })).not.toBeInTheDocument(); + expect(screen.queryByRole('button', { name: 'Content Sources' })).not.toBeInTheDocument(); }); test('expands when expanded prop is true', () => { @@ -139,9 +148,15 @@ describe('AdvancedSearchPanel', () => { /> ); - const searchModeSelect = screen.getByDisplayValue('simple'); + // Find the Select component by its label + const searchModeSelect = screen.getByRole('combobox'); await user.click(searchModeSelect); + // Wait for the options to appear and click on fuzzy + await waitFor(() => { + expect(screen.getByText('Fuzzy Search')).toBeInTheDocument(); + }); + const fuzzyOption = screen.getByText('Fuzzy Search'); await user.click(fuzzyOption); @@ -178,7 +193,11 @@ describe('AdvancedSearchPanel', () => { /> ); - const fuzzySlider = screen.getByRole('slider', { name: /fuzzy match threshold/i }); + // Check that fuzzy threshold text is displayed + expect(screen.getByText(/Fuzzy Match Threshold: 0.8/)).toBeInTheDocument(); + + // Find the slider by role - it should not be disabled in fuzzy mode + const fuzzySlider = screen.getByRole('slider'); expect(fuzzySlider).not.toHaveAttribute('disabled'); }); @@ -192,7 +211,8 @@ describe('AdvancedSearchPanel', () => { /> ); - const fuzzySlider = screen.getByRole('slider', { name: /fuzzy match threshold/i }); + // Find the slider by role - it should be disabled when not in fuzzy mode + const fuzzySlider = screen.getByRole('slider'); expect(fuzzySlider).toHaveAttribute('disabled'); }); diff --git a/frontend/src/components/GlobalSearchBar/__tests__/GlobalSearchBar.test.tsx b/frontend/src/components/GlobalSearchBar/__tests__/GlobalSearchBar.test.tsx index 6e0794f..31062b5 100644 --- a/frontend/src/components/GlobalSearchBar/__tests__/GlobalSearchBar.test.tsx +++ b/frontend/src/components/GlobalSearchBar/__tests__/GlobalSearchBar.test.tsx @@ -76,7 +76,7 @@ describe('GlobalSearchBar', () => { beforeEach(() => { vi.clearAllMocks(); localStorageMock.getItem.mockReturnValue(null); - documentService.enhancedSearch.mockResolvedValue(mockSearchResponse); + (documentService.enhancedSearch as any).mockResolvedValue(mockSearchResponse); }); test('renders search input with placeholder', () => { @@ -265,7 +265,7 @@ describe('GlobalSearchBar', () => { test('shows "View all results" link when there are many results', async () => { // Mock response with 5 or more results to trigger the link - documentService.enhancedSearch.mockResolvedValue({ + (documentService.enhancedSearch as any).mockResolvedValue({ data: { documents: Array.from({ length: 5 }, (_, i) => ({ id: `${i + 1}`, diff --git a/frontend/src/components/MimeTypeFacetFilter/__tests__/MimeTypeFacetFilter.test.tsx b/frontend/src/components/MimeTypeFacetFilter/__tests__/MimeTypeFacetFilter.test.tsx index 5d2c8ae..26c7826 100644 --- a/frontend/src/components/MimeTypeFacetFilter/__tests__/MimeTypeFacetFilter.test.tsx +++ b/frontend/src/components/MimeTypeFacetFilter/__tests__/MimeTypeFacetFilter.test.tsx @@ -2,13 +2,14 @@ import { describe, test, expect, vi, beforeEach } from 'vitest'; import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import MimeTypeFacetFilter from '../MimeTypeFacetFilter'; -import { documentService } from '../../../services/api'; // Mock the document service +const mockDocumentService = { + getFacets: vi.fn(), +}; + vi.mock('../../../services/api', () => ({ - documentService: { - getFacets: vi.fn(), - }, + documentService: mockDocumentService, })); const mockFacetsResponse = { @@ -30,7 +31,7 @@ describe('MimeTypeFacetFilter', () => { beforeEach(() => { vi.clearAllMocks(); - (documentService.getFacets as any).mockResolvedValue(mockFacetsResponse); + mockDocumentService.getFacets.mockResolvedValue(mockFacetsResponse); }); test('renders loading state initially', () => { @@ -261,7 +262,7 @@ describe('MimeTypeFacetFilter', () => { }, }; - (documentService.getFacets as any).mockResolvedValue(customResponse); + mockDocumentService.getFacets.mockResolvedValue(customResponse); render( { describe('SearchPage', () => { beforeEach(() => { vi.clearAllMocks(); - documentService.enhancedSearch.mockResolvedValue(mockSearchResponse); - documentService.search.mockResolvedValue(mockSearchResponse); + (documentService.enhancedSearch as any).mockResolvedValue(mockSearchResponse); + (documentService.search as any).mockResolvedValue(mockSearchResponse); }); test('renders search page with prominent search bar', () => { @@ -387,7 +387,7 @@ describe('SearchPage', () => { test('handles document download', async () => { const user = userEvent.setup(); const mockBlob = new Blob(['test content'], { type: 'application/pdf' }); - documentService.download.mockResolvedValue({ data: mockBlob }); + (documentService.download as any).mockResolvedValue({ data: mockBlob }); // Mock URL.createObjectURL global.URL.createObjectURL = vi.fn(() => 'mock-url'); @@ -516,7 +516,7 @@ describe('Enhanced Search Features', () => { const user = userEvent.setup(); // Mock empty response - documentService.enhancedSearch.mockResolvedValue({ + (documentService.enhancedSearch as any).mockResolvedValue({ data: { documents: [], total: 0,