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

import CountNumber from '.';

describe('Count Number Component', () => {
  test('render count up', async () => {
    const { container, getByText } = render(<CountNumber end={20} />);
    expect(container).toBeTruthy();
    expect(getByText('0')).toBeTruthy();

    await waitFor(() => {
      expect(getByText('1')).toBeTruthy();
    }, 4000);
  });
  test('render count down', async () => {
    const { container, getByText } = render(<CountNumber end={0} start={10} increase={false} />);
    expect(container).toBeTruthy();
    expect(getByText('10')).toBeTruthy();

    await waitFor(() => {
      expect(getByText('9')).toBeTruthy();
    }, 4000);
  });
});
afterEach(() => {
  cleanup();
});
