Skip to content

Commit

Permalink
Merge pull request stakwork#4 from YLeight/fix/1408-people-search-on-…
Browse files Browse the repository at this point in the history
…person-page

Fix/1408 people search on person page
  • Loading branch information
elraphty authored Jan 25, 2024
2 parents 7eb977f + d197df1 commit e9a9a6f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/hooks/__tests__/usePeopleSearchHandler.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { mainStore } from 'store/main';
import { uiStore } from 'store/ui';
import { usePeopleSearchHandler } from 'hooks';
import { act, renderHook } from '@testing-library/react-hooks';

jest.mock('store/ui');
jest.mock('store/main');

describe('People Search Handler Hook', () => {
test('Handler should pass his argument to `ui.setSearchText` method and call `main.getPeople` method', async () => {
await act(async () => {
const { result } = renderHook(() => usePeopleSearchHandler());
const handleSearchChange = result.current;

handleSearchChange('Y');

expect(uiStore.setSearchText).toBeCalledWith('Y');

expect(mainStore.getPeople).toBeCalledTimes(1);
});
});
});
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './useScroll';
export * from './uiHooks';
export * from './usePerson';
export * from './useInViewport';
export * from './usePeopleSearchHandler';
11 changes: 11 additions & 0 deletions src/hooks/usePeopleSearchHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useStores } from 'store';

export function usePeopleSearchHandler() {
const { ui, main } = useStores();

return (newSearchText: string) => {
ui.setSearchText(newSearchText);

main.getPeople({ page: 1, resetPage: true });
};
}
7 changes: 3 additions & 4 deletions src/pages/people/peopleList/PeopleList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, SearchTextInput } from 'components/common';
import { usePageScroll } from 'hooks';
import { usePageScroll, usePeopleSearchHandler } from 'hooks';
import NoResults from 'people/utils/NoResults';
import PageLoadSpinner from 'people/utils/PageLoadSpinner';
import React from 'react';
Expand Down Expand Up @@ -68,6 +68,7 @@ export const PeopleList = observer(() => {
const { peoplePageNumber } = ui || {};
const history = useHistory();
const personId = ui.selectedPerson;
const handleSearchChange = usePeopleSearchHandler();

async function loadMorePeople(direction: number) {
let newPage = peoplePageNumber + direction;
Expand Down Expand Up @@ -113,9 +114,7 @@ export const PeopleList = observer(() => {
border: '1px solid #DDE1E5',
background: '#fff'
}}
onChange={(e: any) => {
ui.setSearchText(e);
}}
onChange={handleSearchChange}
/>
</DBack>

Expand Down

0 comments on commit e9a9a6f

Please sign in to comment.