Skip to content

Commit

Permalink
Merge pull request stakwork#471 from MuhammadUmer44/search-preserved-…
Browse files Browse the repository at this point in the history
…different-location

Fix: Preserve Search Query in Search Bar When Navigating to People Tab and User Profile
  • Loading branch information
elraphty authored Mar 26, 2024
2 parents 96224f4 + fd56ac3 commit 433633a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/people/main/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}}
>
Expand Down
25 changes: 16 additions & 9 deletions src/people/main/__tests__/MainHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,17 +20,24 @@ jest.mock('../../../store', () => ({
showSignIn: false,
torFormBodyQR: ''
}
}))
})
}));

describe('Header Component', () => {
test('renders Header component', () => {
render(<MemoryRouter>{<Header />}</MemoryRouter>);
render(
<MemoryRouter>
<Header />
</MemoryRouter>
);
});

test('clicking on the GetSphinxsBtn calls the correct handler', async () => {
render(<MemoryRouter>{<Header />}</MemoryRouter>);

test('clicking on the "Get Sphinx" button calls the correct handler', async () => {
render(
<MemoryRouter>
<Header />
</MemoryRouter>
);
const getSphinxsBtn = screen.getByText('Get Sphinx');
fireEvent.click(getSphinxsBtn);
});
Expand Down
1 change: 1 addition & 0 deletions src/people/userInfo/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down

0 comments on commit 433633a

Please sign in to comment.