import { render } from '@testing-library/react-native';
import { Text } from 'react-native';
import { CSMask } from '../../../replay/masking/CSMask.android.tsx';
import CSMaskedView from '../../../replay/masking/CSMaskedView.tsx';
import CSUnmaskedView from '../../../replay/masking/CSUnmaskedView.tsx';

jest.mock('../../../replay/masking/CSMaskedView', () =>
  jest.fn(({ children }) => <>{children}</>)
);
jest.mock('../../../replay/masking/CSUnmaskedView', () =>
  jest.fn(({ children }) => <>{children}</>)
);

describe('CSMask', () => {
  beforeEach(() => {
    jest.clearAllMocks();
  });

  it('should render CSMaskedView when isMasking is true', () => {
    const { getByText } = render(
      <CSMask isMasking={true}>
        <Text>Masked content</Text>
      </CSMask>
    );

    expect(CSMaskedView).toHaveBeenCalled();
    expect(CSUnmaskedView).not.toHaveBeenCalled();
    expect(getByText('Masked content')).toBeTruthy();
  });

  it('should render CSUnmaskedView when isMasking is false', () => {
    const { getByText } = render(
      <CSMask isMasking={false}>
        <Text>Unmasked content</Text>
      </CSMask>
    );

    expect(CSUnmaskedView).toHaveBeenCalled();
    expect(CSMaskedView).not.toHaveBeenCalled();
    expect(getByText('Unmasked content')).toBeTruthy();
  });

  it('should render CSMaskedView when isMasking is not provided', () => {
    const { getByText } = render(
      <CSMask>
        <Text>Default masking</Text>
      </CSMask>
    );

    expect(CSMaskedView).toHaveBeenCalled();
    expect(CSUnmaskedView).not.toHaveBeenCalled();
    expect(getByText('Default masking')).toBeTruthy();
  });
});
