Skip to content

Commit

Permalink
feat: lowercase search input value when looking for redirects
Browse files Browse the repository at this point in the history
DAU-249
  • Loading branch information
jkaho committed Feb 7, 2023
1 parent 6797d7e commit 9966eb0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-goats-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sajari/react-search-ui': minor
---

feat: lowercase search input value when looking for redirects
16 changes: 16 additions & 0 deletions packages/search-ui/src/Input/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ describe('Input', () => {
});
});

it('ignores letter casing of input query on redirect lookup', async () => {
const onRedirectSpy = jest.spyOn(eventTrackingPipeline.getTracking(), 'onRedirect');
customRender(<Input data-testid="mysearch" mode="suggestions" />, {
search: { pipeline: eventTrackingPipeline },
});
const input = screen.getByTestId('mysearch');
input.focus(); // need this else we get TypeError: element.ownerDocument.getSelection is not a function
await user.keyboard('ShEeTs');
await waitFor(() => expect(input).toHaveTextContent('ShEeTs'));
await user.keyboard('{enter}');
expect(onRedirectSpy).toHaveBeenCalledWith({
...redirectTarget,
token: `https://re.sajari.com/token/${redirectTarget.token}`, // sdk-js prepends the clickTokenURL
});
});

it('calls onResultClick on results click', async () => {
const onResultClickSpy = jest.spyOn(eventTrackingPipeline.getTracking(), 'onResultClick');
customRender(<Input data-testid="mysearch" mode="results" />, {
Expand Down
4 changes: 2 additions & 2 deletions packages/search-ui/src/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const Input = React.forwardRef((props: InputProps<any>, ref: React.ForwardedRef<
if (!retainFilters) {
resetFilters();
}
const redirectValue = redirectsRef.current[value];
const redirectValue = redirectsRef.current[value.toLowerCase()];
if (!disableRedirects && redirectValue) {
tracking.onRedirect(redirectValue);
window.location.assign(redirectValue.token || redirectValue.target);
Expand All @@ -183,7 +183,7 @@ const Input = React.forwardRef((props: InputProps<any>, ref: React.ForwardedRef<
// If we're performing an autocomplete search, wait a tick to recheck redirects before unloading
e.preventDefault();
setTimeout(() => {
const redirectTarget = redirectsRef.current[value];
const redirectTarget = redirectsRef.current[value.toLowerCase()];
if (redirectTarget) {
tracking.onRedirect(redirectTarget);
window.location.assign(redirectTarget.token || redirectTarget.target);
Expand Down

0 comments on commit 9966eb0

Please sign in to comment.