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

import { getArchiveModule } from '~tests/factories/modules/card.factory';
import Pagination from '~molecules/pagination';
import Archive from '.';

describe('archive component', () => {
  test('render items', () => {
    const archiveModule = getArchiveModule(3);

    const { container, getByText } = render(
      <Archive
        module={archiveModule}
        PaginationComponent={Pagination}
        loadMore={null}
        page={{ page: { translations: {} } }}
      />
    );
    expect(container).toBeTruthy();
    expect(getByText('Card 3')).toBeTruthy();
  });

  test('load more', () => {
    const archiveModule = getArchiveModule(4, 2);

    const { container, getByText } = render(
      <Archive
        module={archiveModule}
        page={{ page: { translations: {} } }}
        loadMore={{
          limit: 3,
          increment: 6,
        }}
      />
    );
    expect(getByText('Load More')).toBeTruthy();

    // click
    fireEvent.click(getByText('Load More'));
    expect(getByText('Card 2')).toBeTruthy();
    expect(getByText('Card 3')).toBeTruthy();
  });
});
afterEach(() => {
  cleanup();
});
