diff --git a/kafka-ui-react-app/src/components/common/Breadcrumb/Breadcrumb.tsx b/kafka-ui-react-app/src/components/common/Breadcrumb/Breadcrumb.tsx
index b3b7a2c5c081341a9134f53599d3625f64c4ba48..2e93e2a6855f316c4f7fada4cded4a49dc1c0859 100644
--- a/kafka-ui-react-app/src/components/common/Breadcrumb/Breadcrumb.tsx
+++ b/kafka-ui-react-app/src/components/common/Breadcrumb/Breadcrumb.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import { NavLink } from 'react-router-dom';
-interface Link {
+export interface Link {
label: string;
href: string;
}
diff --git a/kafka-ui-react-app/src/components/common/Breadcrumb/__tests__/Breadcrumb.spec.tsx b/kafka-ui-react-app/src/components/common/Breadcrumb/__tests__/Breadcrumb.spec.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..c8b3a5815685ca9e343d35d7e4902ae755aa8c34
--- /dev/null
+++ b/kafka-ui-react-app/src/components/common/Breadcrumb/__tests__/Breadcrumb.spec.tsx
@@ -0,0 +1,48 @@
+import { mount, shallow } from 'enzyme';
+import React from 'react';
+import { StaticRouter } from 'react-router-dom';
+import Breadcrumb, { Link } from '../Breadcrumb';
+
+describe('Breadcrumb component', () => {
+ const links: Link[] = [
+ {
+ label: 'link1',
+ href: 'link1href',
+ },
+ {
+ label: 'link2',
+ href: 'link2href',
+ },
+ {
+ label: 'link3',
+ href: 'link3href',
+ },
+ ];
+
+ const child =
;
+
+ const component = mount(
+
+ {child}
+
+ );
+
+ it('renders the list of links', () => {
+ component.find(`NavLink`).forEach((link, idx) => {
+ expect(link.prop('to')).toEqual(links[idx].href);
+ expect(link.contains(links[idx].label)).toBeTruthy();
+ });
+ });
+ it('renders the children', () => {
+ const list = component.find('ul').children();
+ expect(list.last().containsMatchingElement(child)).toBeTruthy();
+ });
+ it('matches the snapshot', () => {
+ const shallowComponent = shallow(
+
+ {child}
+
+ );
+ expect(shallowComponent).toMatchSnapshot();
+ });
+});
diff --git a/kafka-ui-react-app/src/components/common/Breadcrumb/__tests__/__snapshots__/Breadcrumb.spec.tsx.snap b/kafka-ui-react-app/src/components/common/Breadcrumb/__tests__/__snapshots__/Breadcrumb.spec.tsx.snap
new file mode 100644
index 0000000000000000000000000000000000000000..b7696f3bb630e13722b31ccd65e7efc8163faa31
--- /dev/null
+++ b/kafka-ui-react-app/src/components/common/Breadcrumb/__tests__/__snapshots__/Breadcrumb.spec.tsx.snap
@@ -0,0 +1,49 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Breadcrumb component matches the snapshot 1`] = `
+
+
+
+
+
+`;
diff --git a/kafka-ui-react-app/src/components/common/BytesFormatted/BytesFormatted.tsx b/kafka-ui-react-app/src/components/common/BytesFormatted/BytesFormatted.tsx
index 2334c8067ab25f4f125ae10c9b39e06e0f72303a..9447f72402543ccc9362d3285478b1ece9edf3d9 100644
--- a/kafka-ui-react-app/src/components/common/BytesFormatted/BytesFormatted.tsx
+++ b/kafka-ui-react-app/src/components/common/BytesFormatted/BytesFormatted.tsx
@@ -5,20 +5,22 @@ interface Props {
precision?: number;
}
-const BytesFormatted: React.FC = ({ value, precision = 0 }) => {
- const formatedValue = React.useMemo(() => {
- const bytes = typeof value === 'string' ? parseInt(value, 10) : value;
-
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- if (!bytes || bytes === 0) return [0, sizes[0]];
+export const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- if (bytes < 1024) return [Math.ceil(bytes), sizes[0]];
-
- const pow = Math.floor(Math.log2(bytes) / 10);
- const multiplier = 10 ** (precision || 2);
- return (
- Math.round((bytes * multiplier) / 1024 ** pow) / multiplier + sizes[pow]
- );
+const BytesFormatted: React.FC = ({ value, precision = 0 }) => {
+ const formatedValue = React.useMemo((): string => {
+ try {
+ const bytes = typeof value === 'string' ? parseInt(value, 10) : value;
+ if (Number.isNaN(bytes)) return `-Bytes`;
+ if (!bytes || bytes < 1024) return `${Math.ceil(bytes || 0)}${sizes[0]}`;
+ const pow = Math.floor(Math.log2(bytes) / 10);
+ const multiplier = 10 ** (precision < 0 ? 0 : precision);
+ return (
+ Math.round((bytes * multiplier) / 1024 ** pow) / multiplier + sizes[pow]
+ );
+ } catch (e) {
+ return `-Bytes`;
+ }
}, [value]);
return {formatedValue};
diff --git a/kafka-ui-react-app/src/components/common/BytesFormatted/__tests__/BytesFormatted.spec.tsx b/kafka-ui-react-app/src/components/common/BytesFormatted/__tests__/BytesFormatted.spec.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..85ed10877b38e3da2f723985db81602cde49a6ba
--- /dev/null
+++ b/kafka-ui-react-app/src/components/common/BytesFormatted/__tests__/BytesFormatted.spec.tsx
@@ -0,0 +1,38 @@
+import { shallow } from 'enzyme';
+import React from 'react';
+import BytesFormatted, { sizes } from '../BytesFormatted';
+
+describe('BytesFormatted', () => {
+ it('renders Bytes correctly', () => {
+ const component = shallow();
+ expect(component.text()).toEqual('666Bytes');
+ });
+
+ it('renders correct units', () => {
+ let value = 1;
+ sizes.forEach((unit) => {
+ const component = shallow();
+ expect(component.text()).toEqual(`1${unit}`);
+ value *= 1024;
+ });
+ });
+
+ it('renders correct precision', () => {
+ let component = shallow();
+ expect(component.text()).toEqual(`1.953125${sizes[1]}`);
+
+ component = shallow();
+ expect(component.text()).toEqual(`9.76563${sizes[1]}`);
+ });
+
+ it('correctly handles invalid props', () => {
+ let component = shallow();
+ expect(component.text()).toEqual(`10${sizes[1]}`);
+
+ component = shallow();
+ expect(component.text()).toEqual(`-${sizes[0]}`);
+
+ component = shallow();
+ expect(component.text()).toEqual(`0${sizes[0]}`);
+ });
+});
diff --git a/kafka-ui-react-app/src/components/common/Dashboard/__tests__/Indicator.spec.tsx b/kafka-ui-react-app/src/components/common/Dashboard/__tests__/Indicator.spec.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..3709f9add181ce0e0c4f7d287f74aa8b8460a82e
--- /dev/null
+++ b/kafka-ui-react-app/src/components/common/Dashboard/__tests__/Indicator.spec.tsx
@@ -0,0 +1,15 @@
+import { mount } from 'enzyme';
+import React from 'react';
+import Indicator from '../Indicator';
+
+describe('Indicator', () => {
+ it('matches the snapshot', () => {
+ const child = 'Child';
+ const component = mount(
+
+ {child}
+
+ );
+ expect(component).toMatchSnapshot();
+ });
+});
diff --git a/kafka-ui-react-app/src/components/common/Dashboard/__tests__/MetricsWrapper.spec.tsx b/kafka-ui-react-app/src/components/common/Dashboard/__tests__/MetricsWrapper.spec.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..73864385ffd170c64bc1ffeac113dd5fe6267192
--- /dev/null
+++ b/kafka-ui-react-app/src/components/common/Dashboard/__tests__/MetricsWrapper.spec.tsx
@@ -0,0 +1,24 @@
+import { shallow } from 'enzyme';
+import React from 'react';
+import MetricsWrapper from '../MetricsWrapper';
+
+describe('MetricsWrapper', () => {
+ it('correctly adds classes', () => {
+ const className = 'className';
+ const component = shallow(
+
+ );
+ expect(component.find(`.${className}`).exists()).toBeTruthy();
+ expect(component.find('.level-multiline').exists()).toBeTruthy();
+ });
+
+ it('correctly renders children', () => {
+ let component = shallow();
+ expect(component.find('.subtitle').exists()).toBeFalsy();
+
+ const title = 'title';
+ component = shallow();
+ expect(component.find('.subtitle').exists()).toBeTruthy();
+ expect(component.text()).toEqual(title);
+ });
+});
diff --git a/kafka-ui-react-app/src/components/common/Dashboard/__tests__/__snapshots__/Indicator.spec.tsx.snap b/kafka-ui-react-app/src/components/common/Dashboard/__tests__/__snapshots__/Indicator.spec.tsx.snap
new file mode 100644
index 0000000000000000000000000000000000000000..7cabd55e4f5374303acbf009143e21adf62b1e0a
--- /dev/null
+++ b/kafka-ui-react-app/src/components/common/Dashboard/__tests__/__snapshots__/Indicator.spec.tsx.snap
@@ -0,0 +1,27 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Indicator matches the snapshot 1`] = `
+
+
+
+
+ label
+
+
+ Child
+
+
+
+
+`;
diff --git a/kafka-ui-react-app/src/components/common/PageLoader/__tests__/PageLoader.spec.tsx b/kafka-ui-react-app/src/components/common/PageLoader/__tests__/PageLoader.spec.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..ea34bb19420c5f67ccb8bec0e4fef925dbf3f3ce
--- /dev/null
+++ b/kafka-ui-react-app/src/components/common/PageLoader/__tests__/PageLoader.spec.tsx
@@ -0,0 +1,10 @@
+import { mount } from 'enzyme';
+import React from 'react';
+import PageLoader from '../PageLoader';
+
+describe('PageLoader', () => {
+ it('matches the snapshot', () => {
+ const component = mount();
+ expect(component).toMatchSnapshot();
+ });
+});
diff --git a/kafka-ui-react-app/src/components/common/PageLoader/__tests__/__snapshots__/PageLoader.spec.tsx.snap b/kafka-ui-react-app/src/components/common/PageLoader/__tests__/__snapshots__/PageLoader.spec.tsx.snap
new file mode 100644
index 0000000000000000000000000000000000000000..10a9cf063135223ff34fc7f3efb0971669a725d5
--- /dev/null
+++ b/kafka-ui-react-app/src/components/common/PageLoader/__tests__/__snapshots__/PageLoader.spec.tsx.snap
@@ -0,0 +1,36 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`PageLoader matches the snapshot 1`] = `
+
+
+
+`;