import { fireEvent, render, screen } from '@testing-library/react' import { describe, expect, it, vi } from 'vitest' import ConfigurationsSection from './configurations-section' describe('ConfigurationsSection', () => { const defaultProps = { timeout: 30, onTimeoutChange: vi.fn(), sseReadTimeout: 300, onSseReadTimeoutChange: vi.fn(), } describe('Rendering', () => { it('should render without crashing', () => { render() expect(screen.getByDisplayValue('30')).toBeInTheDocument() expect(screen.getByDisplayValue('300')).toBeInTheDocument() }) it('should render timeout input with correct value', () => { render() const timeoutInput = screen.getByDisplayValue('30') expect(timeoutInput).toHaveAttribute('type', 'number') }) it('should render SSE read timeout input with correct value', () => { render() const sseInput = screen.getByDisplayValue('300') expect(sseInput).toHaveAttribute('type', 'number') }) it('should render labels for both inputs', () => { render() // i18n keys are rendered as-is in test environment expect(screen.getByText('tools.mcp.modal.timeout')).toBeInTheDocument() expect(screen.getByText('tools.mcp.modal.sseReadTimeout')).toBeInTheDocument() }) }) describe('Props', () => { it('should display custom timeout value', () => { render() expect(screen.getByDisplayValue('60')).toBeInTheDocument() }) it('should display custom SSE read timeout value', () => { render() expect(screen.getByDisplayValue('600')).toBeInTheDocument() }) }) describe('User Interactions', () => { it('should call onTimeoutChange when timeout input changes', () => { const onTimeoutChange = vi.fn() render() const timeoutInput = screen.getByDisplayValue('30') fireEvent.change(timeoutInput, { target: { value: '45' } }) expect(onTimeoutChange).toHaveBeenCalledWith(45) }) it('should call onSseReadTimeoutChange when SSE timeout input changes', () => { const onSseReadTimeoutChange = vi.fn() render() const sseInput = screen.getByDisplayValue('300') fireEvent.change(sseInput, { target: { value: '500' } }) expect(onSseReadTimeoutChange).toHaveBeenCalledWith(500) }) it('should handle numeric conversion correctly', () => { const onTimeoutChange = vi.fn() render() const timeoutInput = screen.getByDisplayValue('30') fireEvent.change(timeoutInput, { target: { value: '0' } }) expect(onTimeoutChange).toHaveBeenCalledWith(0) }) }) describe('Edge Cases', () => { it('should handle zero timeout value', () => { render() expect(screen.getByDisplayValue('0')).toBeInTheDocument() }) it('should handle zero SSE read timeout value', () => { render() expect(screen.getByDisplayValue('0')).toBeInTheDocument() }) it('should handle large timeout values', () => { render() expect(screen.getAllByDisplayValue('9999')).toHaveLength(2) }) }) })