-
Notifications
You must be signed in to change notification settings - Fork 166
LG-8407: PO Search: search button shows loading state #7502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4e9b7b7
b4ec1ba
42ed342
ffaa02f
79403c7
d3cd26c
f696422
8067141
ecd7ab1
c36ab8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import { setupServer } from 'msw/node'; | ||
| import { rest } from 'msw'; | ||
| import type { SetupServerApi } from 'msw/node'; | ||
| import { fetch } from 'whatwg-fetch'; | ||
| import { useSandbox } from '@18f/identity-test-helpers'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import AddressSearch, { ADDRESS_SEARCH_URL } from './address-search'; | ||
|
|
||
| const DEFAULT_RESPONSE = [ | ||
| { | ||
| address: '100 Main St E, Bronwood, Georgia, 39826', | ||
| location: { | ||
| latitude: 31.831686000000005, | ||
| longitude: -84.363768, | ||
| }, | ||
| street_address: '100 Main St E', | ||
| city: 'Bronwood', | ||
| state: 'GA', | ||
| zip_code: '39826', | ||
| }, | ||
| ]; | ||
|
|
||
| describe('AddressSearch', () => { | ||
| const sandbox = useSandbox(); | ||
|
|
||
| let server: SetupServerApi; | ||
| before(() => { | ||
| global.window.fetch = fetch; | ||
|
||
| server = setupServer( | ||
| rest.post(ADDRESS_SEARCH_URL, (_req, res, ctx) => res(ctx.json(DEFAULT_RESPONSE))), | ||
| ); | ||
| server.listen(); | ||
| }); | ||
|
|
||
| after(() => { | ||
| server.close(); | ||
| global.window.fetch = () => Promise.reject(new Error('Fetch must be stubbed')); | ||
| }); | ||
|
|
||
| it('fires the callback with correct input', async () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes me reconsider how opinionated this component should be about the return value... I don't think it's appropriate for it only return the best match, and maybe that should be dealt with on the consumer side. This component should return all results. |
||
| const handleAddressFound = sandbox.stub(); | ||
| const { findByText, findByLabelText } = render( | ||
| <AddressSearch onAddressFound={handleAddressFound} />, | ||
| ); | ||
|
|
||
| await userEvent.type( | ||
| await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'), | ||
| '200 main', | ||
| ); | ||
| await userEvent.click( | ||
| await findByText('in_person_proofing.body.location.po_search.search_button'), | ||
| ); | ||
|
|
||
| await expect(handleAddressFound).to.eventually.be.calledWith(DEFAULT_RESPONSE[0]); | ||
| }); | ||
|
|
||
| it('validates input and shows inline error', async () => { | ||
| const { findByText } = render(<AddressSearch />); | ||
|
|
||
| await userEvent.click( | ||
| await findByText('in_person_proofing.body.location.po_search.search_button'), | ||
| ); | ||
|
|
||
| await findByText('in_person_proofing.body.location.inline_error'); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.