Skip to content

Commit ece0461

Browse files
authored
[QualityMetrics/MetricCard] Migrate enzyme tests to RTL (#2602)
## Which problem is this PR solving? - Partially addresses #1668 ## Description of the changes - This PR migrates `packages/jaeger-ui/src/components/QualityMetrics/MetricCard.test.js` from enzyme to RTL. - I've updated the **MetricCard** to use `arrow={{ pointAtCenter: true }}` as `arrowPointAtCenter` is deprecated. ## How was this change tested? - By running `npm run test` after updating snapshots ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Tanvi Pooranmal Meena <[email protected]> Signed-off-by: Tanvi Pooranmal Meena <[email protected]>
1 parent 2d880b4 commit ece0461

File tree

3 files changed

+19
-378
lines changed

3 files changed

+19
-378
lines changed

packages/jaeger-ui/src/components/QualityMetrics/MetricCard.test.js

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// limitations under the License.
1414

1515
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';
1818
import MetricCard from './MetricCard';
1919

2020
describe('MetricCard', () => {
@@ -63,42 +63,27 @@ describe('MetricCard', () => {
6363
];
6464

6565
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();
7770
});
7871

7972
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+
});
9081
});
9182

9283
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();
10388
});
10489
});

packages/jaeger-ui/src/components/QualityMetrics/MetricCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class MetricCard extends React.PureComponent<TProps> {
6363
<div className="MetricCard--Body">
6464
<span className="MetricCard--TitleHeader">
6565
{name}{' '}
66-
<Tooltip arrowPointAtCenter title="Metric Documentation">
66+
<Tooltip arrow={{ pointAtCenter: true }} title="Metric Documentation">
6767
<a href={metricDocumentationLink} target="_blank" rel="noreferrer noopener">
6868
<NewWindowIcon />
6969
</a>

0 commit comments

Comments
 (0)