diff --git a/packages/jaeger-ui/src/components/App/TopNav.test.js b/packages/jaeger-ui/src/components/App/TopNav.test.js index 0cc844dfe0..9a86f3ccd1 100644 --- a/packages/jaeger-ui/src/components/App/TopNav.test.js +++ b/packages/jaeger-ui/src/components/App/TopNav.test.js @@ -13,8 +13,9 @@ // limitations under the License. import React from 'react'; -import { mount } from 'enzyme'; -import { Link, BrowserRouter as Router } from 'react-router-dom'; +import { render, screen } from '@testing-library/react'; +import { BrowserRouter } from 'react-router-dom'; +import '@testing-library/jest-dom'; import { mapStateToProps, TopNavImpl as TopNav } from './TopNav'; @@ -55,65 +56,101 @@ describe('', () => { label: 'Blog', url: blogUrl, }, + { + label: 'Docs', + url: 'http://jaeger.readthedocs.io/en/latest/', + }, configMenuGroup, ], }, router: { - location: { location: { pathname: 'some-path ' } }, + location: { location: { pathname: 'some-path' } }, }, traceDiff: {}, }; - let wrapper; + describe('renders the default menu options', () => { + let component; + beforeEach(() => { + component = render( + + + + ); + }); - beforeEach(() => { - wrapper = mount( - - - - ); - }); + afterEach(() => { + component.unmount(); + }); - describe('renders the default menu options', () => { it('renders the "JAEGER UI" link', () => { - const items = wrapper.find(Link).findWhere(link => link.prop('to') === '/'); - expect(items.length).toBe(1); + const items = screen.getByRole('link', { name: 'JAEGER UI' }); + expect(items).toBeInTheDocument(); }); + it('renders the "Search" button', () => { - const items = wrapper.find(Link).findWhere(link => link.prop('to') === '/search'); - expect(items.length).toBe(1); + const items = screen.getByRole('link', { name: 'Search' }); + expect(items).toBeInTheDocument(); }); it('renders the "System Architecture" button', () => { - const items = wrapper.find(Link).findWhere(link => link.prop('to') === '/dependencies'); - expect(items.length).toBe(1); + const items = screen.getByRole('link', { name: 'System Architecture' }); + expect(items).toBeInTheDocument(); }); }); describe('renders the custom menu', () => { + let component; + beforeEach(() => { + component = render( + + + + ); + }); + + afterEach(() => { + component.unmount(); + }); + it('renders the top-level item', () => { - const item = wrapper.find(`[href="${githubUrl}"]`); - expect(item.length).toBe(1); - expect(item.text()).toMatch(labelGitHub); + const item = screen.getByRole('link', { name: labelGitHub }); + expect(item).toBeInTheDocument(); + expect(item.href).toBe(githubUrl); }); it('renders the nested menu items', () => { - const item = wrapper.find(TopNav.CustomNavDropdown); - expect(item.length).toBe(1); - expect(item.prop('label')).toBe(labelAbout); - expect(item.prop('items')).toBe(dropdownItems); + const item = screen.getAllByText(labelAbout)[0]; + expect(item).toBeInTheDocument(); }); it('adds target=_self to top-level item', () => { - const item = wrapper.find(`[href="${githubUrl}"]`); - expect(item.length).toBe(1); - expect(item.find(`[target="_self"]`).length).toBe(1); + const item = screen.getByRole('link', { name: labelGitHub }); + expect(item.target).toBe('_self'); }); it('sets target=_blank by default', () => { - const item = wrapper.find(`[href="${blogUrl}"]`); - expect(item.length).toBe(1); - expect(item.find(`[target="_blank"]`).length).toBe(1); + const item = screen.getByRole('link', { name: 'Blog' }); + expect(item.target).toBe('_blank'); + }); + + describe('', () => { + it('renders sub-menu text', () => { + dropdownItems.slice(0, 0).forEach(itemConfig => { + const item = screen.getByText(itemConfig.label); + expect(item).toBeInTheDocument(); + expect(item.disabled).toBe(true); + }); + }); + + it('renders sub-menu links', () => { + dropdownItems.slice(1, 2).forEach(itemConfig => { + const item = screen.getByRole('link', { name: itemConfig.label }); + expect(item).toBeInTheDocument(); + expect(item.href).toBe(itemConfig.url); + expect(item.target).toBe(itemConfig.anchorTarget || '_blank'); + }); + }); }); }); }); diff --git a/packages/jaeger-ui/src/components/App/__snapshots__/index.test.js.snap b/packages/jaeger-ui/src/components/App/__snapshots__/index.test.js.snap index 658b9a7cb2..59964d8743 100644 --- a/packages/jaeger-ui/src/components/App/__snapshots__/index.test.js.snap +++ b/packages/jaeger-ui/src/components/App/__snapshots__/index.test.js.snap @@ -62,7 +62,7 @@ exports[`JaegerUIApp does not explode 1`] = ` } } > - + - + diff --git a/packages/jaeger-ui/src/components/App/index.test.js b/packages/jaeger-ui/src/components/App/index.test.js index fd5bfae426..2a28a9af14 100644 --- a/packages/jaeger-ui/src/components/App/index.test.js +++ b/packages/jaeger-ui/src/components/App/index.test.js @@ -13,7 +13,7 @@ // limitations under the License. import React from 'react'; -import { shallow } from 'enzyme'; +import shallow from '../../utils/ReactShallowRenderer.test'; import JaegerUIApp from './index';