This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathPreSubmitInfo2.unit.spec.jsx
More file actions
194 lines (176 loc) · 6.05 KB
/
PreSubmitInfo2.unit.spec.jsx
File metadata and controls
194 lines (176 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import React from 'react';
import { expect } from 'chai';
import sinon from 'sinon';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { PreSubmitInfo2 } from '../../../components/PreSubmitInfo2';
describe('COE PreSubmitInfo2', () => {
it('renders a va-statement-of-truth with the expected heading and input label', () => {
const { container } = render(
<PreSubmitInfo2
formData={{}}
showError={false}
onSectionComplete={() => {}}
/>,
);
const sot = container.querySelector('va-statement-of-truth');
expect(sot).to.exist;
expect(sot.getAttribute('heading')).to.equal('Certification and Signature');
expect(sot.getAttribute('input-label')).to.equal('Your full name');
});
it('renders the statement of truth body text', () => {
const { container } = render(
<PreSubmitInfo2
formData={{}}
showError={false}
onSectionComplete={() => {}}
/>,
);
expect(container.textContent).to.include(
'I confirm that the identifying information in this form is accurate',
);
});
it('does not show input or checkbox errors on initial render', () => {
const { container } = render(
<PreSubmitInfo2
formData={{}}
showError={false}
onSectionComplete={() => {}}
/>,
);
const sot = container.querySelector('va-statement-of-truth');
expect(sot.getAttribute('input-error')).to.be.null;
expect(sot.getAttribute('checkbox-error')).to.be.null;
});
it('calls onSectionComplete with the checkbox value when the checkbox changes', async () => {
const onSectionComplete = sinon.spy();
const { container } = render(
<PreSubmitInfo2
formData={{}}
showError={false}
onSectionComplete={onSectionComplete}
/>,
);
const sot = container.querySelector('va-statement-of-truth');
fireEvent(
sot,
new CustomEvent('vaCheckboxChange', { detail: { checked: true } }),
);
await waitFor(() => {
expect(onSectionComplete.calledOnce).to.be.true;
expect(onSectionComplete.firstCall.args[0]).to.be.true;
});
});
it('shows a checkbox error when showError is true and the box is unchecked', async () => {
const { container } = render(
<PreSubmitInfo2 formData={{}} showError onSectionComplete={() => {}} />,
);
await waitFor(() => {
const sot = container.querySelector('va-statement-of-truth');
expect(sot.getAttribute('checkbox-error')).to.equal(
'You must certify by checking the box',
);
});
});
it('clears the checkbox error after the box is checked', async () => {
const { container } = render(
<PreSubmitInfo2 formData={{}} showError onSectionComplete={() => {}} />,
);
const sot = container.querySelector('va-statement-of-truth');
fireEvent(
sot,
new CustomEvent('vaCheckboxChange', { detail: { checked: true } }),
);
await waitFor(() => {
expect(sot.getAttribute('checkbox-error')).to.be.null;
});
});
it('shows a signature mismatch error after blur when the signature does not match the expected name', async () => {
const { container } = render(
<PreSubmitInfo2
formData={{ fullName: { first: 'John', last: 'Doe' } }}
showError={false}
onSectionComplete={() => {}}
/>,
);
const sot = container.querySelector('va-statement-of-truth');
fireEvent(
sot,
new CustomEvent('vaInputChange', { detail: { value: 'Wrong Name' } }),
);
fireEvent(sot, new CustomEvent('vaInputBlur'));
await waitFor(() => {
const inputError = sot.getAttribute('input-error');
expect(inputError).to.include('John Doe');
expect(inputError).to.include(
'Please enter your name exactly as it appears on your application',
);
});
});
it('does not show a mismatch error before blur even when the signature is wrong', async () => {
const { container } = render(
<PreSubmitInfo2
formData={{}}
showError={false}
onSectionComplete={() => {}}
/>,
);
const sot = container.querySelector('va-statement-of-truth');
fireEvent(
sot,
new CustomEvent('vaInputChange', { detail: { value: 'Wrong Name' } }),
);
await waitFor(() => {
expect(sot.getAttribute('input-value')).to.equal('Wrong Name');
});
expect(sot.getAttribute('input-error')).to.be.null;
});
it('does not show a mismatch error when the signature matches the expected name (case/whitespace insensitive)', async () => {
const { container } = render(
<PreSubmitInfo2
formData={{ fullName: { first: 'John', last: 'Doe' } }}
showError
onSectionComplete={() => {}}
/>,
);
const sot = container.querySelector('va-statement-of-truth');
fireEvent(
sot,
new CustomEvent('vaInputChange', { detail: { value: 'john doe' } }),
);
fireEvent(sot, new CustomEvent('vaInputBlur'));
await waitFor(() => {
expect(sot.getAttribute('input-value')).to.equal('john doe');
});
expect(sot.getAttribute('input-error')).to.be.null;
});
it('shows a mismatch error when showError is true even if the input has not been blurred', async () => {
const { container } = render(
<PreSubmitInfo2
formData={{ fullName: { first: 'John', last: 'Doe' } }}
showError
onSectionComplete={() => {}}
/>,
);
const sot = container.querySelector('va-statement-of-truth');
await waitFor(() => {
expect(sot.getAttribute('input-error')).to.include('John Doe');
});
});
it('updates input-value as the user types', async () => {
const { container } = render(
<PreSubmitInfo2
formData={{}}
showError={false}
onSectionComplete={() => {}}
/>,
);
const sot = container.querySelector('va-statement-of-truth');
fireEvent(
sot,
new CustomEvent('vaInputChange', { detail: { value: 'John Doe' } }),
);
await waitFor(() => {
expect(sot.getAttribute('input-value')).to.equal('John Doe');
});
});
});