import React from 'react';
import { render, cleanup, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { getListToplistItem } from '~tests/factories/modules/toplist.factory';

import List from '.';

describe('List', () => {
  test('render list with Load more', () => {
    const { container, getByText } = render(
      <List
        toplist={{ items: getListToplistItem(15) }}
        loadItemsCount="5"
        initItemsCount="5"
        hasLoadMoreButton="1"
      />
    );
    expect(getByText('Load More')).toBeTruthy();
    const button = container.querySelector('.primary');
    fireEvent.click(button);
  });

  test('render list without Load more', () => {
    const { container } = render(<List toplist={{ items: getListToplistItem(5) }} />);
    expect(container.querySelector('button')).toBeFalsy();
  });
});
afterEach(() => {
  cleanup();
});
