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

Commit

Permalink
Fixes tests for new components
Browse files Browse the repository at this point in the history
  • Loading branch information
el-mapache committed Nov 6, 2018
1 parent 064a70e commit 75dc9f8
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 73 deletions.
11 changes: 10 additions & 1 deletion src/components/Form/Location/AlternateAddress.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux';
import { i18n } from '../../../config'
import Field from '../Field'
Expand All @@ -7,9 +8,16 @@ import Show from '../Show'
import Location from './Location'
import LocationValidator, { countryString } from '../../../validators/location'
import ValidationElement from '../ValidationElement'
import alternateAddress from '../../../schema/form/alternateAddress'
import alternateAddress from '../../../schema/form/alternateaddress'

const alternateAddressDefaultState = alternateAddress
const propTypes = {
address: PropTypes.object,
belongingTo: PropTypes.string,
country: PropTypes.string,
onUpdate: PropTypes.func
}


class AlternateAddress extends ValidationElement {
constructor(props) {
Expand Down Expand Up @@ -126,6 +134,7 @@ class AlternateAddress extends ValidationElement {
}
}

AlternateAddress.propTypes = propTypes
AlternateAddress.defaultProps = {
addressFieldMetadata: {
streetLabel: i18n.t('address.us.street.label'),
Expand Down
21 changes: 11 additions & 10 deletions src/components/Form/Location/AlternateAddress.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { mount } from 'enzyme'
import { fn } from 'jest'
import { AlternateAddress } from './AlternateAddress'
import { address } from '../../../config/locales/en/address'
import alternateAddress from '../../../schema/form/alternateaddress'

describe('<AlternateAddress />', () => {
describe('when a user indicates a foreign address', () => {
it('renders a Branch component', () => {
const props = {
country: '',
alternateAddress: {
address: {
HasDifferentAddress: '',
Address: { country: '' }
}
Expand All @@ -26,7 +27,7 @@ describe('<AlternateAddress />', () => {
const props = {
allowForeignMilitary: true,
country: '',
alternateAddress: {
address: {
HasDifferentAddress: { value: 'Yes' }
}
}
Expand All @@ -39,21 +40,21 @@ describe('<AlternateAddress />', () => {
it('passes the branch value to the branch', () => {
const props = {
country: '',
alternateAddress: {
address: {
HasDifferentAddress: { value: 'No' }
}
}
const component = mount(<AlternateAddress {...props} />)

expect(component.find('Branch').prop('value')).toEqual(props.alternateAddress.HasDifferentAddress.value)
expect(component.find('Branch').prop('value')).toEqual(props.address.HasDifferentAddress.value)
})

describe('when the user toggles to an APO address', () => {
it('toggles the secondary APO address form properly', () => {
const props = {
onUpdate: () => ({}),
country: 'Spain',
alternateAddress: {
address: {
HasDifferentAddress: { value: 'Yes' }
}
}
Expand All @@ -74,7 +75,7 @@ describe('<AlternateAddress />', () => {
it('renders the correct field label', () => {
const props = {
country: 'POSTOFFICE',
alternateAddress: {
address: {
HasDifferentAddress: { value: '' },
Address: {}
}
Expand All @@ -90,7 +91,7 @@ describe('<AlternateAddress />', () => {
const props = {
onUpdate: jest.fn(),
country: 'Germany',
alternateAddress: {
address: {
Address: {
country: 'POSTOFFICE',
state: 'AA'
Expand All @@ -100,7 +101,7 @@ describe('<AlternateAddress />', () => {
}

const component = mount(<AlternateAddress {...props} />)
expect(component.prop('alternateAddress').Address.country).toEqual(props.alternateAddress.Address.country);
expect(component.prop('address').Address.country).toEqual(props.address.Address.country);

component.setProps({ country: 'United States' })

Expand All @@ -115,7 +116,7 @@ describe('<AlternateAddress />', () => {
it('supplies the correct props to the Location component', () => {
const props = {
country: 'POSTOFFICE',
alternateAddress: {
address: {
Address: {
country: ''
},
Expand All @@ -127,7 +128,7 @@ describe('<AlternateAddress />', () => {

expect(location.prop('disableToggle')).toEqual(undefined);
expect(location.prop('geocode')).toEqual(true);
expect(location.prop('country')).toEqual(props.alternateAddress.Address.country)
expect(location.prop('country')).toEqual(props.address.Address.country)
})
})
})
18 changes: 9 additions & 9 deletions src/components/Form/Location/alternateAddressProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import React from 'react'
import AlternateAddress from './AlternateAddress'
import alternateAddress from '../../../schema/form/alternateAddress'

/**
* Becuase of the way the app is structured, this component
* MUST be passed an onUpdate function which conforms to the
* `update` function included in every component in this app
*
*/
import alternateAddress from '../../../schema/form/alternateaddress'

const alternateAddressProvider = (Component) => {
class AddressProvider extends React.Component {
Expand All @@ -17,12 +10,19 @@ const alternateAddressProvider = (Component) => {
this.renderAlternateAddress = this.renderAlternateAddress.bind(this)
}


/**
* Becuase of the way the app is structured, this component
* MUST be passed an `onUpdate` function in the extraProps obj that
* conforms to the `update` function included in every component in this app
*
*/
renderAlternateAddress(extraProps) {
return (
<AlternateAddress
{...extraProps}
addressBook={this.props.addressBook}
allowForeignMilitary
allowForeignMilitary={this.props.allowForeignMilitary}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ describe('.alternateAddressProvider', () => {
const mock = component.instance().renderAlternateAddress;
const expected = {
addressBook: 'Residence',
AlternateAddress: {
Address: {},
HasDifferentAddress: { value: '' }
},
allowForeignMilitary: true,
render: mock
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Section/History/Employment/EmploymentItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ export default class EmploymentItem extends ValidationElement {
</Field>

{ this.props.render({
address: this.props.ReferenceAlternateAddress,
belongingTo: 'ReferenceAddress',
country: this.props.ReferenceAddress.country,
onUpdate: this.update
})}
Expand Down
39 changes: 21 additions & 18 deletions src/components/Section/History/Employment/EmploymentItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ import EmploymentItem from './EmploymentItem'
import ReasonLeft from './ReasonLeft'
import Reprimand from './Reprimand'

const alternateAddressRenderMock = jest.fn();
const buildProps = other => ({ render: alternateAddressRenderMock, ...other})

describe('The employment component', () => {
it('no error on empty', () => {
const expected = {
const expected = buildProps({
name: 'employment'
}
})
const component = mount(<EmploymentItem {...expected} />)
expect(component.find('.h3').length).toBeGreaterThan(0)
})

it('can populate values for Military, NationalGuard and USPHS', () => {
let updates = 0
const expected = {
const expected = buildProps({
name: 'employment',
EmploymentActivity: { value: 'ActiveMilitary' },
onUpdate: () => {
updates++
}
}
})
const selectors = [
'.employment-title',
'.employment-duty-station',
Expand All @@ -47,7 +50,7 @@ describe('The employment component', () => {

it('display displinary when within 7 years', () => {
const sevenYearsAgo = daysAgo(today, 365 * 7)
const props = {
const props = buildProps({
EmploymentActivity: { value: 'ActiveMilitary' },
Dates: {
present: true,
Expand All @@ -58,14 +61,14 @@ describe('The employment component', () => {
},
to: {}
}
}
})
const component = mount(<EmploymentItem {...props} />)
expect(component.find('.reprimand-branch').length).toBe(1)
})

it('does not display disciplinary if not within 7 years', () => {
const past = daysAgo(today, 365 * 8)
const props = {
const props = buildProps({
EmploymentActivity: { value: 'ActiveMilitary' },
Dates: {
present: false,
Expand All @@ -76,14 +79,14 @@ describe('The employment component', () => {
},
to: {}
}
}
})
const component = mount(<EmploymentItem {...props} />)
expect(component.find('.reprimand-branch').length).toBe(0)
})

it('display reason left options when within 7 years', () => {
const sevenYearsAgo = daysAgo(today, 365 * 7)
const props = {
const props = buildProps({
EmploymentActivity: { value: 'ActiveMilitary' },
Dates: {
present: true,
Expand All @@ -94,14 +97,14 @@ describe('The employment component', () => {
},
to: {}
}
}
})
const component = mount(<EmploymentItem {...props} />)
expect(component.find('.reason-options').length).toBe(1)
})

it('does not display reason left options if not within 7 years', () => {
const past = daysAgo(today, 365 * 8)
const props = {
const props = buildProps({
EmploymentActivity: { value: 'ActiveMilitary' },
Dates: {
present: false,
Expand All @@ -112,14 +115,14 @@ describe('The employment component', () => {
},
to: {}
}
}
})
const component = mount(<EmploymentItem {...props} />)
expect(component.find('.reason-options').length).toBe(0)
})

it('does not display reason for leaving if currently employed', () => {
const past = daysAgo(today, 365 * 3)
const props = {
const props = buildProps({
EmploymentActivity: { value: 'ActiveMilitary' },
Dates: {
present: true,
Expand All @@ -130,7 +133,7 @@ describe('The employment component', () => {
},
to: {}
}
}
})
const component = mount(<EmploymentItem {...props} />)
expect(component.find('.reason-description').length).toBe(0)
})
Expand All @@ -140,7 +143,7 @@ describe('The employment component', () => {

beforeEach(() => {
const past = daysAgo(today, 365 * 3)
const props = {
const props = buildProps({
EmploymentActivity: { value: 'Unemployment' },
Dates: {
present: true,
Expand All @@ -151,7 +154,7 @@ describe('The employment component', () => {
},
to: {}
}
}
})
component = mount(<EmploymentItem {...props} />)
})

Expand All @@ -166,7 +169,7 @@ describe('The employment component', () => {

it('it does display reason for leaving', () => {
const past = daysAgo(today, 365 * 3)
const props = {
const props = buildProps({
EmploymentActivity: { value: 'ActiveMilitary' },
Dates: {
present: false,
Expand All @@ -177,7 +180,7 @@ describe('The employment component', () => {
},
to: {}
}
}
})
const component = mount(<EmploymentItem {...props} />)
expect(component.find('.reason-description').length).toBe(1)
})
Expand Down
27 changes: 7 additions & 20 deletions src/components/Section/History/Residence/ResidenceItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import configureMockStore from 'redux-mock-store'
import { Provider } from 'react-redux'
import ResidenceItem from './ResidenceItem'

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 {...props} />
<Component {...finalProps} />
</Provider>
)
}
Expand All @@ -18,7 +23,7 @@ describe('The residence component', () => {
const mockStore = configureMockStore()

it('renders without crashing', () => {
shallow(<ResidenceItem />)
shallow(<ResidenceItem render={alternateAddressRenderMock}/>)
})

it('no error on empty', () => {
Expand Down Expand Up @@ -77,28 +82,10 @@ describe('The residence component', () => {
expect(component.find('.role.hidden').length).toEqual(0)
})

describe('displaying a <PhysicalAddress/> component', () => {
it('supplies the physicalAddress prop to the <PhysicalAddress> component', () => {
const props = {
Address: {
country: 'POSTOFFICE'
},
AlternateAddress: {
HasDifferentAddress: { value: '' }
}
}

const component = mountComponent(mockStore, ResidenceItem, props);
expect(component.find('AlternateAddress').prop('alternateAddress')).toBeDefined();
})
})


it('performs updates for components', () => {
let updates = 0
const expected = {
name: 'residence',

Dates: {
from: {
day: '1',
Expand Down

0 comments on commit 75dc9f8

Please sign in to comment.