import { render } from '@testing-library/react-native';
import { View } from 'react-native';
import { ReactTestRendererJSON } from 'react-test-renderer';
import { CSReliableTarget } from '../../tracking/CSReliableTarget';

describe('CSReliableTarget', () => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  let getByTestId: (testID: string) => any;
  let toJSON: () => null | ReactTestRendererJSON | ReactTestRendererJSON[];

  beforeEach(() => {
    const rendered = render(
      <CSReliableTarget name="test-component">
        <View testID="child-view" />
      </CSReliableTarget>
    );
    getByTestId = rendered.getByTestId;
    toJSON = rendered.toJSON;
  });

  it('should render correctly with the given name as testID', () => {
    expect(getByTestId('test-component')).toBeTruthy();
    expect(toJSON()).toMatchSnapshot();
  });

  it('should render children correctly', () => {
    expect(getByTestId('child-view')).toBeTruthy();
    expect(toJSON()).toMatchSnapshot();
  });
});
