import { fireEvent, render, screen } from '@testing-library/react' import { describe, expect, it, vi } from 'vitest' import AuthenticationSection from './authentication-section' describe('AuthenticationSection', () => { const defaultProps = { isDynamicRegistration: true, onDynamicRegistrationChange: vi.fn(), clientID: '', onClientIDChange: vi.fn(), credentials: '', onCredentialsChange: vi.fn(), } describe('Rendering', () => { it('should render without crashing', () => { render() expect(screen.getByText('tools.mcp.modal.useDynamicClientRegistration')).toBeInTheDocument() }) it('should render switch for dynamic registration', () => { render() expect(screen.getByRole('switch')).toBeInTheDocument() }) it('should render client ID input', () => { render() expect(screen.getByDisplayValue('test-client-id')).toBeInTheDocument() }) it('should render credentials input', () => { render() expect(screen.getByDisplayValue('test-secret')).toBeInTheDocument() }) it('should render labels for all fields', () => { render() expect(screen.getByText('tools.mcp.modal.useDynamicClientRegistration')).toBeInTheDocument() expect(screen.getByText('tools.mcp.modal.clientID')).toBeInTheDocument() expect(screen.getByText('tools.mcp.modal.clientSecret')).toBeInTheDocument() }) }) describe('Dynamic Registration Toggle', () => { it('should not show warning when isDynamicRegistration is true', () => { render() expect(screen.queryByText('tools.mcp.modal.redirectUrlWarning')).not.toBeInTheDocument() }) it('should show warning when isDynamicRegistration is false', () => { render() expect(screen.getByText('tools.mcp.modal.redirectUrlWarning')).toBeInTheDocument() }) it('should show OAuth callback URL in warning', () => { render() expect(screen.getByText(/\/mcp\/oauth\/callback/)).toBeInTheDocument() }) it('should disable inputs when isDynamicRegistration is true', () => { render() const inputs = screen.getAllByRole('textbox') inputs.forEach((input) => { expect(input).toBeDisabled() }) }) it('should enable inputs when isDynamicRegistration is false', () => { render() const inputs = screen.getAllByRole('textbox') inputs.forEach((input) => { expect(input).not.toBeDisabled() }) }) }) describe('User Interactions', () => { it('should call onDynamicRegistrationChange when switch is toggled', () => { const onDynamicRegistrationChange = vi.fn() render( , ) const switchElement = screen.getByRole('switch') fireEvent.click(switchElement) expect(onDynamicRegistrationChange).toHaveBeenCalled() }) it('should call onClientIDChange when client ID input changes', () => { const onClientIDChange = vi.fn() render( , ) const inputs = screen.getAllByRole('textbox') const clientIDInput = inputs[0] fireEvent.change(clientIDInput, { target: { value: 'new-client-id' } }) expect(onClientIDChange).toHaveBeenCalledWith('new-client-id') }) it('should call onCredentialsChange when credentials input changes', () => { const onCredentialsChange = vi.fn() render( , ) const inputs = screen.getAllByRole('textbox') const credentialsInput = inputs[1] fireEvent.change(credentialsInput, { target: { value: 'new-secret' } }) expect(onCredentialsChange).toHaveBeenCalledWith('new-secret') }) }) describe('Props', () => { it('should display provided clientID value', () => { render() expect(screen.getByDisplayValue('my-client-123')).toBeInTheDocument() }) it('should display provided credentials value', () => { render() expect(screen.getByDisplayValue('secret-456')).toBeInTheDocument() }) }) describe('Edge Cases', () => { it('should handle empty string values', () => { render() const inputs = screen.getAllByRole('textbox') expect(inputs).toHaveLength(2) inputs.forEach((input) => { expect(input).toHaveValue('') }) }) it('should handle special characters in values', () => { render( , ) expect(screen.getByDisplayValue('client@123!#$')).toBeInTheDocument() expect(screen.getByDisplayValue('secret&*()_+')).toBeInTheDocument() }) }) })