import {renderHook} from '@testing-library/react';
import {useRangeDate} from '.';
import dayjs from 'dayjs';
import {act} from 'react-dom/test-utils';

describe('useRangeDate', function () {
  it('声明', function () {
    expect(useRangeDate).toBeDefined();
    expect(useRangeDate).toBeInstanceOf(Function);
  });

  it('返回值', function () {
    const {result} = renderHook(function () {
      return useRangeDate(dayjs(), dayjs());
    });

    expect(result.current[0].start).toBe('2023-03-09');
    expect(result.current[0].end).toBe('2023-03-09');

    act(function () {
      result.current[1]([dayjs().add(1, 'day'), dayjs().add(2, 'day')]);
    });

    expect(result.current[0].start).toBe('2023-03-10');
    expect(result.current[0].end).toBe('2023-03-11');
  });
});
