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

import CountDate from '.';

describe('Count Date Component', () => {
  test('render count date', async () => {
    const twoDaysFuture = new Date().getTime() + 1000 * 3600 * 48;
    const { container, getByText } = render(<CountDate targetDate={twoDaysFuture} />);
    expect(container).toBeTruthy();
    expect(container.querySelectorAll('span')).toHaveLength(2);
    expect(getByText('23 h : 59 m : 59 s')).toBeTruthy();

    await waitFor(() => {
      expect(container.querySelectorAll('span')).toHaveLength(2);
      expect(getByText('23 h : 59 m : 58 s')).toBeTruthy();
    }, 1000);
  });
});
afterEach(() => {
  cleanup();
});
