Skip to content

Commit

Permalink
UIIN-2514 Reset all will move focus to input in Browse
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis committed Nov 7, 2023
1 parent dbdf65e commit 3f44a38
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/components/InstancesList/InstancesList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ describe('InstancesList', () => {
});
});

describe('when user clicks Reset all', () => {
it('should move focus to query input', () => {
renderInstancesList({
segment: 'instances',
});

fireEvent.change(screen.getByRole('textbox', { name: 'Search' }), { target: { value: 'test' } });
fireEvent.click(screen.getAllByRole('button', { name: 'Search' })[1]);
fireEvent.click(screen.getByRole('button', { name: 'Reset all' }));

expect(screen.getByRole('textbox', { name: 'Search' })).toHaveFocus();
});
});

describe('when search segment is changed', () => {
it('should clear selected rows', () => {
const {
Expand Down Expand Up @@ -490,7 +504,7 @@ describe('InstancesList', () => {
renderInstancesList({ segment: 'instances' });

fireEvent.click(screen.getByRole('button', { name: 'Advanced search' }));
fireEvent.change(screen.getAllByRole('textbox', { name: 'Search for' })[0], {
indexRef(screen.getAllByRole('textbox', { name: 'Search for' })[0], {

Check failure on line 507 in src/components/InstancesList/InstancesList.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'indexRef' is not defined

Check failure on line 507 in src/components/InstancesList/InstancesList.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'indexRef' is not defined
target: { value: 'test2' }
});
const advancedSearchSubmit = screen.getAllByRole('button', { name: 'Search' })[0];
Expand All @@ -515,7 +529,7 @@ describe('InstancesList', () => {
renderInstancesList({ segment: 'instances' });

fireEvent.click(screen.getByRole('button', { name: 'Advanced search' }));
fireEvent.change(screen.getAllByRole('textbox', { name: 'Search for' })[0], {
indexRef(screen.getAllByRole('textbox', { name: 'Search for' })[0], {

Check failure on line 532 in src/components/InstancesList/InstancesList.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'indexRef' is not defined

Check failure on line 532 in src/components/InstancesList/InstancesList.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'indexRef' is not defined
target: { value: 'test' }
});

Expand All @@ -531,7 +545,7 @@ describe('InstancesList', () => {
it('should show Save Holdings UUIDs button', () => {
renderInstancesList({ segment: 'holdings' });

fireEvent.change(screen.getByRole('combobox'), {
indexRef(screen.getByRole('combobox'), {

Check failure on line 548 in src/components/InstancesList/InstancesList.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'indexRef' is not defined

Check failure on line 548 in src/components/InstancesList/InstancesList.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'indexRef' is not defined
target: { value: 'all' }
});

Expand Down
12 changes: 10 additions & 2 deletions src/views/BrowseInventory/BrowseInventory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState, useEffect, useMemo } from 'react';
import React, { useCallback, useState, useEffect, useMemo, useRef } from 'react';
import { useIntl } from 'react-intl';
import { useHistory, useLocation } from 'react-router-dom';

Expand Down Expand Up @@ -46,6 +46,8 @@ const BrowseInventory = () => {
const { isFiltersOpened, toggleFilters } = useFiltersToogle(`${namespace}/filters`);
const { deleteItemToView } = useItemToView('browse');
const [pageConfig, setPageConfig] = useState(getLastBrowseOffset());
const inputRef = useRef();

const { search } = location;

useEffect(() => {
Expand Down Expand Up @@ -134,6 +136,11 @@ const BrowseInventory = () => {
changeSearchIndex(e);
}, []);

const onReset = useCallback(() => {
resetFilters();
inputRef.current.focus();
}, [inputRef.current]);

return (
<PersistedPaneset
appId={namespace}
Expand All @@ -160,10 +167,11 @@ const BrowseInventory = () => {
selectedIndex={searchIndex}
searchableIndexesPlaceholder={searchableIndexesPlaceholder}
inputType="textarea"
inputRef={inputRef}
/>

<ResetButton
reset={resetFilters}
reset={onReset}
disabled={isResetButtonDisabled}
/>

Expand Down
13 changes: 13 additions & 0 deletions src/views/BrowseInventory/BrowseInventory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,17 @@ describe('BrowseInventory', () => {
expect(getByText('Contributors')).toBeDefined();
expect(getByText('Subjects')).toBeDefined();
});

describe('when user clicks on Reset all', () => {
it('should move focus to query input', () => {
renderBrowseInventory();

fireEvent.change(screen.getByRole('combobox'), { target: { value: 'contributors' } });
userEvent.type(screen.getByRole('textbox'), 'test')

Check failure on line 225 in src/views/BrowseInventory/BrowseInventory.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing semicolon

Check failure on line 225 in src/views/BrowseInventory/BrowseInventory.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing semicolon
fireEvent.click(screen.getByRole('button', { name: 'Search' }));
fireEvent.click(screen.getByRole('button', { name: 'Reset all' }));

expect(screen.getByRole('textbox')).toHaveFocus();
});
});
});

0 comments on commit 3f44a38

Please sign in to comment.