Browse Source

Cover Dashboard page with tests (#527)

* Cover Dashboard page with tests

* Cover Dashboard page with tests

* Cover Dashboard page with tests

* Cover Dashboard page with tests

* Cover Dashboard page with tests

* Cover Dashboard page with tests #527

* Cover Brokers page with tests #213
MBovtriukProvectus 4 years ago
parent
commit
aa46749778

+ 37 - 0
kafka-ui-react-app/src/components/Dashboard/ClustersWidget/__test__/ClustersWidget.spec.tsx

@@ -0,0 +1,37 @@
+import React from 'react';
+import { shallow } from 'enzyme';
+import ClustersWidget from 'components/Dashboard/ClustersWidget/ClustersWidget';
+
+import { offlineCluster, onlineCluster, clusters } from './fixtures';
+
+const component = () =>
+  shallow(
+    <ClustersWidget
+      clusters={clusters}
+      onlineClusters={[onlineCluster]}
+      offlineClusters={[offlineCluster]}
+    />
+  );
+
+describe('ClustersWidget', () => {
+  it('renders clusterWidget list', () => {
+    const clusterWidget = component().find('ClusterWidget');
+    expect(clusterWidget.length).toBe(2);
+  });
+
+  it('renders ClusterWidget', () => {
+    expect(component().exists('ClusterWidget')).toBeTruthy();
+  });
+
+  it('renders columns', () => {
+    expect(component().exists('.columns')).toBeTruthy();
+  });
+
+  it('hides online cluster widgets', () => {
+    const value = component();
+    const input = value.find('input');
+    expect(value.find('ClusterWidget').length).toBe(2);
+    input.simulate('change', { target: { checked: true } });
+    expect(value.find('ClusterWidget').length).toBe(1);
+  });
+});

+ 18 - 0
kafka-ui-react-app/src/components/Dashboard/ClustersWidget/__test__/ClustersWidgetContainer.spec.tsx

@@ -0,0 +1,18 @@
+import React from 'react';
+import { mount } from 'enzyme';
+import { containerRendersView } from 'lib/testHelpers';
+import ClustersWidget from 'components/Dashboard/ClustersWidget/ClustersWidget';
+import ClustersWidgetContainer from 'components/Dashboard/ClustersWidget/ClustersWidgetContainer';
+
+describe('ClustersWidgetContainer', () => {
+  containerRendersView(<ClustersWidgetContainer />, ClustersWidget);
+  describe('view empty ClusterWidget', () => {
+    const setupEmptyWrapper = () => (
+      <ClustersWidget clusters={[]} onlineClusters={[]} offlineClusters={[]} />
+    );
+    it(' is empty when no online clusters', () => {
+      const wrapper = mount(setupEmptyWrapper());
+      expect(wrapper.find('.is-success').text()).toBe('0');
+    });
+  });
+});

+ 15 - 0
kafka-ui-react-app/src/components/Dashboard/__test__/Dashboard.spec.tsx

@@ -0,0 +1,15 @@
+import React from 'react';
+import { shallow } from 'enzyme';
+import Dashboard from 'components/Dashboard/Dashboard';
+
+const component = shallow(<Dashboard />);
+
+describe('Dashboard', () => {
+  it('renders section', () => {
+    expect(component.exists('.section')).toBe(true);
+  });
+
+  it('renders ClustersWidget', () => {
+    expect(component.exists('Connect(ClustersWidget)')).toBe(true);
+  });
+});