mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(catalog-search): clear stale query filter
This commit is contained in:
@@ -121,6 +121,25 @@ describe('CatalogSearch', () => {
|
|||||||
expect(queryInput()?.getAttribute('value')).toBe('linux');
|
expect(queryInput()?.getAttribute('value')).toBe('linux');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('clears the catalog search filter when navigation removes the query param', async () => {
|
||||||
|
testState.location = {
|
||||||
|
pathname: '/mu/catalog',
|
||||||
|
search: '?q=linux',
|
||||||
|
};
|
||||||
|
|
||||||
|
await renderSearch();
|
||||||
|
|
||||||
|
testState.location = {
|
||||||
|
pathname: '/mu/catalog',
|
||||||
|
search: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
await renderSearch();
|
||||||
|
|
||||||
|
expect(testState.clearSearchFilterMock).toHaveBeenCalled();
|
||||||
|
expect(queryInput()).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
it('toggles the search UI, updates the filter and URL, and closes via Escape', async () => {
|
it('toggles the search UI, updates the filter and URL, and closes via Escape', async () => {
|
||||||
await renderSearch();
|
await renderSearch();
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,11 @@ const CatalogSearch = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (queryParam) {
|
if (queryParam) {
|
||||||
setSearchFilter(queryParam);
|
setSearchFilter(queryParam);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, [queryParam, setSearchFilter]);
|
|
||||||
|
clearSearchFilter();
|
||||||
|
}, [queryParam, setSearchFilter, clearSearchFilter]);
|
||||||
|
|
||||||
const updateURL = useCallback(
|
const updateURL = useCallback(
|
||||||
(searchText: string) => {
|
(searchText: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user