|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 | 15 | import React from 'react';
|
16 |
| -import { shallow } from 'enzyme'; |
17 |
| - |
| 16 | +import { render, screen, within } from '@testing-library/react'; |
| 17 | +import '@testing-library/jest-dom'; |
18 | 18 | import MetricCard from './MetricCard';
|
19 | 19 |
|
20 | 20 | describe('MetricCard', () => {
|
@@ -63,42 +63,27 @@ describe('MetricCard', () => {
|
63 | 63 | ];
|
64 | 64 |
|
65 | 65 | it('renders as expected without details', () => {
|
66 |
| - expect(shallow(<MetricCard metric={metric} />)).toMatchSnapshot(); |
67 |
| - expect( |
68 |
| - shallow( |
69 |
| - <MetricCard |
70 |
| - metric={{ |
71 |
| - ...metric, |
72 |
| - details: details.slice(0, 2), |
73 |
| - }} |
74 |
| - /> |
75 |
| - ) |
76 |
| - ).toMatchSnapshot(); |
| 66 | + const { container } = render(<MetricCard metric={metric} />); |
| 67 | + expect(screen.getByText('Metric Name')).toBeInTheDocument(); |
| 68 | + expect(screen.getByText('Metric Description')).toBeInTheDocument(); |
| 69 | + expect(container.querySelector('.MetricCard--Details')).not.toBeInTheDocument(); |
77 | 70 | });
|
78 | 71 |
|
79 | 72 | it('renders as expected with details', () => {
|
80 |
| - expect( |
81 |
| - shallow( |
82 |
| - <MetricCard |
83 |
| - metric={{ |
84 |
| - ...metric, |
85 |
| - details, |
86 |
| - }} |
87 |
| - /> |
88 |
| - ) |
89 |
| - ).toMatchSnapshot(); |
| 73 | + render(<MetricCard metric={{ ...metric, details }} />); |
| 74 | + expect(screen.getByText(metric.name)).toBeInTheDocument(); |
| 75 | + expect(screen.getByText(metric.description)).toBeInTheDocument(); |
| 76 | + details.forEach(detail => { |
| 77 | + if (detail.rows && detail.rows.length) { |
| 78 | + expect(screen.getByText(detail.description)).toBeInTheDocument(); |
| 79 | + } |
| 80 | + }); |
90 | 81 | });
|
91 | 82 |
|
92 | 83 | it('renders as expected when passCount is zero', () => {
|
93 |
| - expect( |
94 |
| - shallow( |
95 |
| - <MetricCard |
96 |
| - metric={{ |
97 |
| - ...metric, |
98 |
| - passCount: 0, |
99 |
| - }} |
100 |
| - /> |
101 |
| - ) |
102 |
| - ).toMatchSnapshot(); |
| 84 | + render(<MetricCard metric={{ ...metric, passCount: 0 }} />); |
| 85 | + expect(screen.getByText('Metric Name')).toBeInTheDocument(); |
| 86 | + expect(screen.getByText('0.0%')).toBeInTheDocument(); |
| 87 | + expect(screen.getByText('Passing')).toBeInTheDocument(); |
103 | 88 | });
|
104 | 89 | });
|
0 commit comments