Skip to content

Commit

Permalink
Merge pull request #4064 from ProjectMirador/test-warnings
Browse files Browse the repository at this point in the history
Clean up some test warnings
  • Loading branch information
marlo-longley authored Dec 18, 2024
2 parents 8302554 + d85dadc commit 01ebfc1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
18 changes: 8 additions & 10 deletions __tests__/src/components/SearchPanelControls.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cloneElement } from 'react';
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';

Expand All @@ -7,13 +8,16 @@ import { SearchPanelControls } from '../../../src/components/SearchPanelControls
* Helper function to create a shallow wrapper around AttributionPanel
*/
function createWrapper(props) {
return render(
const component = (
<SearchPanelControls
companionWindowId="cw"
windowId="window"
fetchSearch={vi.fn()}
searchService={{ id: 'http://example.com/search' }}
{...props}
/>,
/>
);
return { component, ...render(component) };
}

describe('SearchPanelControls', () => {
Expand Down Expand Up @@ -110,16 +114,10 @@ describe('SearchPanelControls', () => {
});

it('clears the local search state/input when the incoming query prop has been cleared', () => {
const wrapper = createWrapper({ query: 'Wolpertinger' });
const { component, rerender } = createWrapper({ query: 'Wolpertinger' });
expect(screen.getByRole('combobox')).toHaveValue('Wolpertinger');

wrapper.rerender((
<SearchPanelControls
companionWindowId="cw"
windowId="window"
query=""
/>
));
rerender(cloneElement(component, { query: '' }));

expect(screen.getByRole('combobox')).toHaveValue('');
});
Expand Down
1 change: 1 addition & 0 deletions __tests__/src/components/SidebarIndexList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function createWrapper(props) {
id="asdf"
canvases={canvases}
classes={{}}
containerRef={{ current: null }}
windowId="xyz"
setCanvas={() => {}}
config={{ canvasNavigation: { height: 100 } }}
Expand Down
3 changes: 1 addition & 2 deletions src/components/ScrollTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function usePrevious(value) {
* ScrollTo ~
*/
export function ScrollTo({
children, containerRef, offsetTop = 0, scrollTo, nodeId, ...otherProps
children, containerRef, offsetTop = 0, scrollTo, ...otherProps
}) {
const scrollToRef = useRef();
const prevScrollTo = usePrevious(scrollTo);
Expand Down Expand Up @@ -60,7 +60,6 @@ ScrollTo.propTypes = {
PropTypes.func,
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
]).isRequired,
nodeId: PropTypes.string.isRequired,
offsetTop: PropTypes.number,
scrollTo: PropTypes.bool.isRequired,
};
4 changes: 2 additions & 2 deletions src/components/SearchPanelControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getMatch = (option) => (isObject(option) ? option.match : option);
/** */
export function SearchPanelControls({
autocompleteService = undefined, companionWindowId, fetchSearch, query = '',
searchIsFetching, searchService, windowId,
searchIsFetching = false, searchService, windowId,
}) {
const { t } = useTranslation();
const [input, setInput] = useState(query);
Expand Down Expand Up @@ -157,7 +157,7 @@ SearchPanelControls.propTypes = {
companionWindowId: PropTypes.string.isRequired,
fetchSearch: PropTypes.func.isRequired,
query: PropTypes.string,
searchIsFetching: PropTypes.bool.isRequired,
searchIsFetching: PropTypes.bool,
searchService: PropTypes.shape({
id: PropTypes.string,
}).isRequired,
Expand Down
3 changes: 0 additions & 3 deletions src/components/SearchPanelNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ SearchPanelNavigation.propTypes = {
direction: PropTypes.string.isRequired,
numTotal: PropTypes.number,
searchHits: PropTypes.arrayOf(PropTypes.object), // eslint-disable-line react/forbid-prop-types
searchService: PropTypes.shape({
id: PropTypes.string,
}).isRequired,
selectAnnotation: PropTypes.func.isRequired,
selectedContentSearchAnnotation: PropTypes.arrayOf(PropTypes.string).isRequired,
windowId: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
Expand Down
5 changes: 4 additions & 1 deletion src/components/SidebarIndexList.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export function SidebarIndexList({

SidebarIndexList.propTypes = {
canvases: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types
containerRef: PropTypes.oneOf([PropTypes.func, PropTypes.object]).isRequired,
containerRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
]).isRequired,
selectedCanvasIds: PropTypes.arrayOf(PropTypes.string),
setCanvas: PropTypes.func.isRequired,
variant: PropTypes.oneOf(['item', 'thumbnail']),
Expand Down

0 comments on commit 01ebfc1

Please sign in to comment.