import { ResponsiveDialog } from '@/components/Dialog' import { Button, TextField, TwakeMuiThemeProvider } from '@linagora/twake-mui' import { fireEvent, render, screen } from '@testing-library/react' import React from 'react' describe('ResponsiveDialog', () => { const mockOnClose = jest.fn() const mockOnExpandToggle = jest.fn() const renderWithTheme = (ui: React.ReactElement) => { return render({ui}) } beforeEach(() => { mockOnClose.mockClear() mockOnExpandToggle.mockClear() }) it('renders in normal mode by default', () => { renderWithTheme( ) expect(screen.getByText('Test Dialog')).toBeInTheDocument() expect(screen.getByLabelText(/name/i)).toBeInTheDocument() }) it('renders title in normal mode', () => { renderWithTheme(
Content
) expect(screen.getByText('My Title')).toBeInTheDocument() expect(screen.queryByLabelText('show less')).not.toBeInTheDocument() }) it('renders back arrow in extended mode', () => { renderWithTheme(
Content
) expect(screen.queryByText('My Title')).not.toBeInTheDocument() expect(screen.getByLabelText('show less')).toBeInTheDocument() }) it('calls onExpandToggle when back arrow is clicked', () => { renderWithTheme(
Content
) const backButton = screen.getByLabelText('show less') fireEvent.click(backButton) expect(mockOnExpandToggle).toHaveBeenCalledTimes(1) }) it('renders actions when provided', () => { renderWithTheme( Custom Action} >
Content
) expect(screen.getByText('Custom Action')).toBeInTheDocument() }) it('does not render actions when not provided', () => { const { container } = renderWithTheme(
Content
) const dialogActions = container.querySelector('.MuiDialogActions-root') expect(dialogActions).not.toBeInTheDocument() }) it('calls onClose when backdrop is clicked', () => { renderWithTheme(
Content
) const backdrop = document.querySelector('.MuiBackdrop-root') if (backdrop) { fireEvent.click(backdrop) } expect(mockOnClose).toHaveBeenCalled() }) it('applies custom normalMaxWidth', () => { renderWithTheme(
Normal Width Content
) expect(screen.getByText('Normal Width Content')).toBeInTheDocument() }) it('wraps children in Stack component', () => { renderWithTheme( ) expect(screen.getByLabelText('Field 1')).toBeInTheDocument() expect(screen.getByLabelText('Field 2')).toBeInTheDocument() }) it('uses correct spacing in normal mode', () => { renderWithTheme(
Normal Spacing Content
) expect(screen.getByText('Normal Spacing Content')).toBeInTheDocument() }) it('uses correct spacing in extended mode', () => { renderWithTheme(
Extended Spacing Content
) expect(screen.getByText('Extended Spacing Content')).toBeInTheDocument() }) it('applies contentSx custom styles', () => { renderWithTheme(
Custom Styled Content
) expect(screen.getByText('Custom Styled Content')).toBeInTheDocument() }) it('applies titleSx custom styles', () => { const { container } = renderWithTheme(
Content
) const title = screen.getByText('Test') expect(title).toBeInTheDocument() }) it('shows dividers when dividers prop is true', () => { renderWithTheme(
Content with Dividers
) expect(screen.getByText('Content with Dividers')).toBeInTheDocument() }) it('does not show back arrow when onExpandToggle is not provided', () => { renderWithTheme(
Content
) expect(screen.queryByLabelText('show less')).not.toBeInTheDocument() expect(screen.getByText('Test Title')).toBeInTheDocument() }) it('accepts custom headerHeight', () => { renderWithTheme(
Custom Header Content
) expect(screen.getByText('Custom Header Content')).toBeInTheDocument() }) it('renders with custom expandedContentMaxWidth', () => { renderWithTheme(
Wide Content
) expect(screen.getByText('Wide Content')).toBeInTheDocument() }) it('does not render dialog content when open is false', () => { renderWithTheme(
Test Content
) expect(screen.queryByText('Test Content')).not.toBeInTheDocument() }) it('renders correctly in extended mode', () => { renderWithTheme(
Extended Content
) expect(screen.getByText('Extended Content')).toBeInTheDocument() expect(screen.getByLabelText('show less')).toBeInTheDocument() }) it('renders expand and close icons in normal mode when showHeaderActions is true', () => { renderWithTheme(
Content
) expect(screen.getByLabelText('expand')).toBeInTheDocument() expect(screen.getByLabelText('close')).toBeInTheDocument() }) it('does not render header icons when showHeaderActions is false', () => { renderWithTheme(
Content
) expect(screen.queryByLabelText('expand')).not.toBeInTheDocument() expect(screen.queryByLabelText('close')).not.toBeInTheDocument() expect(screen.getByText('Test Title')).toBeInTheDocument() }) it('calls onClose when close icon is clicked', () => { renderWithTheme(
Content
) const closeButton = screen.getByLabelText('close') fireEvent.click(closeButton) expect(mockOnClose).toHaveBeenCalledTimes(1) }) it('calls onExpandToggle when expand icon is clicked', () => { renderWithTheme(
Content
) const expandButton = screen.getByLabelText('expand') fireEvent.click(expandButton) expect(mockOnExpandToggle).toHaveBeenCalledTimes(1) }) })