mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Convert AccordianReferences test to RTL (#51274)
* Convert AccordianReferences test to RTL * Convert AccordianReferences test to RTL * Convert AccordianReferences test to RTL * Convert AccordianReferences tests to RTL * Convert AccordianReferences test to RTL * fix betterer * Convert AccordianReferences test to RTL Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
This commit is contained in:
parent
7d815a1db5
commit
37c6a0b3cb
@ -44,9 +44,6 @@ exports[`no enzyme tests`] = {
|
|||||||
"packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.js:1734982398": [
|
"packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.js:1734982398": [
|
||||||
[14, 26, 13, "RegExp match", "2409514259"]
|
[14, 26, 13, "RegExp match", "2409514259"]
|
||||||
],
|
],
|
||||||
"packages/jaeger-ui-components/src/TraceTimelineViewer/SpanDetail/AccordianReferences.test.js:2025513694": [
|
|
||||||
[14, 19, 13, "RegExp match", "2409514259"]
|
|
||||||
],
|
|
||||||
"packages/jaeger-ui-components/src/TraceTimelineViewer/SpanDetail/KeyValuesTable.test.js:3813002651": [
|
"packages/jaeger-ui-components/src/TraceTimelineViewer/SpanDetail/KeyValuesTable.test.js:3813002651": [
|
||||||
[14, 19, 13, "RegExp match", "2409514259"]
|
[14, 19, 13, "RegExp match", "2409514259"]
|
||||||
],
|
],
|
||||||
|
@ -12,11 +12,9 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { shallow } from 'enzyme';
|
import { render, screen } from '@testing-library/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import ReferenceLink from '../../url/ReferenceLink';
|
|
||||||
|
|
||||||
import AccordianReferences, { References } from './AccordianReferences';
|
import AccordianReferences, { References } from './AccordianReferences';
|
||||||
|
|
||||||
const traceID = 'trace1';
|
const traceID = 'trace1';
|
||||||
@ -54,60 +52,45 @@ const references = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('<AccordianReferences>', () => {
|
const link = { href: 'link' };
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
|
const setup = (propOverrides) => {
|
||||||
const props = {
|
const props = {
|
||||||
compact: false,
|
compact: false,
|
||||||
data: references,
|
data: references,
|
||||||
highContrast: false,
|
highContrast: false,
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
onToggle: jest.fn(),
|
onToggle: jest.fn(),
|
||||||
createFocusSpanLink: jest.fn(),
|
createFocusSpanLink: () => link,
|
||||||
|
...propOverrides,
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
return render(<AccordianReferences {...props} />);
|
||||||
wrapper = shallow(<AccordianReferences {...props} />);
|
};
|
||||||
|
|
||||||
|
describe('AccordianReferences tests', () => {
|
||||||
|
it('renders without exploding', () => {
|
||||||
|
expect(() => setup()).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders without exploding', () => {
|
it('renders the correct number of references', () => {
|
||||||
expect(wrapper).toBeDefined();
|
setup();
|
||||||
expect(wrapper.exists()).toBe(true);
|
|
||||||
|
expect(screen.getByRole('switch', { name: 'References (3)' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('content doesnt show when not expanded', () => {
|
||||||
|
setup({ isOpen: false });
|
||||||
|
|
||||||
|
expect(screen.queryByRole('link', { name: /^View\sLinked/ })).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryAllByRole('link', { name: /^service\d\sop\d/ })).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the content when it is expanded', () => {
|
it('renders the content when it is expanded', () => {
|
||||||
wrapper.setProps({ isOpen: true });
|
setup({ isOpen: true });
|
||||||
const content = wrapper.find(References);
|
|
||||||
expect(content.length).toBe(1);
|
expect(screen.getByRole('switch', { name: 'References (3)' })).toBeInTheDocument();
|
||||||
expect(content.prop('data')).toBe(references);
|
expect(screen.getAllByRole('link', { name: /^service\d\sop\d/ })).toHaveLength(2);
|
||||||
});
|
expect(screen.getByRole('link', { name: /^View\sLinked/ })).toBeInTheDocument();
|
||||||
});
|
|
||||||
|
|
||||||
describe('<References>', () => {
|
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
const props = {
|
|
||||||
data: references,
|
|
||||||
createFocusSpanLink: jest.fn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
wrapper = shallow(<References {...props} />);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('render references list', () => {
|
|
||||||
const refLinks = wrapper.find(ReferenceLink);
|
|
||||||
expect(refLinks.length).toBe(references.length);
|
|
||||||
refLinks.forEach((refLink, i) => {
|
|
||||||
const span = references[i].span;
|
|
||||||
const serviceName = refLink.find('span.span-svc-name').text();
|
|
||||||
if (span && span.traceID === traceID) {
|
|
||||||
const endpointName = refLink.find('small.endpoint-name').text();
|
|
||||||
expect(serviceName).toBe(span.process.serviceName);
|
|
||||||
expect(endpointName).toBe(span.operationName);
|
|
||||||
} else {
|
|
||||||
expect(serviceName).toBe('View Linked Span ');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user