Skip to content

Commit

Permalink
whoo, that should be it!
Browse files Browse the repository at this point in the history
  • Loading branch information
aradmargalit authored and eshedmargalit committed Jan 10, 2021
1 parent a60749b commit baa811c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
49 changes: 49 additions & 0 deletions client/src/components/PaperSearchBar/PaperSearchBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,54 @@ describe('<PaperSearchBar />', () => {
// Once no result comes back from our mocked API, confirm our custom message is rendered
await waitFor(() => expect(screen.getByText('No Results Found')).toBeDefined());
});

describe('result interaction', () => {
it('shows both options on click', async () => {
// Render some basic results
renderWithRouterRedux(<PaperSearchBar />);

// Type in a search query
const searchInput = screen.getByPlaceholderText(/search by/);
userEvent.type(searchInput, 'http://dx.doi.org/10.1523/JNEUROSCI.2106-19');
await waitFor(() => screen.getByText('Test DOI Title'));

// Click on the item
userEvent.click(screen.getByText('Test DOI Title'));

// Confirm both popover options are present
expect(screen.getByText(/Add to Reading List/)).toBeDefined();
expect(screen.getByText(/Start Review Now/)).toBeDefined();
});

it('adds results to the reading list', async () => {
// Render some basic results
renderWithRouterRedux(<PaperSearchBar />);

// Type in a search query
const searchInput = screen.getByPlaceholderText(/search by/);
userEvent.type(searchInput, 'http://dx.doi.org/10.1523/JNEUROSCI.2106-19');
await waitFor(() => screen.getByText('Test DOI Title'));

// Click on the item
userEvent.click(screen.getByText('Test DOI Title'));
userEvent.click(screen.getByText(/Add to Reading List/));
});

it('starts the review now', async () => {
// Render some basic results
renderWithRouterRedux(<PaperSearchBar />, { redirectTo: '/form' });

// Type in a search query
const searchInput = screen.getByPlaceholderText(/search by/);
userEvent.type(searchInput, 'test query');
await waitFor(() => screen.getByText('Test Interpret Title'));

// Click on the item
userEvent.click(screen.getByText('Test Interpret Title'));
userEvent.click(screen.getByText(/Start Review Now/));

expect(screen.getByText(/Redirected/)).toBeDefined();
});
});
});
});
3 changes: 3 additions & 0 deletions client/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ export const handlers = [
rest.get('/api/doi/*', (_req, res, ctx) => {
return res(ctx.status(200), ctx.json({ ...blankPaper, title: 'Test DOI Title' }));
}),
rest.put('/api/readingList', (_req, res, ctx) => {
return res(ctx.status(200), ctx.json([{ ...blankPaper, title: 'Test Paper Title' }, blankPaper]));
}),
];

0 comments on commit baa811c

Please sign in to comment.