import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import { CloseButton } from '../components/CloseButton';

describe('CloseButton', () => {
    it('should render close button text when visible is true', () => {
        const { getByText } = render(
            <CloseButton onPress={jest.fn()} visible={true} />
        );

        expect(getByText('✕')).toBeTruthy();
    });

    it('should not render when visible is false', () => {
        const { queryByText } = render(
            <CloseButton onPress={jest.fn()} visible={false} />
        );

        expect(queryByText('✕')).toBeNull();
    });

    it('should render by default when visible prop is omitted', () => {
        const { getByText } = render(
            <CloseButton onPress={jest.fn()} />
        );

        expect(getByText('✕')).toBeTruthy();
    });

    it('should call onPress when pressed', () => {
        const mockOnPress = jest.fn();
        const { getByText } = render(
            <CloseButton onPress={mockOnPress} visible={true} />
        );

        fireEvent.press(getByText('✕'));

        expect(mockOnPress).toHaveBeenCalledTimes(1);
    });

    it('should not call onPress when not pressed', () => {
        const mockOnPress = jest.fn();
        render(<CloseButton onPress={mockOnPress} visible={true} />);

        expect(mockOnPress).not.toHaveBeenCalled();
    });
});
