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 8, 2023
1 parent fe9ea75 commit cca168c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 26 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` returns 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 is used (dependent upon your browser).
## Results
```jsx
Expand Down
58 changes: 39 additions & 19 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 All @@ -77,6 +84,7 @@ describe('Input', () => {
});
afterEach(() => {
jest.clearAllMocks();
jest.resetAllMocks();
server.resetHandlers();
});
afterAll(() => {
Expand All @@ -92,28 +100,12 @@ describe('Input', () => {
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(screen.getByText('suggestion')).toBeInTheDocument());
await waitFor(() => expect(screen.getByRole('option')).toHaveTextContent('suggestion'));
await user.keyboard('{enter}');

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

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(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 Expand Up @@ -172,3 +164,31 @@ describe('Input', () => {
await waitFor(() => expect(input.attributes.getNamedItem('readonly')).toBeNull());
});
});

describe('redirects', () => {
beforeAll(() => {
server.listen({ onUnhandledRequest: 'warn' });
});
afterAll(() => {
jest.restoreAllMocks();
server.close();
});

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 userEvent.type(input, 'ShEeTs');
await waitFor(() => expect(screen.getByRole('option')).toHaveTextContent('suggestion'));
await userEvent.keyboard('{enter}');
await waitFor(() => {
expect(onRedirectSpy).toHaveBeenCalledWith({
...redirectTarget2,
token: `https://re.sajari.com/token/${redirectTarget2.token}`, // sdk-js appends the clickTokenURL
});
});
});
});
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 cca168c

Please sign in to comment.