test(useSearchModal): Add new test case for location change
Signed-off-by: Renan Mendes Carvalho <aitherios@gmail.com>
This commit is contained in:
committed by
Fredrik Adelöw
parent
3b9e96c536
commit
430b9f2890
@@ -13,10 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { act, renderHook } from '@testing-library/react-hooks';
|
||||
import { useSearchModal } from './useSearchModal';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import { BrowserRouter, Router } from 'react-router-dom';
|
||||
import { createMemoryHistory } from 'history';
|
||||
|
||||
describe('useSearchModal', () => {
|
||||
it.each([
|
||||
@@ -79,4 +80,21 @@ describe('useSearchModal', () => {
|
||||
hidden: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should hide when location changes', () => {
|
||||
const history = createMemoryHistory({ initialEntries: ['/'] });
|
||||
|
||||
const rendered = renderHook(() => useSearchModal(true), {
|
||||
wrapper: ({ children }) => (
|
||||
<Router location={history.location} navigator={history}>
|
||||
{children}
|
||||
</Router>
|
||||
),
|
||||
});
|
||||
|
||||
expect(rendered.result.current.state.hidden).toBe(false);
|
||||
act(() => history.push('/new/path'));
|
||||
rendered.rerender();
|
||||
expect(rendered.result.current.state.hidden).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,13 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React, {
|
||||
ReactNode,
|
||||
useCallback,
|
||||
useContext,
|
||||
useState,
|
||||
useEffect,
|
||||
} from 'react';
|
||||
import React, { ReactNode, useCallback, useContext, useState } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import {
|
||||
createVersionedContext,
|
||||
|
||||
Reference in New Issue
Block a user