Skip to content

Commit

Permalink
resolve comments: update tests + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaho committed Feb 7, 2023
1 parent fe9ea75 commit 918b429
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
5 changes: 0 additions & 5 deletions .changeset/plenty-goats-tan.md

This file was deleted.

6 changes: 6 additions & 0 deletions .changeset/strong-tomatoes-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sajari/react-search-ui': minor
'sajari-sdk-docs': patch
---

feat: make redirects case-insensitive for search input component
6 changes: 6 additions & 0 deletions docs/pages/search-ui/input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ function Example() {
}
```
### Note
The `Input` component treats redirects as _case-insensitive_, meaning the user-inputted value `Computer` will return the redirect for the query `computer` and vice versa.
The component does not support the handling of multiple redirects for queries of the same word with varied letter casing. For example, if you have created redirects for each of the queries `computer`, `Computer`, and `COMPUTER`, only one of them will be used (dependant upon your browser).
## Results
```jsx
Expand Down
15 changes: 11 additions & 4 deletions packages/search-ui/src/Input/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const redirectTarget = {
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwdXJwb3NlIjoic2VhcmNoIiwiZGVzdGluYXRpb24iOiJodHRwOi8vdGFyZ2V0LmNvbS5hdS9zaGVldHMiLCJ2YWxzIjp7ImNvbGxlY3Rpb24iOlsiYmVzdGJ1eSJdLCJpZGVudGlmaWVyIjpbInJlZGlyZWN0Il0sInByb2plY3QiOlsiMTU5NDE1MzcxMTkwMTcyNDIyMCJdLCJxIjpbInNoZWV0cyJdLCJxLmlkIjpbIjc2ZGJiOGU2LWE3MDctNDU2NC1iYTYxLWY0NjNiYTRhZDdlYSJdLCJxLnVpZCI6WyI3NmRiYjhlNi1hNzA3LTQ1NjQtYmE2MS1mNDYzYmE0YWQ3ZWEwIl0sInJlZGlyZWN0LkNvbmRpdGlvbiI6WyJxIH4gJ3NoZWV0cyciXSwicmVkaXJlY3QuSUQiOlsiMjJ3MFZGdkdWYVlhQ1Jzc0NBUm11YkQ2bGdUIl0sInJlZGlyZWN0LlRhcmdldCI6WyJodHRwOi8vdGFyZ2V0LmNvbS5hdS9zaGVldHMiXX19.BhcAVPB4z9LjlIoV42CUaEW-H0qCJ2JKngs6OGAXTf8',
};
const redirectTarget2 = {
id: '12w0VFvGVaYaCRssCARmubD6lgA',
target: 'http://target.com.au/sheets2',
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwdXJwb3NlIjoic2VhcmNoIiwiZGVzdGluYXRpb24iOiJodHRwOi8vdGFyZ2V0LmNvbS5hdS9zaGVldHMiLCJ2YWxzIjp7ImNvbGxlY3Rpb24iOlsiYmVzdGJ1eSJdLCJpZGVudGlmaWVyIjpbInJlZGlyZWN0Il0sInByb2plY3QiOlsiMTU5NDE1MzcxMTkwMTcyNDIyMCJdLCJxIjpbInNoZWV0cyJdLCJxLmlkIjpbIjc2ZGJiOGU2LWE3MDctNDU2NC1iYTYxLWY0NjNiYTRhZDdlYSJdLCJxLnVpZCI6WyI3NmRiYjhlNi1hNzA3LTQ1NjQtYmE2MS1mNDYzYmE0YWQ3ZWEwIl0sInJlZGlyZWN0LkNvbmRpdGlvbiI6WyJxIH4gJ3NoZWV0cyciXSwicmVkaXJlY3QuSUQiOlsiMjJ3MFZGdkdWYVlhQ1Jzc0NBUm11YkQ2bGdUIl0sInJlZGlyZWN0LlRhcmdldCI6WyJodHRwOi8vdGFyZ2V0LmNvbS5hdS9zaGVldHMiXX19.BhcAVPB4z9LjlIoV42CUaEW-H0qCJ2JKngs6OGAXTf9',
};
const iPhoneResult = {
values: {
_id: {
Expand Down Expand Up @@ -53,6 +59,7 @@ const server = setupServer(
},
redirects: {
sheets: redirectTarget,
Sheets: redirectTarget2,
},
searchResponse: {
reads: '141',
Expand Down Expand Up @@ -96,8 +103,8 @@ describe('Input', () => {
await user.keyboard('{enter}');

expect(onRedirectSpy).toHaveBeenCalledWith({
...redirectTarget,
token: `https://re.sajari.com/token/${redirectTarget.token}`, // sdk-js prepends the clickTokenURL
...redirectTarget2,
token: `https://re.sajari.com/token/${redirectTarget2.token}`, // sdk-js appends the clickTokenURL
});
});

Expand All @@ -112,8 +119,8 @@ describe('Input', () => {
await waitFor(() => expect(screen.getByText('suggestion')).toBeInTheDocument());
await user.keyboard('{enter}');
expect(onRedirectSpy).toHaveBeenCalledWith({
...redirectTarget,
token: `https://re.sajari.com/token/${redirectTarget.token}`, // sdk-js prepends the clickTokenURL
...redirectTarget2,
token: `https://re.sajari.com/token/${redirectTarget2.token}`, // sdk-js appends the clickTokenURL
});
});

Expand Down
5 changes: 3 additions & 2 deletions packages/search-ui/src/Input/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ test('lowercaseRedirects', () => {
FoO: { id: '1', target: 'a' },
BAR: { id: '2', target: 'b' },
baz: { id: '3', target: 'c' },
Test: { id: '4', target: 'd' },
test: { id: '4', target: 'd' },
Test: { id: '5', target: 'e' },
};
const want = {
foo: { id: '1', target: 'a' },
bar: { id: '2', target: 'b' },
baz: { id: '3', target: 'c' },
test: { id: '4', target: 'd' },
test: { id: '5', target: 'e' },
};

const got = lowercaseObjectKeys(redirects);
Expand Down

0 comments on commit 918b429

Please sign in to comment.