diff --git a/src/people/main/Header.tsx b/src/people/main/Header.tsx index 779191ee..4ef9064c 100644 --- a/src/people/main/Header.tsx +++ b/src/people/main/Header.tsx @@ -475,9 +475,13 @@ function Header() { key={i} to={t.path} selected={selected} - onClick={() => { + onClick={(e: any) => { + e.preventDefault(); + ui.setSearchText(''); + if (t.name === 'people') { + main.getPeople({ resetPage: true }); + } history.push(t.path); - ui.searchText && ui.setSearchText(''); localStorage.setItem('key', t.path); }} > diff --git a/src/people/main/__tests__/MainHeader.spec.tsx b/src/people/main/__tests__/MainHeader.spec.tsx index c9bb3e1f..d1eac458 100644 --- a/src/people/main/__tests__/MainHeader.spec.tsx +++ b/src/people/main/__tests__/MainHeader.spec.tsx @@ -2,14 +2,14 @@ import React from 'react'; import { render, screen, fireEvent } from '@testing-library/react'; import '@testing-library/jest-dom'; import { MemoryRouter } from 'react-router-dom'; -import { observer } from 'mobx-react-lite'; import Header from '../Header'; jest.mock('../../../store', () => ({ - useStores: jest.fn(() => ({ + useStores: () => ({ main: { - getIsAdmin: jest.fn(), - getSelf: jest.fn() + getIsAdmin: jest.fn().mockResolvedValue(false), + getSelf: jest.fn().mockResolvedValue({}), + getPeople: jest.fn().mockResolvedValue([]) }, ui: { meInfo: null, @@ -20,17 +20,24 @@ jest.mock('../../../store', () => ({ showSignIn: false, torFormBodyQR: '' } - })) + }) })); describe('Header Component', () => { test('renders Header component', () => { - render({
}); + render( + +
+ + ); }); - test('clicking on the GetSphinxsBtn calls the correct handler', async () => { - render({
}); - + test('clicking on the "Get Sphinx" button calls the correct handler', async () => { + render( + +
+ + ); const getSphinxsBtn = screen.getByText('Get Sphinx'); fireEvent.click(getSphinxsBtn); }); diff --git a/src/people/userInfo/hooks.ts b/src/people/userInfo/hooks.ts index d10eb51f..fd59517d 100644 --- a/src/people/userInfo/hooks.ts +++ b/src/people/userInfo/hooks.ts @@ -20,6 +20,7 @@ export const useUserInfo = () => { ui.setSelectingPerson(0); const path = localStorage.getItem('key'); if (path) { + ui.setSearchText(''); history.replace(path); } else { history.replace('/');