Skip to content

Commit 60a0553

Browse files
committed
FE: Add tests for kafka connect connectors
1 parent c57b75b commit 60a0553

File tree

13 files changed

+195
-209
lines changed

13 files changed

+195
-209
lines changed

frontend/src/components/ClusterPage/ClusterPage.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ const ClusterPage: React.FC = () => {
106106
element={<KafkaConnect />}
107107
/>
108108
)}
109-
{contextValue.hasKafkaConnectConfigured && (
110-
<Route
111-
path={getNonExactPath(kafkaConnectRelativePath)}
112-
element={<KafkaConnect />}
113-
/>
114-
)}
115109
{contextValue.hasKsqlDbConfigured && (
116110
<Route
117111
path={getNonExactPath(clusterKsqlDbRelativePath)}

frontend/src/components/ClusterPage/__tests__/ClusterPage.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import { render, WithRoute } from 'lib/testHelpers';
66
import {
77
clusterBrokersPath,
88
clusterConnectorsPath,
9-
clusterConnectsPath,
109
clusterConsumerGroupsPath,
1110
clusterKsqlDbPath,
1211
clusterPath,
1312
clusterSchemasPath,
1413
clusterTopicsPath,
14+
kafkaConnectPath,
1515
} from 'lib/paths';
1616
import { useClusters } from 'lib/hooks/api/clusters';
1717
import { onlineClusterPayload } from 'lib/fixtures/clusters';
1818

1919
const CLusterCompText = {
2020
Topics: 'Topics',
2121
Schemas: 'Schemas',
22-
Connect: 'Connect',
22+
Connect: 'Kafka Connect',
2323
Brokers: 'Brokers',
2424
ConsumerGroups: 'ConsumerGroups',
2525
KsqlDb: 'KsqlDb',
@@ -111,7 +111,7 @@ describe('ClusterPage', () => {
111111
itCorrectlyHandlesConfiguredSchema(
112112
ClusterFeaturesEnum.KAFKA_CONNECT,
113113
CLusterCompText.Connect,
114-
clusterConnectsPath(onlineClusterPayload.name)
114+
kafkaConnectPath(onlineClusterPayload.name)
115115
);
116116
itCorrectlyHandlesConfiguredSchema(
117117
ClusterFeaturesEnum.KAFKA_CONNECT,

frontend/src/components/Connect/Clusters/Clusters.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
11
import React from 'react';
2-
import { Connect } from 'generated-sources';
32
import { useConnects } from 'lib/hooks/api/kafkaConnect';
43
import useAppParams from 'lib/hooks/useAppParams';
54
import { ClusterNameRoute } from 'lib/paths';
65

76
import ClustersStatistics from './ui/Statistics/Statistics';
87
import List from './ui/List/List';
98

10-
const testConnects: Connect[] = [
11-
{
12-
name: 'local',
13-
connectorsCount: 5,
14-
failedConnectorsCount: 0,
15-
tasksCount: 5,
16-
failedTasksCount: 0,
17-
},
18-
{
19-
name: 'Cluster name 2',
20-
connectorsCount: 5,
21-
failedConnectorsCount: 1,
22-
tasksCount: 6,
23-
failedTasksCount: 3,
24-
},
25-
];
26-
279
const KafkaConnectClustersPage = () => {
2810
const { clusterName } = useAppParams<ClusterNameRoute>();
2911
const { data: connects, isLoading } = useConnects(clusterName, true);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react';
2+
import Header from 'components/Connect/Header/Header';
3+
import ClusterContext, {
4+
initialValue,
5+
} from 'components/contexts/ClusterContext';
6+
import { render } from 'lib/testHelpers';
7+
import { screen } from '@testing-library/react';
8+
import { connects } from 'lib/fixtures/kafkaConnect';
9+
import { useConnects } from 'lib/hooks/api/kafkaConnect';
10+
11+
jest.mock('lib/hooks/api/kafkaConnect', () => ({
12+
useConnects: jest.fn(),
13+
}));
14+
15+
describe('Kafka Connect header', () => {
16+
beforeEach(() => {
17+
(useConnects as jest.Mock).mockImplementation(() => ({
18+
data: connects,
19+
}));
20+
});
21+
22+
async function renderComponent({ isReadOnly }: { isReadOnly: boolean }) {
23+
render(
24+
<ClusterContext.Provider value={{ ...initialValue, isReadOnly }}>
25+
<Header />
26+
</ClusterContext.Provider>
27+
);
28+
}
29+
30+
it('render create connector button', () => {
31+
renderComponent({ isReadOnly: false });
32+
33+
const btn = screen.getByRole('button', { name: 'Create Connector' });
34+
35+
expect(btn).toBeInTheDocument();
36+
expect(btn).toBeEnabled();
37+
});
38+
39+
describe('when no connects', () => {
40+
it('create connector button is disabled', () => {
41+
renderComponent({ isReadOnly: false });
42+
43+
const btn = screen.getByRole('button', { name: 'Create Connector' });
44+
45+
expect(btn).toBeInTheDocument();
46+
expect(btn).toBeEnabled();
47+
});
48+
});
49+
50+
describe('when cluster is readonly', () => {
51+
it('doesnt render create connector button', () => {
52+
(useConnects as jest.Mock).mockImplementation(() => ({
53+
data: [],
54+
}));
55+
renderComponent({ isReadOnly: false });
56+
57+
const btn = screen.queryByRole('button', { name: 'Create Connector' });
58+
59+
expect(btn).toBeDisabled();
60+
});
61+
});
62+
});

frontend/src/components/Connect/List/Statistics/Statistics.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const ConnectorsStatistics = ({ connectors, isLoading }: Props) => {
1414
}, [connectors]);
1515

1616
return (
17-
<Statistics.Container>
17+
<Statistics.Container role="group">
1818
<Statistics.Item
1919
title="Connectors"
2020
count={statistics.connectorsCount}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import React from 'react';
2+
import { render } from 'lib/testHelpers';
3+
import { screen, within } from '@testing-library/react';
4+
import Statistics from 'components/Connect/List/Statistics/Statistics';
5+
import { FullConnectorInfo } from 'generated-sources';
6+
import { connectors } from 'lib/fixtures/kafkaConnect';
7+
8+
describe('Kafka Connect Connectors Statistics', () => {
9+
async function renderComponent({
10+
data,
11+
isLoading,
12+
}: {
13+
data: FullConnectorInfo[] | undefined;
14+
isLoading: boolean;
15+
}) {
16+
render(<Statistics connectors={data ?? []} isLoading={isLoading} />);
17+
}
18+
19+
describe('when data loading', () => {
20+
let statistics: HTMLElement;
21+
beforeEach(() => {
22+
renderComponent({ data: undefined, isLoading: true });
23+
statistics = screen.getByRole('group');
24+
});
25+
26+
it('renders statistic container elements', () => {
27+
expect(statistics).toBeInTheDocument();
28+
});
29+
30+
describe('Connectors statistic', () => {
31+
let connectorStatisticsCell: HTMLElement;
32+
beforeEach(() => {
33+
connectorStatisticsCell = within(statistics).getByRole('cell', {
34+
name: 'Connectors',
35+
});
36+
});
37+
it('exists', () => {
38+
expect(connectorStatisticsCell).toBeInTheDocument();
39+
});
40+
41+
it('shows loader', () => {
42+
const loader = within(connectorStatisticsCell).getByRole('status');
43+
expect(loader).toBeInTheDocument();
44+
});
45+
});
46+
describe('Tasks statistic', () => {
47+
let tasksStatisticsCell: HTMLElement;
48+
beforeEach(() => {
49+
tasksStatisticsCell = within(statistics).getByRole('cell', {
50+
name: 'Tasks',
51+
});
52+
});
53+
it('exists', () => {
54+
expect(tasksStatisticsCell).toBeInTheDocument();
55+
});
56+
57+
it('shows loader', () => {
58+
const loader = within(tasksStatisticsCell).getByRole('status');
59+
expect(loader).toBeInTheDocument();
60+
});
61+
});
62+
});
63+
64+
describe('when data is loaded', () => {
65+
let connectorsStatistic: HTMLElement;
66+
let tasksStatistics: HTMLElement;
67+
beforeEach(() => {
68+
renderComponent({ data: connectors, isLoading: false });
69+
[connectorsStatistic, tasksStatistics] = screen.getAllByRole('cell');
70+
});
71+
72+
describe('Connectors statistics', () => {
73+
it('renders statistic', () => {
74+
expect(connectorsStatistic).toBeInTheDocument();
75+
76+
const count = within(connectorsStatistic).getByText(3);
77+
expect(count).toBeInTheDocument();
78+
79+
const alert = within(connectorsStatistic).getByRole('alert');
80+
expect(alert).toBeInTheDocument();
81+
expect(alert).toHaveTextContent('1');
82+
});
83+
});
84+
describe('Tasks statistics', () => {
85+
it('renders statistic', () => {
86+
expect(tasksStatistics).toBeInTheDocument();
87+
88+
const count = within(tasksStatistics).getByText(5);
89+
expect(count).toBeInTheDocument();
90+
91+
const alert = within(tasksStatistics).getByRole('alert');
92+
expect(alert).toBeInTheDocument();
93+
expect(alert).toHaveTextContent('1');
94+
});
95+
});
96+
});
97+
});

frontend/src/components/Connect/List/Statistics/models/computeStatistics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const computeStatistics = (
1616
let failedTasksCount = 0;
1717

1818
connectors.forEach((connector) => {
19-
if (connector.status.state !== ConnectorState.RUNNING) {
19+
if (connector.status.state === ConnectorState.FAILED) {
2020
failedConnectorsCount += 1;
2121
}
2222

0 commit comments

Comments
 (0)