-
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.
Implement new confirmation page on form 21P-0847 (#33658)
- Loading branch information
1 parent
7f33ff0
commit 5e412c8
Showing
2 changed files
with
119 additions
and
56 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
120 changes: 90 additions & 30 deletions
120
src/applications/simple-forms/21P-0847/tests/containers/ConfirmationPage.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 |
---|---|---|
@@ -1,45 +1,105 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { render } from '@testing-library/react'; | ||
import configureStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
|
||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { createStore } from 'redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { Provider } from 'react-redux'; | ||
import { cleanup } from '@testing-library/react'; | ||
import { format } from 'date-fns'; | ||
import { createInitialState } from '@department-of-veterans-affairs/platform-forms-system/state/helpers'; | ||
import formConfig from '../../config/form'; | ||
import ConfirmationPage from '../../containers/ConfirmationPage'; | ||
import testData from '../e2e/fixtures/data/maximal-test.json'; | ||
|
||
const storeBase = { | ||
form: { | ||
formId: formConfig.formId, | ||
submission: { | ||
response: { | ||
confirmationNumber: '123456', | ||
describe('ConfirmationPage', () => { | ||
let wrapper; | ||
let store; | ||
const mockStore = configureMockStore(); | ||
const initialState = { | ||
form: { | ||
data: { | ||
...createInitialState(formConfig), | ||
...testData.data, | ||
}, | ||
timestamp: Date.now(), | ||
}, | ||
data: { | ||
preparerName: { | ||
first: 'Jack', | ||
middle: 'W', | ||
last: 'Witness', | ||
submission: { | ||
response: { | ||
confirmationNumber: '1234567890', | ||
}, | ||
timestamp: '2022-01-01T00:00:00Z', | ||
}, | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
describe('Confirmation page', () => { | ||
const middleware = [thunk]; | ||
const mockStore = configureStore(middleware); | ||
beforeEach(() => { | ||
store = mockStore(initialState); | ||
wrapper = mount( | ||
<Provider store={store}> | ||
<ConfirmationPage route={{ formConfig }} /> | ||
</Provider>, | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
} | ||
cleanup(); | ||
}); | ||
|
||
it('it should show status success and the correct name of person', () => { | ||
const { container, getByText } = render( | ||
<Provider store={mockStore(storeBase)}> | ||
<ConfirmationPage /> | ||
it('passes the correct props to ConfirmationPageView', () => { | ||
const confirmationViewProps = wrapper.find('ConfirmationView').props(); | ||
|
||
expect(confirmationViewProps.submitDate).to.equal('2022-01-01T00:00:00Z'); | ||
expect(confirmationViewProps.confirmationNumber).to.equal('1234567890'); | ||
}); | ||
|
||
it('should select form from state when state.form is defined', () => { | ||
const submitDate = new Date(); | ||
const mockInitialState = { | ||
form: { | ||
submission: { | ||
timestamp: submitDate, | ||
response: { confirmationNumber: '1234' }, | ||
}, | ||
data: { | ||
...createInitialState(formConfig), | ||
...testData.data, | ||
}, | ||
}, | ||
}; | ||
const mockDefinedState = createStore(() => mockInitialState); | ||
|
||
const definedWrapper = mount( | ||
<Provider store={mockDefinedState}> | ||
<ConfirmationPage route={{ formConfig }} /> | ||
</Provider>, | ||
); | ||
expect(container.querySelector('va-alert')).to.have.attr( | ||
'status', | ||
'success', | ||
|
||
expect(definedWrapper.text()).to.include( | ||
format(submitDate, 'MMMM d, yyyy'), | ||
); | ||
getByText(/Jack W Witness/); | ||
expect(definedWrapper.text()).to.include('1234'); | ||
|
||
definedWrapper.unmount(); | ||
}); | ||
|
||
it('should throw error when state.form is undefined', () => { | ||
const mockEmptyState = {}; | ||
const mockEmptyStore = createStore(() => mockEmptyState); | ||
|
||
let errorWrapper; | ||
|
||
expect(() => { | ||
errorWrapper = mount( | ||
<Provider store={mockEmptyStore}> | ||
<ConfirmationPage route={{ formConfig }} /> | ||
</Provider>, | ||
); | ||
}).to.throw(); | ||
|
||
if (errorWrapper) { | ||
errorWrapper.unmount(); | ||
} | ||
}); | ||
}); |