-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[92622] Add presubmit unit tests (#33500)
* add presubmit unit tests * update descriptions
- Loading branch information
Showing
2 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
src/applications/representative-appoint/tests/containers/PreSubmitInfo.unit.spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { expect } from 'chai'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import sinon from 'sinon'; | ||
import { $ } from 'platform/forms-system/src/js/utilities/ui'; | ||
import PreSubmitInfo from '../../containers/PreSubmitInfo'; | ||
import repResults from '../fixtures/data/representative-results.json'; | ||
|
||
describe('<PreSubmitInfo>', () => { | ||
const getProps = ({ | ||
showError = false, | ||
status = 'applicationSubmitted', | ||
} = {}) => { | ||
return { | ||
props: { | ||
formData: { | ||
veteranFullName: { | ||
first: 'John', | ||
middle: 'Edmund', | ||
last: 'Doe', | ||
suffix: 'Sr.', | ||
}, | ||
selectedAccreditedOrganizationName: 'American Legion', | ||
'view:applicantIsVeteran': 'Yes', | ||
'view:selectedRepresentative': repResults[0].data, | ||
}, | ||
showError, | ||
onSectionComplete: sinon.spy(), | ||
formSubmission: { status }, | ||
}, | ||
mockStore: { | ||
getState: () => ({ | ||
form: { | ||
submission: { status }, | ||
}, | ||
}), | ||
subscribe: () => {}, | ||
dispatch: () => ({}), | ||
}, | ||
}; | ||
}; | ||
|
||
const renderContainer = (props, mockStore) => { | ||
return render( | ||
<Provider store={mockStore}> | ||
<PreSubmitInfo {...props} /> | ||
</Provider>, | ||
); | ||
}; | ||
|
||
it('should render component', () => { | ||
const { props, mockStore } = getProps(); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
|
||
expect(container).to.exist; | ||
}); | ||
|
||
it('should include the applicant name', () => { | ||
const { props, mockStore } = getProps(); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
const content = $('va-accordion-item', container); | ||
|
||
expect(content.textContent).to.contain('John Edmund Doe Sr.'); | ||
}); | ||
|
||
it('should include the representative name', () => { | ||
const { props, mockStore } = getProps(); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
const content = $('va-accordion-item', container); | ||
|
||
expect(content.textContent).to.contain('American Legion'); | ||
}); | ||
|
||
context('when terms and conditions and form replacement are accepted', () => { | ||
it('calls onSectionComplete with true', async () => { | ||
const { props, mockStore } = getProps({ status: null }); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
|
||
const tcBox = container.querySelector( | ||
'[data-testid="terms-and-conditions"]', | ||
); | ||
|
||
tcBox.__events.vaChange({ | ||
detail: { checked: true }, | ||
}); | ||
|
||
const frBox = container.querySelector('[data-testid="form-replacement"]'); | ||
|
||
frBox.__events.vaChange({ | ||
detail: { checked: true }, | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(props.onSectionComplete.calledWith(true)).to.be.true; | ||
}); | ||
}); | ||
}); | ||
|
||
context('when only terms and conditions is accepted', () => { | ||
it('calls onSectionComplete with false', async () => { | ||
const { props, mockStore } = getProps({ status: null }); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
|
||
const tcBox = container.querySelector( | ||
'[data-testid="terms-and-conditions"]', | ||
); | ||
|
||
tcBox.__events.vaChange({ | ||
detail: { checked: true }, | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(props.onSectionComplete.calledWith(false)).to.be.true; | ||
}); | ||
}); | ||
|
||
it('shows an error message for form replacement', async () => { | ||
const { props, mockStore } = getProps({ showError: true, status: null }); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
|
||
const tcBox = container.querySelector( | ||
'[data-testid="terms-and-conditions"]', | ||
); | ||
|
||
tcBox.__events.vaChange({ | ||
detail: { checked: true }, | ||
}); | ||
|
||
const frBox = container.querySelector('[data-testid="form-replacement"]'); | ||
|
||
await waitFor(() => { | ||
expect(frBox).to.have.attr('error', 'This field is mandatory'); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when only form replacement is accepted', () => { | ||
it('calls onSectionComplete with false', async () => { | ||
const { props, mockStore } = getProps({ status: null }); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
|
||
const frBox = container.querySelector('[data-testid="form-replacement"]'); | ||
|
||
frBox.__events.vaChange({ | ||
detail: { checked: true }, | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(props.onSectionComplete.calledWith(false)).to.be.true; | ||
}); | ||
}); | ||
|
||
it('shows an error message for terms and conditions ', async () => { | ||
const { props, mockStore } = getProps({ showError: true, status: null }); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
|
||
const frBox = container.querySelector('[data-testid="form-replacement"]'); | ||
|
||
frBox.__events.vaChange({ | ||
detail: { checked: true }, | ||
}); | ||
|
||
const tcBox = container.querySelector( | ||
'[data-testid="terms-and-conditions"]', | ||
); | ||
|
||
await waitFor(() => { | ||
expect(tcBox).to.have.attr('error', 'This field is mandatory'); | ||
}); | ||
}); | ||
}); | ||
|
||
context('submission pending', () => { | ||
it('displays the loading message', () => { | ||
const { props, mockStore } = getProps({ status: 'submitPending' }); | ||
|
||
const { container } = renderContainer(props, mockStore); | ||
|
||
expect( | ||
$('va-loading-indicator', container).getAttribute('message'), | ||
).to.contain('We’re processing your form'); | ||
}); | ||
}); | ||
}); |