<commit_before>import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery';
import asideMenuCreator from '../../src/common/AsideMenu';
import { ReachableServer } from '../../src/servers/data';

jest.mock('react-router-dom', () => ({
  ...jest.requireActual('react-router-dom'),
  useLocation: jest.fn().mockReturnValue({ pathname: '' }),
}));

describe('<AsideMenu />', () => {
  let wrapped: ShallowWrapper;
  const DeleteServerButton = () => null;

  beforeEach(() => {
    const AsideMenu = asideMenuCreator(DeleteServerButton);

    wrapped = shallow(<AsideMenu selectedServer={Mock.of<ReachableServer>({ id: 'abc123' })} />);
  });
  afterEach(() => wrapped.unmount());

  it('contains links to different sections', () => {
    const links = wrapped.find('[to]');

    expect(links).toHaveLength(5);
    links.forEach((link) => expect(link.prop('to')).toContain('abc123'));
  });

  it('contains a button to delete server', () => {
    expect(wrapped.find(DeleteServerButton)).toHaveLength(1);
  });
});<commit_msg>Migrated AsideMenu test to react testing library<commit_after>import { render, screen } from '@testing-library/react';
import { Mock } from 'ts-mockery';
import { MemoryRouter } from 'react-router-dom';
import asideMenuCreator from '../../src/common/AsideMenu';
import { ReachableServer } from '../../src/servers/data';
import { SemVer } from '../../src/utils/helpers/version';

describe('<AsideMenu />', () => {
  const AsideMenu = asideMenuCreator(() => <>DeleteServerButton</>);
  const setUp = (version: SemVer, id: string | false = 'abc123') => render(
    <MemoryRouter>
      <AsideMenu selectedServer={Mock.of<ReachableServer>({ id: id || undefined, version })} />
    </MemoryRouter>,
  );

  it.each([
    ['2.7.0' as SemVer, 5],
    ['2.8.0' as SemVer, 6],
  ])('contains links to different sections', (version, expectedAmountOfLinks) => {
    setUp(version);

    const links = screen.getAllByRole('link');

    expect.assertions(links.length + 1);
    expect(links).toHaveLength(expectedAmountOfLinks);
    links.forEach((link) => expect(link.getAttribute('href')).toContain('abc123'));
  });

  it.each([
    ['abc', true],
    [false, false],
  ])('contains a button to delete server if appropriate', (id, shouldHaveBtn) => {
    setUp('2.8.0', id as string | false);

    if (shouldHaveBtn) {
      expect(screen.getByText('DeleteServerButton')).toBeInTheDocument();
    } else {
      expect(screen.queryByText('DeleteServerButton')).not.toBeInTheDocument();
    }
  });
});
{'fraction_non_alphanumeric': 0.1913214990138067, 'fraction_numerical': 0.010256410256410256, 'mean_word_length': 4.2181069958847734, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6694959', 'n_tokens_mistral': 808, 'n_tokens_neox': 791, 'n_words': 161}