From f7103ac6b5650abfb3afcae63c6d90c5113c7d8d Mon Sep 17 00:00:00 2001 From: Ryuash <42913823+ryuash@users.noreply.github.com> Date: Mon, 6 Dec 2021 12:04:53 +0800 Subject: [PATCH] add: searchbar testing (#571) --- .../nav/components/seach_bar/hooks.test.ts | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/components/nav/components/seach_bar/hooks.test.ts diff --git a/src/components/nav/components/seach_bar/hooks.test.ts b/src/components/nav/components/seach_bar/hooks.test.ts new file mode 100644 index 0000000000..472228f509 --- /dev/null +++ b/src/components/nav/components/seach_bar/hooks.test.ts @@ -0,0 +1,85 @@ +import { RecoilRoot } from 'recoil'; +import { + renderHook, act, +} from '@testing-library/react-hooks'; +import { useSearchBar } from './hooks'; + +const mockPush = jest.fn(); + +jest.mock('next/router', () => ({ + useRouter: () => ({ + push: mockPush, + }), +})); + +jest.mock('react-toastify', () => ({ + toast: jest.fn(), +})); + +const t = jest.fn((value) => value); + +describe('misc: useSearchBar', () => { + it('use a validator address', async () => { + const { result } = renderHook(() => useSearchBar(t), { + wrapper: RecoilRoot, + }); + act(() => { + result.current.handleOnSubmit('desmosvaloper1jrld5g998gqm4yx26l6cvhxz7y5adgxqzfdpes'); + }); + expect(mockPush).toBeCalledWith('/validators/desmosvaloper1jrld5g998gqm4yx26l6cvhxz7y5adgxqzfdpes'); + }); + + it('use a consensus address', async () => { + const { result } = renderHook(() => useSearchBar(t), { + wrapper: RecoilRoot, + }); + act(() => { + result.current.handleOnSubmit('desmosvalcons1rzhewpmmdl72lhnxj6zmxr4v94f522s4hyz467'); + }); + expect(mockPush).toBeCalledTimes(0); + }); + + it('use a user address', async () => { + const { result } = renderHook(() => useSearchBar(t), { + wrapper: RecoilRoot, + }); + act(() => { + result.current.handleOnSubmit('desmos1jrld5g998gqm4yx26l6cvhxz7y5adgxquy94nz'); + }); + expect(mockPush).toBeCalledWith('/accounts/desmos1jrld5g998gqm4yx26l6cvhxz7y5adgxquy94nz'); + }); + + it('use a dtag', async () => { + const { result } = renderHook(() => useSearchBar(t), { + wrapper: RecoilRoot, + }); + act(() => { + result.current.handleOnSubmit('@desmos1jrld5g998gqm4yx26l6cvhxz7y5adgxquy94nz'); + }); + expect(mockPush).toBeCalledWith('/@desmos1jrld5g998gqm4yx26l6cvhxz7y5adgxquy94nz'); + }); + + it('use a block', async () => { + const { result } = renderHook(() => useSearchBar(t), { + wrapper: RecoilRoot, + }); + act(() => { + result.current.handleOnSubmit('300,000'); + }); + expect(mockPush).toBeCalledWith('/blocks/300000'); + }); + + it('use a transactions', async () => { + const { result } = renderHook(() => useSearchBar(t), { + wrapper: RecoilRoot, + }); + act(() => { + result.current.handleOnSubmit('FF4ED0EA688507EF3469804580136B4925116FC9B5F5658AF2B65E987A2138E0'); + }); + expect(mockPush).toBeCalledWith('/transactions/FF4ED0EA688507EF3469804580136B4925116FC9B5F5658AF2B65E987A2138E0'); + }); +}); + +afterEach(() => { + jest.clearAllMocks(); +});