import React from 'react';
import { render } from '@testing-library/react';
import UserAuthWrapper from '../../legacy/customAuthWrapper';

const MockComponent = React.forwardRef((props, ref) => <div ref={ref} {...props}>Mock Component</div>);

describe('UserAuthWrapper HOC', () => {
  const getWrappedComponent = (props = {}) => {
    const WrappedComponent = UserAuthWrapper({})(MockComponent);
    return render(<WrappedComponent {...props} />);
  };

  it('forwards a ref to the DecoratedComponent', () => {
    const ref = React.createRef();
    getWrappedComponent({ isAuthenticated: true, ref });
    expect(ref.current).toBeInstanceOf(HTMLElement);
  });

  it('forwards a ref to the AuthenticatingComponent when isAuthenticating', () => {
    const ref = React.createRef();
    getWrappedComponent({ isAuthenticating: true, ref });
    expect(ref.current).toBeInstanceOf(HTMLElement);
  });

  it('forwards a ref to the FailureComponent when authentication fails', () => {
    const ref = React.createRef();
    getWrappedComponent({ ref });
    expect(ref.current).toBeInstanceOf(HTMLElement);
  });
});