convert LogLabels tests toRTL (#48887)

This commit is contained in:
Chrysa Dikonimaki 2022-05-11 00:53:14 +02:00 committed by GitHub
parent 2bd9e9aca5
commit 7e5ea3f5a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 16 deletions

View File

@ -26,9 +26,6 @@ exports[`no enzyme tests`] = {
"packages/grafana-ui/src/components/Graph/GraphTooltip/MultiModeGraphTooltip.test.tsx:1865444105": [
[0, 17, 13, "RegExp match", "2409514259"]
],
"packages/grafana-ui/src/components/Logs/LogLabels.test.tsx:1029448019": [
[0, 19, 13, "RegExp match", "2409514259"]
],
"packages/grafana-ui/src/components/Logs/LogMessageAnsi.test.tsx:1630730648": [
[0, 19, 13, "RegExp match", "2409514259"]
],

View File

@ -1,4 +1,4 @@
import { shallow } from 'enzyme';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { getTheme } from '../../themes';
@ -7,23 +7,23 @@ import { UnThemedLogLabels as LogLabels } from './LogLabels';
describe('<LogLabels />', () => {
it('renders notice when no labels are found', () => {
const wrapper = shallow(<LogLabels labels={{}} theme={getTheme()} />);
expect(wrapper.text()).toContain('no unique labels');
render(<LogLabels labels={{}} theme={getTheme()} />);
expect(screen.queryByText('(no unique labels)')).toBeInTheDocument();
});
it('renders labels', () => {
const wrapper = shallow(<LogLabels labels={{ foo: 'bar', baz: '42' }} theme={getTheme()} />);
expect(wrapper.text()).toContain('bar');
expect(wrapper.text()).toContain('42');
render(<LogLabels labels={{ foo: 'bar', baz: '42' }} theme={getTheme()} />);
expect(screen.queryByText('bar')).toBeInTheDocument();
expect(screen.queryByText('42')).toBeInTheDocument();
});
it('excludes labels with certain names or labels starting with underscore', () => {
const wrapper = shallow(<LogLabels labels={{ foo: 'bar', level: '42', _private: '13' }} theme={getTheme()} />);
expect(wrapper.text()).toContain('bar');
expect(wrapper.text()).not.toContain('42');
expect(wrapper.text()).not.toContain('13');
render(<LogLabels labels={{ foo: 'bar', level: '42', _private: '13' }} theme={getTheme()} />);
expect(screen.queryByText('bar')).toBeInTheDocument();
expect(screen.queryByText('42')).not.toBeInTheDocument();
expect(screen.queryByText('13')).not.toBeInTheDocument();
});
it('excludes labels with empty string values', () => {
const wrapper = shallow(<LogLabels labels={{ foo: 'bar', baz: '' }} theme={getTheme()} />);
expect(wrapper.text()).toContain('bar');
expect(wrapper.html()).not.toContain('baz');
render(<LogLabels labels={{ foo: 'bar', baz: '' }} theme={getTheme()} />);
expect(screen.queryByText('bar')).toBeInTheDocument();
expect(screen.queryByText('baz')).not.toBeInTheDocument();
});
});