-
Notifications
You must be signed in to change notification settings - Fork 126
/
RatingLists.unit.spec.jsx
170 lines (145 loc) · 5.47 KB
/
RatingLists.unit.spec.jsx
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
import React from 'react';
import { render } from '@testing-library/react';
import { expect } from 'chai';
import {
$,
$$,
} from '@department-of-veterans-affairs/platform-forms-system/ui';
import RatingLists, { helpers } from '../../../components/RatingLists';
const nonServiceConnectedSectionTitle =
'Conditions VA determined aren’t service-connected';
const serviceConnectedSectionTitle = 'Service-connected ratings';
// The possible decision values that we can get from vets-api currently are:
// 1151 Denied, 1151 Granted, Not Service Connected, and Service Connected
const ratings = [
{
decision: 'Service Connected',
diagnosticText: 'Hearing Loss',
diagnosticTypeName: '6100-Hearing loss',
effectiveDate: '2005-01-01',
ratingPercentage: 20,
},
{
decision: 'Service Connected',
diagnosticText: 'Allergies due to Hearing Loss',
diagnosticTypeName: 'Limitation of flexion, knee',
effectiveDate: '2012-05-01',
ratingPercentage: 100,
},
{
decision: '1151 Granted',
diagnosticText: 'Sarcoma Soft-Tissue',
diagnosticTypeName: 'Soft tissue sarcoma (neurogenic origin)',
effectiveDate: '2018-08-01',
ratingPercentage: 80,
},
{
decision: 'Not Service Connected',
diagnosticText: 'Tinnitus',
diagnosticTypeName: 'Tinnitus',
effectiveDate: null,
ratingPercentage: null,
},
{
decision: '1151 Denied',
diagnosticText: 'Diabetes',
diagnosticTypeName: 'Diabetes mellitus',
effectiveDate: null,
ratingPercentage: null,
},
];
const serviceConnectedRatingsOnly = ratings.slice(0, 3);
const nonServiceConnectedRatingsOnly = ratings.slice(3);
describe('<RatingLists>', () => {
context('when there are no ratings', () => {
it('should display an alert indicating that there are no ratings', () => {
const screen = render(<RatingLists ratings={[]} />);
expect(
screen.getByText(
'We don’t have any rated disabilities on file for you',
),
).to.exist;
});
});
context(
'when there are a mix of service-connected and non-service-connected ratings',
() => {
it('should display both sections', () => {
const screen = render(<RatingLists ratings={ratings} />);
expect(screen.getByText(serviceConnectedSectionTitle)).to.exist;
expect(screen.getByText(nonServiceConnectedSectionTitle)).to.exist;
});
it('should display a total of five ratings', () => {
const screen = render(<RatingLists ratings={ratings} />);
const cards = screen.getAllByRole('heading', { level: 4 });
expect(cards.length).to.equal(5);
});
it('should sort service-connected ratings by effective date (most to least recent)', () => {
const { container } = render(<RatingLists ratings={ratings} />);
// Get the first rating list (Service connected ratings) and check
// that the cards is sorted correctly by evaluating the order of the card headings
const list = $$('.rating-list', container)[0];
const listItems = $$('h4', list);
expect(listItems[0].textContent).to.equal(
helpers.getHeadingText(ratings[2]),
);
expect(listItems[1].textContent).to.equal(
helpers.getHeadingText(ratings[1]),
);
expect(listItems[2].textContent).to.equal(
helpers.getHeadingText(ratings[0]),
);
});
},
);
context('when there are only service-connected ratings', () => {
it('should only display the service-connected ratings section', () => {
const screen = render(
<RatingLists ratings={serviceConnectedRatingsOnly} />,
);
expect(screen.getByText(serviceConnectedSectionTitle)).to.exist;
expect(screen.queryByText(nonServiceConnectedSectionTitle)).not.to.exist;
});
it('should display a total of three ratings', () => {
const screen = render(
<RatingLists ratings={serviceConnectedRatingsOnly} />,
);
const cards = screen.getAllByRole('heading', { level: 4 });
expect(cards.length).to.equal(3);
});
it('should sort service-connected ratings by effective date (most to least recent)', () => {
const { container } = render(
<RatingLists ratings={serviceConnectedRatingsOnly} />,
);
// Get the rating list (Service connected ratings) and check
// that the cards is sorted correctly by evaluating the order of the card headings
const list = $('.rating-list', container);
const listItems = $$('h4', list);
expect(listItems[0].textContent).to.equal(
helpers.getHeadingText(ratings[2]),
);
expect(listItems[1].textContent).to.equal(
helpers.getHeadingText(ratings[1]),
);
expect(listItems[2].textContent).to.equal(
helpers.getHeadingText(ratings[0]),
);
});
});
context('when there are only non-service-connected ratings', () => {
it('should only display the non-service-connected ratings section', () => {
const screen = render(
<RatingLists ratings={nonServiceConnectedRatingsOnly} />,
);
expect(screen.queryByText(serviceConnectedSectionTitle)).not.to.exist;
expect(screen.getByText(nonServiceConnectedSectionTitle)).to.exist;
});
it('should display a total of two ratings', () => {
const screen = render(
<RatingLists ratings={nonServiceConnectedRatingsOnly} />,
);
const cards = screen.getAllByRole('heading', { level: 4 });
expect(cards.length).to.equal(2);
});
});
});