Skip to content

Commit

Permalink
Merge branch 'main' into feature/answers-to-search
Browse files Browse the repository at this point in the history
merge with main.
  • Loading branch information
ElemelonWind committed Jul 19, 2022
2 parents 9279f47 + ba357d1 commit 67c35ff
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/search-ui-react.renderentitypreviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export declare type RenderEntityPreviews = (autocompleteLoading: boolean, vertic

The autocomplete loading state is passed in as an optional param.

An onSubmit function is provided to allow an entity preview to be submitted.
Default props for rendering corresponding DropdownItems are passed in: an onClick function to allow an entity preview to be submitted, and an ariaLabel function that returns text for the screenreader

For the entity previews to be navigable in the search bar's dropdown section, wrap each entity preview in a [DropdownItem()](./search-ui-react.dropdownitem.md) component.

3 changes: 2 additions & 1 deletion src/components/FilterSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ export function FilterSearch({
}
answersActions.setFilterOption({ ...newFilter, displayName: newDisplayName, selected: true });
setCurrentFilter(newFilter);
answersActions.setOffset(0);
if (select && searchOnSelect) {
answersActions.setOffset(0);
answersActions.resetFacets();
executeSearch(answersActions);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export interface SearchBarCssClasses extends AutocompleteResultCssClasses {
* @remarks
* The autocomplete loading state is passed in as an optional param.
*
* An onSubmit function is provided to allow an entity preview to be submitted.
* Default props for rendering corresponding DropdownItems are passed in:
* an onClick function to allow an entity preview to be submitted, and
* an ariaLabel function that returns text for the screenreader
*
* For the entity previews to be navigable in the search bar's dropdown section,
* wrap each entity preview in a {@link DropdownItem} component.
Expand Down
8 changes: 7 additions & 1 deletion test-site/src/pages/PeoplePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ export function PeoplePage() {
const answersActions = useAnswersActions();
useLayoutEffect(() => {
answersActions.setVertical('people');
answersActions.executeVerticalQuery();
});

return (
<div>
<SearchBar />
<div className='flex'>
<div className='w-56 shrink-0 mr-5'>
<FilterSearch
searchFields={[{ fieldApiName: 'name', entityType: 'ce_person' }]}
searchOnSelect={true}
label='Filters'
/>
<div className='w-full h-px bg-gray-200 my-4' />
<NumericalFacets searchOnChange={false} />
<StandardFacets
searchable={true}
Expand All @@ -50,7 +57,6 @@ export function PeoplePage() {
searchOnChange={false}
/>
<br />
<FilterSearch searchFields={[{ fieldApiName: 'name', entityType: 'ce_person' }]} />
<ApplyFiltersButton />
</div>
<div className='flex-grow'>
Expand Down
1 change: 1 addition & 0 deletions test-site/src/pages/ProductsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function ProductsPage() {
const answersActions = useAnswersActions();
useLayoutEffect(() => {
answersActions.setVertical('products');
answersActions.executeVerticalQuery();
});

return (
Expand Down
1 change: 1 addition & 0 deletions test-site/src/pages/UniversalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function UniversalPage(): JSX.Element {
const answersActions = useAnswersActions();
useLayoutEffect(() => {
answersActions.setUniversal();
answersActions.executeUniversalQuery();
});

return (
Expand Down
12 changes: 11 additions & 1 deletion tests/components/FilterSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const actions = spyOnActions();

const setFilterOption = jest.fn();
const setOffset = jest.fn();
const resetFacets = jest.fn();
const searchFieldsProp = [{
fieldApiName: 'name',
entityType: 'ce_person'
Expand All @@ -21,6 +22,7 @@ describe('search with section labels', () => {
mockAnswersActions({
setFilterOption,
setOffset,
resetFacets,
executeFilterSearch: jest.fn().mockResolvedValue(labeledFilterSearchResponse)
});
});
Expand Down Expand Up @@ -174,12 +176,15 @@ describe('search with section labels', () => {
expect(setFilterOption).toBeCalledWith(expectedSetFilterOptionParam);
});
expect(setOffset).toBeCalledWith(expectedSetOffsetParam);
expect(resetFacets).toBeCalled();

const setFilterOptionCallOrder = setFilterOption.mock.invocationCallOrder[0];
const setOffsetCallOrder = setOffset.mock.invocationCallOrder[0];
const resetFacetsCallOrder = resetFacets.mock.invocationCallOrder[0];
const mockExecuteSearchCallOrder = mockExecuteSearch.mock.invocationCallOrder[0];
expect(setFilterOptionCallOrder).toBeLessThan(mockExecuteSearchCallOrder);
expect(setOffsetCallOrder).toBeLessThan(mockExecuteSearchCallOrder);
expect(resetFacetsCallOrder).toBeLessThan(mockExecuteSearchCallOrder);
});

it('does not trigger a search on pressing "enter" if no autocomplete result is selected', async () => {
Expand All @@ -193,6 +198,7 @@ describe('search with section labels', () => {
expect(setFilterOption).not.toBeCalled();
});
expect(setOffset).not.toBeCalled();
expect(resetFacets).not.toBeCalled();
expect(mockExecuteSearch).not.toBeCalled();
});

Expand All @@ -216,12 +222,15 @@ describe('search with section labels', () => {
userEvent.click(autocompleteSuggestion);
expect(setFilterOption).toBeCalledWith(expectedSetFilterOptionParam);
expect(setOffset).toBeCalledWith(expectedSetOffsetParam);
expect(resetFacets).toBeCalled();

const setFilterOptionCallOrder = setFilterOption.mock.invocationCallOrder[0];
const setOffsetCallOrder = setOffset.mock.invocationCallOrder[0];
const resetFacetsCallOrder = setOffset.mock.invocationCallOrder[0];
const mockExecuteSearchCallOrder = mockExecuteSearch.mock.invocationCallOrder[0];
expect(setFilterOptionCallOrder).toBeLessThan(mockExecuteSearchCallOrder);
expect(setOffsetCallOrder).toBeLessThan(mockExecuteSearchCallOrder);
expect(resetFacetsCallOrder).toBeLessThan(mockExecuteSearchCallOrder);
});
});

Expand All @@ -244,7 +253,8 @@ describe('search with section labels', () => {
selected: true
});
});
expect(setOffset).toBeCalledWith(0);
expect(setOffset).not.toHaveBeenCalled();
expect(resetFacets).not.toHaveBeenCalled();
expect(mockExecuteSearch).not.toHaveBeenCalled();
});
});
Expand Down

0 comments on commit 67c35ff

Please sign in to comment.