|
@@ -1,7 +1,7 @@
|
|
|
import React from 'react';
|
|
|
import { render, WithRoute } from 'lib/testHelpers';
|
|
|
import { screen, waitFor } from '@testing-library/dom';
|
|
|
-import { clusterBrokersPath } from 'lib/paths';
|
|
|
+import { clusterBrokerPath, clusterBrokersPath } from 'lib/paths';
|
|
|
import { act } from '@testing-library/react';
|
|
|
import BrokersList from 'components/Brokers/BrokersList/BrokersList';
|
|
|
import userEvent from '@testing-library/user-event';
|
|
@@ -41,84 +41,108 @@ describe('BrokersList Component', () => {
|
|
|
);
|
|
|
|
|
|
describe('BrokersList', () => {
|
|
|
- beforeEach(() => {
|
|
|
- (useBrokers as jest.Mock).mockImplementation(() => ({
|
|
|
- data: brokersPayload,
|
|
|
- }));
|
|
|
- (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
- data: clusterStatsPayload,
|
|
|
- }));
|
|
|
+ describe('when the brokers are loaded', () => {
|
|
|
+ beforeEach(() => {
|
|
|
+ (useBrokers as jest.Mock).mockImplementation(() => ({
|
|
|
+ data: brokersPayload,
|
|
|
+ }));
|
|
|
+ (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
+ data: clusterStatsPayload,
|
|
|
+ }));
|
|
|
+ });
|
|
|
+ it('renders', async () => {
|
|
|
+ renderComponent();
|
|
|
+ expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
+ expect(screen.getAllByRole('row').length).toEqual(3);
|
|
|
+ });
|
|
|
+ it('opens broker when row clicked', async () => {
|
|
|
+ renderComponent();
|
|
|
+ await act(() => {
|
|
|
+ userEvent.click(screen.getByRole('cell', { name: '0' }));
|
|
|
+ });
|
|
|
+ await waitFor(() =>
|
|
|
+ expect(mockedUsedNavigate).toBeCalledWith(
|
|
|
+ clusterBrokerPath(clusterName, '0')
|
|
|
+ )
|
|
|
+ );
|
|
|
+ });
|
|
|
+ it('shows warning when offlinePartitionCount > 0', async () => {
|
|
|
+ (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
+ data: {
|
|
|
+ ...clusterStatsPayload,
|
|
|
+ offlinePartitionCount: 1345,
|
|
|
+ },
|
|
|
+ }));
|
|
|
+ renderComponent();
|
|
|
+ const onlineWidget = screen.getByText(
|
|
|
+ clusterStatsPayload.onlinePartitionCount
|
|
|
+ );
|
|
|
+ expect(onlineWidget).toBeInTheDocument();
|
|
|
+ expect(onlineWidget).toHaveStyle({ color: '#E51A1A' });
|
|
|
+ });
|
|
|
+ it('shows right count when offlinePartitionCount > 0', async () => {
|
|
|
+ (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
+ data: {
|
|
|
+ ...clusterStatsPayload,
|
|
|
+ inSyncReplicasCount: testInSyncReplicasCount,
|
|
|
+ outOfSyncReplicasCount: testOutOfSyncReplicasCount,
|
|
|
+ },
|
|
|
+ }));
|
|
|
+ renderComponent();
|
|
|
+ const onlineWidgetDef = screen.getByText(testInSyncReplicasCount);
|
|
|
+ const onlineWidget = screen.getByText(
|
|
|
+ `of ${testInSyncReplicasCount + testOutOfSyncReplicasCount}`
|
|
|
+ );
|
|
|
+ expect(onlineWidgetDef).toBeInTheDocument();
|
|
|
+ expect(onlineWidget).toBeInTheDocument();
|
|
|
+ });
|
|
|
+ it('shows right count when inSyncReplicasCount: undefined && outOfSyncReplicasCount: 1', async () => {
|
|
|
+ (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
+ data: {
|
|
|
+ ...clusterStatsPayload,
|
|
|
+ inSyncReplicasCount: undefined,
|
|
|
+ outOfSyncReplicasCount: testOutOfSyncReplicasCount,
|
|
|
+ },
|
|
|
+ }));
|
|
|
+ renderComponent();
|
|
|
+ const onlineWidget = screen.getByText(
|
|
|
+ `of ${testOutOfSyncReplicasCount}`
|
|
|
+ );
|
|
|
+ expect(onlineWidget).toBeInTheDocument();
|
|
|
+ });
|
|
|
+ it(`shows right count when inSyncReplicasCount: ${testInSyncReplicasCount} outOfSyncReplicasCount: undefined`, async () => {
|
|
|
+ (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
+ data: {
|
|
|
+ ...clusterStatsPayload,
|
|
|
+ inSyncReplicasCount: testInSyncReplicasCount,
|
|
|
+ outOfSyncReplicasCount: undefined,
|
|
|
+ },
|
|
|
+ }));
|
|
|
+ renderComponent();
|
|
|
+ const onlineWidgetDef = screen.getByText(testInSyncReplicasCount);
|
|
|
+ const onlineWidget = screen.getByText(`of ${testInSyncReplicasCount}`);
|
|
|
+ expect(onlineWidgetDef).toBeInTheDocument();
|
|
|
+ expect(onlineWidget).toBeInTheDocument();
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('renders', async () => {
|
|
|
- renderComponent();
|
|
|
- expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
- const rows = screen.getAllByRole('row');
|
|
|
- expect(rows.length).toEqual(3);
|
|
|
- });
|
|
|
- it('opens broker when row clicked', async () => {
|
|
|
- renderComponent();
|
|
|
- await act(() => {
|
|
|
- userEvent.click(screen.getByRole('cell', { name: '0' }));
|
|
|
+ describe('when diskUsage is empty', () => {
|
|
|
+ beforeEach(() => {
|
|
|
+ (useBrokers as jest.Mock).mockImplementation(() => ({
|
|
|
+ data: brokersPayload,
|
|
|
+ }));
|
|
|
+ (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
+ data: { ...clusterStatsPayload, diskUsage: undefined },
|
|
|
+ }));
|
|
|
});
|
|
|
- await waitFor(() => expect(mockedUsedNavigate).toBeCalledWith('0'));
|
|
|
- });
|
|
|
- it('shows warning when offlinePartitionCount > 0', async () => {
|
|
|
- (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
- data: {
|
|
|
- ...clusterStatsPayload,
|
|
|
- offlinePartitionCount: 1345,
|
|
|
- },
|
|
|
- }));
|
|
|
- renderComponent();
|
|
|
- const onlineWidget = screen.getByText(
|
|
|
- clusterStatsPayload.onlinePartitionCount
|
|
|
- );
|
|
|
- expect(onlineWidget).toBeInTheDocument();
|
|
|
- expect(onlineWidget).toHaveStyle({ color: '#E51A1A' });
|
|
|
- });
|
|
|
- it('shows right count when offlinePartitionCount > 0', async () => {
|
|
|
- (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
- data: {
|
|
|
- ...clusterStatsPayload,
|
|
|
- inSyncReplicasCount: testInSyncReplicasCount,
|
|
|
- outOfSyncReplicasCount: testOutOfSyncReplicasCount,
|
|
|
- },
|
|
|
- }));
|
|
|
- renderComponent();
|
|
|
- const onlineWidgetDef = screen.getByText(testInSyncReplicasCount);
|
|
|
- const onlineWidget = screen.getByText(
|
|
|
- `of ${testInSyncReplicasCount + testOutOfSyncReplicasCount}`
|
|
|
- );
|
|
|
- expect(onlineWidgetDef).toBeInTheDocument();
|
|
|
- expect(onlineWidget).toBeInTheDocument();
|
|
|
- });
|
|
|
|
|
|
- it('shows right count when inSyncReplicasCount: undefined outOfSyncReplicasCount: 1', async () => {
|
|
|
- (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
- data: {
|
|
|
- ...clusterStatsPayload,
|
|
|
- inSyncReplicasCount: undefined,
|
|
|
- outOfSyncReplicasCount: testOutOfSyncReplicasCount,
|
|
|
- },
|
|
|
- }));
|
|
|
- renderComponent();
|
|
|
- const onlineWidget = screen.getByText(`of ${testOutOfSyncReplicasCount}`);
|
|
|
- expect(onlineWidget).toBeInTheDocument();
|
|
|
- });
|
|
|
- it(`shows right count when inSyncReplicasCount: ${testInSyncReplicasCount} outOfSyncReplicasCount: undefined`, async () => {
|
|
|
- (useClusterStats as jest.Mock).mockImplementation(() => ({
|
|
|
- data: {
|
|
|
- ...clusterStatsPayload,
|
|
|
- inSyncReplicasCount: testInSyncReplicasCount,
|
|
|
- outOfSyncReplicasCount: undefined,
|
|
|
- },
|
|
|
- }));
|
|
|
- renderComponent();
|
|
|
- const onlineWidgetDef = screen.getByText(testInSyncReplicasCount);
|
|
|
- const onlineWidget = screen.getByText(`of ${testInSyncReplicasCount}`);
|
|
|
- expect(onlineWidgetDef).toBeInTheDocument();
|
|
|
- expect(onlineWidget).toBeInTheDocument();
|
|
|
+ it('renders empty table', async () => {
|
|
|
+ renderComponent();
|
|
|
+ expect(screen.getByRole('table')).toBeInTheDocument();
|
|
|
+ expect(
|
|
|
+ screen.getByRole('row', { name: 'Disk usage data not available' })
|
|
|
+ ).toBeInTheDocument();
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
});
|