feat(4.1-05-07): create frontend components for spare-parts search integration - useItemSearch hook, LoadingModal, ErrorModal with tests
This commit is contained in:
35
frontend/tests/SearchLoadingModal.test.tsx
Normal file
35
frontend/tests/SearchLoadingModal.test.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import { SearchLoadingModal } from '../components/SearchLoadingModal';
|
||||
|
||||
describe('SearchLoadingModal', () => {
|
||||
it('renders when open', () => {
|
||||
render(<SearchLoadingModal isOpen={true} maxSeconds={30} />);
|
||||
expect(screen.getByText(/Searching for specs/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render when closed', () => {
|
||||
const { container } = render(<SearchLoadingModal isOpen={false} />);
|
||||
expect(container.firstChild?.childNodes.length).toBe(0);
|
||||
});
|
||||
|
||||
it('displays countdown timer', () => {
|
||||
render(<SearchLoadingModal isOpen={true} maxSeconds={30} />);
|
||||
expect(screen.getByText(/30 seconds remaining/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onTimeout when timer expires', async () => {
|
||||
const onTimeout = vi.fn();
|
||||
render(<SearchLoadingModal isOpen={true} maxSeconds={1} onTimeout={onTimeout} />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onTimeout).toHaveBeenCalled();
|
||||
}, { timeout: 2000 });
|
||||
});
|
||||
|
||||
it('shows progress bar', () => {
|
||||
const { container } = render(<SearchLoadingModal isOpen={true} maxSeconds={30} />);
|
||||
const progressBar = container.querySelector('div[class*="bg-primary"]');
|
||||
expect(progressBar).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user