import React from 'react';
import { render, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import ConditionalWrapper from '.';

const MyComponent = () => <div className="my-component" />;
const MyWrapper = (children) => <div className="my-warpper">{children}</div>;

describe('ConditionalWrapper Component', () => {
  test('render without crash', () => {
    const { container } = render(
      <ConditionalWrapper condition wrapper={MyWrapper}>
        <MyComponent />
      </ConditionalWrapper>
    );
    expect(container).toBeTruthy();
    expect(container.querySelector('.my-component')).toBeTruthy();
    expect(container.querySelector('.my-warpper')).toBeTruthy();
  });
  test('render with false condition', () => {
    const { container } = render(
      <ConditionalWrapper condition={false} wrapper={MyWrapper}>
        <MyComponent />
      </ConditionalWrapper>
    );
    expect(container).toBeTruthy();
    expect(container.querySelector('.my-component')).toBeTruthy();
    expect(container.querySelector('.my-warpper')).toBeFalsy();
  });
});
afterEach(() => {
  cleanup();
});
