-
Notifications
You must be signed in to change notification settings - Fork 166
LG-11082 - Add optional info alert to FullAddressSearch #9276
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
c733763
143e48c
3a9d8b4
8b41d67
b319b70
e3b75be
fd56d10
ca91397
7a39614
1c4a5ca
12c6057
131df3d
a9d4128
b939e8a
248751b
e183cf6
7de2c25
4b53875
e695888
66c08ce
d3f6b40
28d9a11
abc8ce7
f650012
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,64 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import sinon from 'sinon'; | ||
| import { useSandbox } from '@18f/identity-test-helpers'; | ||
| import { SWRConfig } from 'swr'; | ||
| import AddressSearch from './address-search'; | ||
|
|
||
| describe('AddressSearch', () => { | ||
| const sandbox = useSandbox(); | ||
| const locationsURL = 'https://localhost:3000/locations/endpoint'; | ||
|
|
||
| context('Page Heading and PO Search About Message', () => { | ||
| it('both render when handleLocationSelect is not null', async () => { | ||
| const handleLocationsFound = sandbox.stub(); | ||
| const onSelect = sinon.stub(); | ||
| const { queryByText, queryByRole } = render( | ||
| <SWRConfig value={{ provider: () => new Map() }}> | ||
| <AddressSearch | ||
| addressSearchURL="test" | ||
| disabled={false} | ||
| handleLocationSelect={onSelect} | ||
| locationsURL={locationsURL} | ||
| onFoundLocations={handleLocationsFound} | ||
| registerField={() => undefined} | ||
| /> | ||
| </SWRConfig>, | ||
| ); | ||
|
|
||
| const heading = await queryByText('in_person_proofing.headings.po_search.location'); | ||
| const aboutMessage = await queryByText( | ||
| 'in_person_proofing.body.location.po_search.po_search_about', | ||
| ); | ||
|
|
||
| expect(heading).to.exist(); | ||
| expect(aboutMessage).to.exist(); | ||
| expect( | ||
| queryByRole('heading', { name: 'in_person_proofing.headings.po_search.location' }), | ||
| ).to.exist(); | ||
| }); | ||
|
|
||
| it('both do not render when handleLocationSelect is null', async () => { | ||
| const handleLocationsFound = sandbox.stub(); | ||
| const onSelect = sinon.stub(); | ||
| const { queryByText } = render( | ||
| <SWRConfig value={{ provider: () => new Map() }}> | ||
| <AddressSearch | ||
| addressSearchURL="test" | ||
| disabled={false} | ||
| handleLocationSelect={onSelect} | ||
| locationsURL={locationsURL} | ||
| onFoundLocations={handleLocationsFound} | ||
| registerField={() => undefined} | ||
| /> | ||
| </SWRConfig>, | ||
| ); | ||
|
|
||
| const heading = await queryByText('in_person_proofing.headings.po_search.location'); | ||
| const aboutMessage = await queryByText( | ||
| 'in_person_proofing.body.location.po_search.po_search_about', | ||
| ); | ||
| expect(heading).to.be.empty; | ||
| expect(aboutMessage).to.be.empty; | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import sinon from 'sinon'; | ||
| import { useSandbox } from '@18f/identity-test-helpers'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { setupServer } from 'msw/node'; | ||
|
|
@@ -12,6 +13,59 @@ describe('FullAddressSearch', () => { | |
| const locationsURL = 'https://localhost:3000/locations/endpoint'; | ||
| const usStatesTerritories = [['Delware', 'DE']]; | ||
|
|
||
| context('Page Heading and PO Search About Message', () => { | ||
| it('both render when handleLocationSelect is not null', async () => { | ||
| const handleLocationsFound = sandbox.stub(); | ||
| const onSelect = sinon.stub(); | ||
| const { queryByText, queryByRole } = render( | ||
| <SWRConfig value={{ provider: () => new Map() }}> | ||
| <FullAddressSearch | ||
| usStatesTerritories={usStatesTerritories} | ||
| onFoundLocations={handleLocationsFound} | ||
| locationsURL={locationsURL} | ||
| registerField={() => undefined} | ||
| handleLocationSelect={onSelect} | ||
| disabled={false} | ||
| /> | ||
| </SWRConfig>, | ||
| ); | ||
|
|
||
| const heading = await queryByText('in_person_proofing.headings.po_search.location'); | ||
| const aboutMessage = await queryByText( | ||
| 'in_person_proofing.body.location.po_search.po_search_about', | ||
| ); | ||
|
|
||
| expect(heading).to.exist(); | ||
| expect(aboutMessage).to.exist(); | ||
| expect( | ||
| queryByRole('heading', { name: 'in_person_proofing.headings.po_search.location' }), | ||
| ).to.exist(); | ||
| }); | ||
|
|
||
| it('both do not render when handleLocationSelect is null', async () => { | ||
| const handleLocationsFound = sandbox.stub(); | ||
| const { queryByText } = render( | ||
| <SWRConfig value={{ provider: () => new Map() }}> | ||
| <FullAddressSearch | ||
| usStatesTerritories={usStatesTerritories} | ||
| onFoundLocations={handleLocationsFound} | ||
| locationsURL={locationsURL} | ||
| registerField={() => undefined} | ||
| handleLocationSelect={null} | ||
| disabled={false} | ||
| /> | ||
| </SWRConfig>, | ||
| ); | ||
|
|
||
| const heading = await queryByText('in_person_proofing.headings.po_search.location'); | ||
| const aboutMessage = await queryByText( | ||
| 'in_person_proofing.body.location.po_search.po_search_about', | ||
| ); | ||
| expect(heading).to.be.empty; | ||
| expect(aboutMessage).to.be.empty; | ||
| }); | ||
| }); | ||
|
|
||
| context('validates form', () => { | ||
| it('displays an error for all required fields when input is empty', async () => { | ||
| const handleLocationsFound = sandbox.stub(); | ||
|
|
@@ -21,9 +75,9 @@ describe('FullAddressSearch', () => { | |
| usStatesTerritories={usStatesTerritories} | ||
| onFoundLocations={handleLocationsFound} | ||
| locationsURL={locationsURL} | ||
|
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. I created interface FullAddressSearchProps and as a result had to update these tests to satisfy the data type- that is the reason for the following updates in this test file |
||
| registerField={undefined} | ||
| registerField={() => undefined} | ||
| handleLocationSelect={undefined} | ||
| disabled={undefined} | ||
| disabled={false} | ||
| /> | ||
| </SWRConfig>, | ||
| ); | ||
|
|
@@ -44,9 +98,9 @@ describe('FullAddressSearch', () => { | |
| usStatesTerritories={usStatesTerritories} | ||
| onFoundLocations={handleLocationsFound} | ||
| locationsURL={locationsURL} | ||
| registerField={undefined} | ||
| registerField={() => undefined} | ||
| handleLocationSelect={undefined} | ||
| disabled={undefined} | ||
| disabled={false} | ||
| /> | ||
| </SWRConfig>, | ||
| ); | ||
|
|
@@ -83,9 +137,9 @@ describe('FullAddressSearch', () => { | |
| usStatesTerritories={usStatesTerritories} | ||
| onFoundLocations={handleLocationsFound} | ||
| locationsURL={locationsURL} | ||
| registerField={undefined} | ||
| registerField={() => undefined} | ||
| handleLocationSelect={undefined} | ||
| disabled={undefined} | ||
| disabled={false} | ||
| /> | ||
| </SWRConfig>, | ||
| ); | ||
|
|
@@ -135,9 +189,9 @@ describe('FullAddressSearch', () => { | |
| usStatesTerritories={usStatesTerritories} | ||
| onFoundLocations={handleLocationsFound} | ||
| locationsURL={locationsURL} | ||
| registerField={undefined} | ||
| registerField={() => undefined} | ||
| handleLocationSelect={undefined} | ||
| disabled={undefined} | ||
| disabled={false} | ||
| /> | ||
| </SWRConfig>, | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,16 +4,18 @@ import { t } from '@18f/identity-i18n'; | |
| import { InPersonLocations, NoInPersonLocationsDisplay } from '@18f/identity-address-search'; | ||
| import type { LocationQuery, FormattedLocation } from '@18f/identity-address-search/types'; | ||
| import FullAddressSearchInput from './full-address-search-input'; | ||
| import type { FullAddressSearchProps } from '../types'; | ||
|
|
||
| function FullAddressSearch({ | ||
| usStatesTerritories, | ||
| registerField, | ||
| locationsURL, | ||
| handleLocationSelect, | ||
| disabled, | ||
| onFoundLocations, | ||
| handleLocationSelect, | ||
| locationsURL, | ||
| noInPersonLocationsDisplay = NoInPersonLocationsDisplay, | ||
| }) { | ||
| onFoundLocations, | ||
| registerField, | ||
| resultsHeaderComponent, | ||
| usStatesTerritories, | ||
| }: FullAddressSearchProps) { | ||
| const [apiError, setApiError] = useState<Error | null>(null); | ||
| const [foundAddress, setFoundAddress] = useState<LocationQuery | null>(null); | ||
| const [locationResults, setLocationResults] = useState<FormattedLocation[] | null | undefined>( | ||
|
|
@@ -28,8 +30,12 @@ function FullAddressSearch({ | |
| {t('idv.failure.exceptions.post_office_search_error')} | ||
| </Alert> | ||
| )} | ||
| <PageHeading>{t('in_person_proofing.headings.po_search.location')}</PageHeading> | ||
| <p>{t('in_person_proofing.body.location.po_search.po_search_about')}</p> | ||
| {handleLocationSelect && ( | ||
| <> | ||
| <PageHeading>{t('in_person_proofing.headings.po_search.location')}</PageHeading> | ||
| <p>{t('in_person_proofing.body.location.po_search.po_search_about')}</p> | ||
| </> | ||
| )} | ||
|
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. |
||
| <FullAddressSearchInput | ||
| usStatesTerritories={usStatesTerritories} | ||
| registerField={registerField} | ||
|
|
@@ -52,6 +58,7 @@ function FullAddressSearch({ | |
| onSelect={handleLocationSelect} | ||
| address={foundAddress.address || ''} | ||
| noInPersonLocationsDisplay={noInPersonLocationsDisplay} | ||
| resultsHeaderComponent={resultsHeaderComponent} | ||
| /> | ||
| )} | ||
| </> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { ComponentType } from 'react'; | ||
| import { t } from '@18f/identity-i18n'; | ||
| import LocationCollection from './location-collection'; | ||
| import LocationCollectionItem from './location-collection-item'; | ||
| import type { InPersonLocationsProps } from '../types'; | ||
|
|
||
| export interface FormattedLocation { | ||
| formattedCityStateZip: string; | ||
|
|
@@ -15,14 +15,6 @@ export interface FormattedLocation { | |
| isPilot: boolean; | ||
| } | ||
|
|
||
| interface InPersonLocationsProps { | ||
| locations: FormattedLocation[] | null | undefined; | ||
| onSelect; | ||
| address: string; | ||
| noInPersonLocationsDisplay: ComponentType<{ address: string }>; | ||
| resultsHeaderComponent?: ComponentType; | ||
| } | ||
|
|
||
|
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. Looks like we had the InPersonLocationsProps interface in both types.d and in in-person-locations.tsx. I deleted this one and updated the one in types.d to have the complete prop list. |
||
| function InPersonLocations({ | ||
| locations, | ||
| onSelect, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@18f/identity-address-search", | ||
| "version": "3.0.0", | ||
| "version": "3.1.0", | ||
| "type": "module", | ||
| "private": false, | ||
|
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. My changes should not be breaking so I went with a minor update. Please confirm you agree, not breaking. |
||
| "files": [ | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although we are not using AddressSearch at the moment, we will be. I wanted to update this component to have the same logic as FullAddressSearch so they behave similar. That will make switching over easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if this change was covered with a spec, but probably of limited value until we get this back into use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added tests around this show/hide logic with commit d3f6b40