diff --git a/packages/jaeger-ui/src/components/common/EmphasizedNode.test.js b/packages/jaeger-ui/src/components/common/EmphasizedNode.test.js index 02c1a48d8f..932b8105b3 100644 --- a/packages/jaeger-ui/src/components/common/EmphasizedNode.test.js +++ b/packages/jaeger-ui/src/components/common/EmphasizedNode.test.js @@ -13,23 +13,25 @@ // limitations under the License. import React from 'react'; -import { shallow } from 'enzyme'; +import { render } from '@testing-library/react'; import EmphasizedNode from './EmphasizedNode'; +import '@testing-library/jest-dom'; describe('', () => { - let wrapper; - let defaultProps; + const defaultProps = { + height: 100, + width: 500, + }; - beforeEach(() => { - defaultProps = { - height: 100, - width: 500, - }; + it('renders with default props', () => { + const { container } = render(); - wrapper = shallow(); - }); + const recElements = container.querySelectorAll('rect'); - it('renders with default props', () => { - expect(wrapper).toMatchSnapshot(); + expect(recElements.length).toBe(4); + recElements.forEach(element => { + expect(element).toHaveAttribute('height', defaultProps.height.toString()); + expect(element).toHaveAttribute('width', defaultProps.width.toString()); + }); }); }); diff --git a/packages/jaeger-ui/src/components/common/EmphasizedNode.tsx b/packages/jaeger-ui/src/components/common/EmphasizedNode.tsx index ce4497a308..4c97747517 100644 --- a/packages/jaeger-ui/src/components/common/EmphasizedNode.tsx +++ b/packages/jaeger-ui/src/components/common/EmphasizedNode.tsx @@ -25,7 +25,7 @@ export default class EmphasizedNode extends React.PureComponent { render() { const { height, width } = this.props; return ( - <> + { height={height} /> - + ); } } diff --git a/packages/jaeger-ui/src/components/common/ExamplesLink.test.js b/packages/jaeger-ui/src/components/common/ExamplesLink.test.js index d6a0c642c2..555c0d752f 100644 --- a/packages/jaeger-ui/src/components/common/ExamplesLink.test.js +++ b/packages/jaeger-ui/src/components/common/ExamplesLink.test.js @@ -13,7 +13,8 @@ // limitations under the License. import React from 'react'; -import { shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; import ExamplesLink from './ExamplesLink'; @@ -25,45 +26,49 @@ describe('ExamplesLink', () => { { traceID: 'bar', }, - { - traceID: 'baz', - }, ]; + const spanLinks = traceLinks.map(({ traceID }, i) => ({ traceID: `${traceID}${i}`, spanIDs: new Array(i + 1).fill('spanID').map((str, j) => `${str}${i}${j}`), })); + const expectedTraceParams = 'traceID=foo&traceID=bar'; + const expectedSpanParams = 'span=spanID00%40foo0&span=spanID10%20spanID11%40bar1'; + it('renders null when props.examples is absent', () => { - expect(shallow().type()).toBe(null); + render(); + expect(screen.queryByRole('link')).toBeNull(); }); it('renders null when props.examples is empty', () => { - expect(shallow().type()).toBe(null); + render(); + expect(screen.queryByRole('link')).toBeNull(); }); - it('renders as expected when given trace links', () => { - expect(shallow()).toMatchSnapshot(); + it('renders correctly when given trace links', () => { + render(); + expect(screen.getByRole('link')).toHaveAttribute('href', `/search?${expectedTraceParams}`); }); it('renders as expected when given span links', () => { - expect(shallow()).toMatchSnapshot(); + render(); + expect(screen.getByRole('link')).toHaveAttribute('href', `/search?${expectedSpanParams}`); }); it('renders as expected when given both span and trace links', () => { - expect(shallow()).toMatchSnapshot(); + render(); + expect(screen.getByRole('link')).toHaveAttribute( + 'href', + `/search?${expectedSpanParams}&${expectedTraceParams}` + ); }); it('renders label text iff props.includeText is true', () => { - expect( - shallow() - .find('a') - .props().children[0] - ).toBe(undefined); - expect( - shallow() - .find('a') - .props().children[0] - ).toBe('Examples '); + render(); + expect(screen.queryByText('Examples')).toBeNull(); + + render(); + expect(screen.getByText('Examples')).toBeInTheDocument(); }); }); diff --git a/packages/jaeger-ui/src/components/common/ExamplesLink.tsx b/packages/jaeger-ui/src/components/common/ExamplesLink.tsx index 6a1167f399..894e48110d 100644 --- a/packages/jaeger-ui/src/components/common/ExamplesLink.tsx +++ b/packages/jaeger-ui/src/components/common/ExamplesLink.tsx @@ -39,10 +39,12 @@ function hasSpans(example: TExample | TExampleWithSpans): example is TExampleWit function getGetUrlArg(examples: TExample[]): { spanLinks: Record; traceID: string[] } { const spanLinks: Record = {}; const traceID: string[] = []; + examples.forEach((example: TExample) => { if (hasSpans(example)) spanLinks[example.traceID] = example.spanIDs.join(' '); else traceID.push(example.traceID); }); + return { spanLinks, traceID, diff --git a/packages/jaeger-ui/src/components/common/__snapshots__/EmphasizedNode.test.js.snap b/packages/jaeger-ui/src/components/common/__snapshots__/EmphasizedNode.test.js.snap deleted file mode 100644 index 15ad71c978..0000000000 --- a/packages/jaeger-ui/src/components/common/__snapshots__/EmphasizedNode.test.js.snap +++ /dev/null @@ -1,28 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` renders with default props 1`] = ` - - - - - - -`; diff --git a/packages/jaeger-ui/src/components/common/__snapshots__/ExamplesLink.test.js.snap b/packages/jaeger-ui/src/components/common/__snapshots__/ExamplesLink.test.js.snap deleted file mode 100644 index 20762163b9..0000000000 --- a/packages/jaeger-ui/src/components/common/__snapshots__/ExamplesLink.test.js.snap +++ /dev/null @@ -1,37 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ExamplesLink renders as expected when given both span and trace links 1`] = ` - - - -`; - -exports[`ExamplesLink renders as expected when given span links 1`] = ` - - - -`; - -exports[`ExamplesLink renders as expected when given trace links 1`] = ` - - - -`;