fix(unit): fix more broken tests

This commit is contained in:
perf3ct 2025-06-18 02:18:46 +00:00
parent c233b8f6fe
commit 1ec8235f63
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
4 changed files with 38 additions and 17 deletions

View File

@ -46,7 +46,7 @@ describe('AdvancedSearchPanel', () => {
vi.clearAllMocks();
});
test('renders collapsed state by default', () => {
test('renders collapsed state by default', async () => {
render(
<AdvancedSearchPanel
settings={mockSettings}
@ -59,7 +59,16 @@ describe('AdvancedSearchPanel', () => {
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');
});

View File

@ -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}`,

View File

@ -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(
<MimeTypeFacetFilter

View File

@ -79,8 +79,8 @@ const renderWithRouter = (component) => {
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,