Skip to content
This repository has been archived by the owner on Sep 19, 2021. It is now read-only.

Commit

Permalink
Adds AlternateAddress to foreign contact
Browse files Browse the repository at this point in the history
  • Loading branch information
el-mapache committed Nov 13, 2018
1 parent 6ab4adc commit 04e9dc5
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/Form/Location/AlternateAddress.jsx
Expand Up @@ -101,7 +101,7 @@ class AlternateAddress extends ValidationElement {
render() {
return (
<div>
<Show when={this.props.forceAPO || (this.isForeignAddress() && this.props.allowForeignMilitary)}>
<Show when={this.props.forceAPO || this.isForeignAddress()}>
<Branch
label={this.props.militaryAddressLabel}
labelSize="h3"
Expand Down
5 changes: 4 additions & 1 deletion src/components/Section/Foreign/Contacts/Contacts.jsx
Expand Up @@ -10,6 +10,9 @@ import {
import SubsectionElement from '../../SubsectionElement'
import { Field, Branch, Show, Accordion } from '../../../Form'
import ForeignNational from './ForeignNational'
import alternateAddressProvider from '../../../Form/Location/alternateAddressProvider'

const ForeignNationalWithAlternateAddress = alternateAddressProvider(ForeignNational)

export default class Contacts extends SubsectionElement {
constructor(props) {
Expand Down Expand Up @@ -86,7 +89,7 @@ export default class Contacts extends SubsectionElement {
appendLabel={i18n.t('foreign.contacts.collection.append')}
required={this.props.required}
scrollIntoView={this.props.scrollIntoView}>
<ForeignNational
<ForeignNationalWithAlternateAddress
name="Item"
bind={true}
addressBooks={this.props.addressBooks}
Expand Down
23 changes: 21 additions & 2 deletions src/components/Section/Foreign/Contacts/Contacts.test.jsx
@@ -1,24 +1,43 @@
import React from 'react'
import { mount } from 'enzyme'
import configureMockStore from 'redux-mock-store'
import { Provider } from 'react-redux'
import Contacts from './Contacts'

const alternateAddressRenderMock = jest.fn();
const mountComponent = (mockStore, Component, props) => {
const store = mockStore({ application: { AddressBooks: {} }})
const finalProps = {
render: alternateAddressRenderMock,
...props
}

return mount(
<Provider store={store}>
<Component {...finalProps} />
</Provider>
)
}

describe('The contacts component', () => {
it('display nothing when "no" is clicked', () => {
const mockStore = configureMockStore()
const expected = {
name: 'foreign-contacts',
HasForeignContacts: { value: 'No' }
}
const component = mount(<Contacts {...expected} />)
const component = mountComponent(mockStore, Contacts, expected)
expect(component.find('.accordion').length).toBe(0)
})

it('display accordion when "yes" is clicked', () => {
const mockStore = configureMockStore()
const expected = {
name: 'foreign-contacts',
HasForeignContacts: { value: 'Yes' },
List: { branch: {}, items: [{ Item: { Name: {} } }] }
}
const component = mount(<Contacts {...expected} />)
const component = mountComponent(mockStore, Contacts, expected)
expect(component.find('.accordion').length).toBe(1)
})
})
13 changes: 11 additions & 2 deletions src/components/Section/Foreign/Contacts/ForeignNational.jsx
Expand Up @@ -670,10 +670,9 @@ export default class ForeignNational extends ValidationElement {
className="current-address"
{...this.props.Address}
layout={Location.ADDRESS}
geocode={true}
geocode
addressBooks={this.props.addressBooks}
addressBook="ForeignNational"
showPostOffice={true}
dispatch={this.props.dispatch}
onUpdate={this.updateAddress}
onError={this.props.onError}
Expand All @@ -682,6 +681,16 @@ export default class ForeignNational extends ValidationElement {
</NotApplicable>
</Field>

{this.props.render({
address: this.props.AlternateAddress,
addressBook: 'ForeignNational',
belongingTo: 'AlternateAddress',
country: this.props.Address.country,
forceAPO: true,
militaryAddressLabel: i18n.t('address.militaryAddress.other'),
onUpdate: this.update
})}

<Field
title={i18n.t('foreign.contacts.heading.employer')}
scrollIntoView={this.props.scrollIntoView}>
Expand Down
Expand Up @@ -2,9 +2,12 @@ import React from 'react'
import { mount } from 'enzyme'
import ForeignNational from './ForeignNational'

const renderMock = jest.fn()

describe('The foreign national component', () => {
it('display explanation if we do not know the name', () => {
const expected = {
render: renderMock,
name: 'foreign-national',
NameNotApplicable: { applicable: false }
}
Expand All @@ -14,6 +17,7 @@ describe('The foreign national component', () => {

it('display explanation if we have methods of "other"', () => {
const expected = {
render: renderMock,
name: 'foreign-national',
Methods: { values: ['Other'] }
}
Expand All @@ -23,6 +27,7 @@ describe('The foreign national component', () => {

it('display explanation if we have frequency of "other"', () => {
const expected = {
render: renderMock,
name: 'foreign-national',
Frequency: { value: 'Other' }
}
Expand All @@ -32,6 +37,7 @@ describe('The foreign national component', () => {

it('display explanation if we have relation of "other"', () => {
const expected = {
render: renderMock,
name: 'foreign-national',
Relationship: { values: ['Other'] }
}
Expand All @@ -43,6 +49,7 @@ describe('The foreign national component', () => {

it('display explanation if we have relation of "obligation"', () => {
const expected = {
render: renderMock,
name: 'foreign-national',
Relationship: { values: ['Obligation'] }
}
Expand All @@ -52,6 +59,7 @@ describe('The foreign national component', () => {

it('display affiliations if said to have some', () => {
const expected = {
render: renderMock,
name: 'foreign-national',
HasAffiliations: { value: 'Yes' }
}
Expand All @@ -62,6 +70,7 @@ describe('The foreign national component', () => {
it('trigger updates', () => {
let updates = 0
const expected = {
render: renderMock,
name: 'foreign-national',
NameNotApplicable: { applicable: false },
Methods: { values: ['Other'] },
Expand Down
3 changes: 2 additions & 1 deletion src/components/Section/Military/Foreign/ForeignContact.jsx
Expand Up @@ -89,7 +89,8 @@ export default class ForeignContact extends React.Component {
addressBook="ForeignNational"
dispatch={this.props.dispatch}
layout={Location.ADDRESS}
geocode={true}
geocode
showPostOffice={false}
onUpdate={this.updateAddress}
onError={this.props.onError}
required={this.props.required}
Expand Down
14 changes: 14 additions & 0 deletions src/components/Section/Relationships/Relatives/Relative.test.jsx
Expand Up @@ -6,6 +6,7 @@ import Location from '../../../Form/Location'
describe('The relative component', () => {
it('no error on empty', () => {
const expected = {
render: jest.fn(),
name: 'relative'
}

Expand Down Expand Up @@ -47,6 +48,7 @@ describe('The relative component', () => {

it('display maiden name if relationship is mother', () => {
const expected = {
render: jest.fn(),
name: 'relative',
Relation: { value: 'Mother' },
MaidenSameAsListed: { value: 'No' }
Expand All @@ -60,6 +62,7 @@ describe('The relative component', () => {

it('display items specific to immediate relationships', () => {
const expected = {
render: jest.fn(),
name: 'relative',
Relation: { value: 'Father' }
}
Expand All @@ -70,6 +73,7 @@ describe('The relative component', () => {

it('display address if not deceased', () => {
const expected = {
render: jest.fn(),
name: 'relative',
IsDeceased: { value: 'No' }
}
Expand All @@ -85,6 +89,7 @@ describe('The relative component', () => {
onUpdate: () => {
updates++
},
render: jest.fn(),
name: 'relative',
Citizenship: { value: ['United States'] },
CitizenshipDocumentation: { value: 'Other' },
Expand All @@ -111,6 +116,7 @@ describe('The relative component', () => {

it('display items if not deceased and not a citizen but lives in the U.S.', () => {
const expected = {
render: jest.fn(),
name: 'relative',
Citizenship: {
value: ['Germany']
Expand All @@ -135,6 +141,7 @@ describe('The relative component', () => {

it('display items if not deceased and not a citizen and lives abroad', () => {
const expected = {
render: jest.fn(),
name: 'relative',
Citizenship: {
value: ['Germany']
Expand All @@ -159,6 +166,7 @@ describe('The relative component', () => {

it('display employer relationship if affiliated', () => {
const expected = {
render: jest.fn(),
name: 'relative',
Citizenship: {
value: ['Germany']
Expand All @@ -184,6 +192,7 @@ describe('The relative component', () => {
it('initial questions presented', () => {
let updates = 0
const expected = {
render: jest.fn(),
name: 'relative',
Relation: { value: 'Mother' },
Birthplace: { country: { value: 'Germany' } },
Expand Down Expand Up @@ -220,6 +229,7 @@ describe('The relative component', () => {
it('are you my mother?', () => {
let updates = 0
const expected = {
render: jest.fn(),
name: 'relative',
Relation: { value: 'Mother' },
Name: {
Expand Down Expand Up @@ -265,6 +275,7 @@ describe('The relative component', () => {
it('is immediate relationships?', () => {
let updates = 0
const expected = {
render: jest.fn(),
name: 'relative',
Relation: { value: 'Mother' },
Name: {
Expand Down Expand Up @@ -328,6 +339,7 @@ describe('The relative component', () => {
it('is a citizen but lives abroad?', () => {
let updates = 0
const expected = {
render: jest.fn(),
name: 'relative',
Relation: { value: 'Mother' },
Name: {
Expand Down Expand Up @@ -384,6 +396,7 @@ describe('The relative component', () => {
it('is not a citizen but lives in the United States?', () => {
let updates = 0
const expected = {
render: jest.fn(),
name: 'relative',
Relation: { value: 'Mother' },
Name: {
Expand Down Expand Up @@ -453,6 +466,7 @@ describe('The relative component', () => {
it('is not a citizen and lives outside the United States?', () => {
let updates = 0
const expected = {
render: jest.fn(),
name: 'relative',
Relation: { value: 'Mother' },
Name: {
Expand Down
1 change: 1 addition & 0 deletions src/schema/section/foreign-contacts.js
Expand Up @@ -37,6 +37,7 @@ export const foreignContacts = (data = {}) => {
xitem.BirthplaceNotApplicable
),
Address: form.location(xitem.Address),
AlternateAddress: form.physicaladdress(xitem.AlternateAddress),
AddressNotApplicable: form.notapplicable(xitem.AddressNotApplicable),
Employer: form.text(xitem.Employer),
EmployerNotApplicable: form.notapplicable(xitem.EmployerNotApplicable),
Expand Down
2 changes: 2 additions & 0 deletions src/schema/section/foreign-contacts.test.js
@@ -1,5 +1,6 @@
import { unschema } from '../schema'
import { foreignContacts } from './foreign-contacts'
import alternateAddress from '../form/alternateaddress'

describe('Schema for financial taxes', () => {
it('can wrap in schema', () => {
Expand Down Expand Up @@ -42,6 +43,7 @@ describe('Schema for financial taxes', () => {
Address: {
country: null
},
AlternateAddress: alternateAddress(),
AddressNotApplicable: {},
Employer: {},
EmployerNotApplicable: {},
Expand Down
4 changes: 2 additions & 2 deletions src/schema/section/relationships-relatives.test.js
@@ -1,6 +1,6 @@
import { unschema } from '../schema'
import { relationshipsRelatives } from './relationships-relatives'
import { alternateaddress } from '../form';
import alternateAddress from '../form/alternateaddress'

describe('Schema for financial taxes', () => {
it('can wrap in schema', () => {
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('Schema for financial taxes', () => {
},
HasAffiliation: {},
EmployerRelationship: {},
AlternateAddress: alternateaddress()
AlternateAddress: alternateAddress()
}
}
]
Expand Down

0 comments on commit 04e9dc5

Please sign in to comment.