import React from 'react';

import { useScrollLock } from '../hooks';
import renderWithTheme from '../../../testUtils/renderWithTheme';

window.scrollTo = jest.fn();

describe('scroll lock', () => {
  const SomeComponent = ({ open = false }: { open?: boolean }) => {
    useScrollLock(open);

    return <div>Test</div>;
  };
  it('set body position correctly based on component open prop', () => {
    expect(document.body.style.position).toEqual('');
    const { rerender } = renderWithTheme(<SomeComponent open />);

    expect(document.body.style.position).toEqual('fixed');

    rerender(<SomeComponent />);
    expect(document.body.style.position).toEqual('');
  });

  it('set body position correctly based on component mounted state', () => {
    expect(document.body.style.position).toEqual('');
    const { unmount } = renderWithTheme(<SomeComponent open />);

    expect(document.body.style.position).toEqual('fixed');

    unmount();
    expect(document.body.style.position).toEqual('');
  });
});
