import React from 'react';
import { renderHook, act, cleanup } from '@testing-library/react-hooks';
import { useSharedData } from './useSharedData';

test('useSharedData testar onChange e setData', async (done) => {
   const { result, waitForNextUpdate } = renderHook(() => useSharedData<number>('nameTest'));

   const [onChange, setData] = result.current;

   onChange((v) => {
      done();
   });

   act(() => {
      setData(1);
      setData(1);
      setData(1);
   });
});

test('useSharedData atualizar valor de outro hook', async (done) => {
   const { result, waitForNextUpdate } = renderHook(() => useSharedData<number>('nameTest'));
   const { result: result2 } = renderHook(() => useSharedData<number>('nameTest2', 2));

   const [onChange, setData] = result.current;
   const [onChange2, setData2] = result2.current;

   onChange((v) => {
      done();
   });

   act(() => {
      setData2(2, 'nameTest');
   });
});
