Browse Source

add tests

sergei 3 years ago
parent
commit
22612ed385

+ 2 - 2
kafka-ui-react-app/src/components/Nav/ClusterMenu.tsx

@@ -11,7 +11,7 @@ import {
   clusterKsqlDbPath,
   clusterKsqlDbPath,
 } from 'lib/paths';
 } from 'lib/paths';
 
 
-import { ClusterMenuItem } from './ClusterMenuItem/ClusterMenuItem';
+import ClusterMenuItem from './ClusterMenuItem/ClusterMenuItem';
 import DefaultClusterIcon from './DefaultClusterIcon';
 import DefaultClusterIcon from './DefaultClusterIcon';
 import ClusterStatusIcon from './ClusterStatusIcon';
 import ClusterStatusIcon from './ClusterStatusIcon';
 
 
@@ -50,7 +50,7 @@ const ClusterMenu: React.FC<Props> = ({
             </NavLink>
             </NavLink>
           </li>
           </li>
           <ClusterMenuItem
           <ClusterMenuItem
-            liType="primary1"
+            liType="primary"
             to={clusterTopicsPath(name)}
             to={clusterTopicsPath(name)}
             activeClassName="is-active"
             activeClassName="is-active"
             title="Topics"
             title="Topics"

+ 1 - 1
kafka-ui-react-app/src/components/Nav/ClusterMenuItem/ClusterMenuItem.styled.ts

@@ -1,7 +1,7 @@
 import styled from 'styled-components';
 import styled from 'styled-components';
 
 
 export interface Props {
 export interface Props {
-  liType: 'primary1';
+  liType: 'primary';
   to?: string;
   to?: string;
   activeClassName?: string;
   activeClassName?: string;
   title?: string;
   title?: string;

+ 4 - 2
kafka-ui-react-app/src/components/Nav/ClusterMenuItem/ClusterMenuItem.tsx

@@ -4,9 +4,9 @@ import StyledMenuItem, {
 import React from 'react';
 import React from 'react';
 import { NavLink } from 'react-router-dom';
 import { NavLink } from 'react-router-dom';
 
 
-type Props = MenuItemProps;
+export type Props = MenuItemProps;
 
 
-export const ClusterMenuItem: React.FC<Props> = (props) => {
+const ClusterMenuItem: React.FC<Props> = (props) => {
   const { to, activeClassName, title, children, liType, ...rest } = props;
   const { to, activeClassName, title, children, liType, ...rest } = props;
 
 
   if (to) {
   if (to) {
@@ -21,3 +21,5 @@ export const ClusterMenuItem: React.FC<Props> = (props) => {
 
 
   return <StyledMenuItem {...props} />;
   return <StyledMenuItem {...props} />;
 };
 };
+
+export default ClusterMenuItem;

+ 33 - 0
kafka-ui-react-app/src/components/Nav/__tests__/ClusterMenuItem.spec.tsx

@@ -0,0 +1,33 @@
+import React from 'react';
+import { mount } from 'enzyme';
+import { StaticRouter } from 'react-router';
+import ClusterMenuItem, {
+  Props as MenuItemProps,
+} from 'components/Nav/ClusterMenuItem/ClusterMenuItem';
+
+describe('ClusterMenuItem', () => {
+  const setupComponent = (props: MenuItemProps) => (
+    <StaticRouter>
+      <ClusterMenuItem {...props} />
+    </StaticRouter>
+  );
+
+  it('renders with NavLink', () => {
+    const wrapper = mount(
+      setupComponent({
+        liType: 'primary',
+        to: 'test-url',
+      })
+    );
+    expect(wrapper.find('a').length).toEqual(1);
+  });
+
+  it('renders without NavLink', () => {
+    const wrapper = mount(
+      setupComponent({
+        liType: 'primary',
+      })
+    );
+    expect(wrapper.find('a').length).toEqual(0);
+  });
+});