Skip to content

Commit cca2c96

Browse files
moremagicHaarolean
andauthored
FE: Fix active controller badge on invalid node (#4085)
Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com>
1 parent 844eb17 commit cca2c96

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

kafka-ui-react-app/src/components/Brokers/Broker/__test__/Broker.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { brokersPayload } from 'lib/fixtures/brokers';
1313
import { clusterStatsPayload } from 'lib/fixtures/clusters';
1414

1515
const clusterName = 'local';
16-
const brokerId = 1;
16+
const brokerId = 200;
1717
const activeClassName = 'is-active';
1818
const brokerLogdir = {
1919
pageText: 'brokerLogdir',

kafka-ui-react-app/src/components/Brokers/BrokersList/BrokersList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ const BrokersList: React.FC = () => {
7373
header: 'Broker ID',
7474
accessorKey: 'brokerId',
7575
// eslint-disable-next-line react/no-unstable-nested-components
76-
cell: ({ row: { id }, getValue }) => (
76+
cell: ({ getValue }) => (
7777
<S.RowCell>
7878
<LinkCell
7979
value={`${getValue<string | number>()}`}
8080
to={encodeURIComponent(`${getValue<string | number>()}`)}
8181
/>
82-
{id === String(activeControllers) && (
82+
{getValue<string | number>() === activeControllers && (
8383
<Tooltip
8484
value={<CheckMarkRoundIcon />}
8585
content="Active Controller"

kafka-ui-react-app/src/components/Brokers/BrokersList/__test__/BrokersList.spec.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ describe('BrokersList Component', () => {
5656
});
5757
it('opens broker when row clicked', async () => {
5858
renderComponent();
59-
await userEvent.click(screen.getByRole('cell', { name: '0' }));
59+
await userEvent.click(screen.getByRole('cell', { name: '100' }));
6060

6161
await waitFor(() =>
6262
expect(mockedUsedNavigate).toBeCalledWith(
63-
clusterBrokerPath(clusterName, '0')
63+
clusterBrokerPath(clusterName, '100')
6464
)
6565
);
6666
});
@@ -124,6 +124,39 @@ describe('BrokersList Component', () => {
124124
});
125125
});
126126

127+
describe('BrokersList', () => {
128+
describe('when the brokers are loaded', () => {
129+
const testActiveControllers = 0;
130+
beforeEach(() => {
131+
(useBrokers as jest.Mock).mockImplementation(() => ({
132+
data: brokersPayload,
133+
}));
134+
(useClusterStats as jest.Mock).mockImplementation(() => ({
135+
data: clusterStatsPayload,
136+
}));
137+
});
138+
139+
it(`Indicates correct active cluster`, async () => {
140+
renderComponent();
141+
await waitFor(() =>
142+
expect(screen.getByRole('tooltip')).toBeInTheDocument()
143+
);
144+
});
145+
it(`Correct display even if there is no active cluster: ${testActiveControllers} `, async () => {
146+
(useClusterStats as jest.Mock).mockImplementation(() => ({
147+
data: {
148+
...clusterStatsPayload,
149+
activeControllers: testActiveControllers,
150+
},
151+
}));
152+
renderComponent();
153+
await waitFor(() =>
154+
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
155+
);
156+
});
157+
});
158+
});
159+
127160
describe('when diskUsage is empty', () => {
128161
beforeEach(() => {
129162
(useBrokers as jest.Mock).mockImplementation(() => ({
@@ -157,11 +190,11 @@ describe('BrokersList Component', () => {
157190
});
158191
it('opens broker when row clicked', async () => {
159192
renderComponent();
160-
await userEvent.click(screen.getByRole('cell', { name: '1' }));
193+
await userEvent.click(screen.getByRole('cell', { name: '100' }));
161194

162195
await waitFor(() =>
163196
expect(mockedUsedNavigate).toBeCalledWith(
164-
clusterBrokerPath(clusterName, '1')
197+
clusterBrokerPath(clusterName, '100')
165198
)
166199
);
167200
});

kafka-ui-react-app/src/components/common/Icons/CheckMarkRoundIcon.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const CheckMarkRoundIcon: React.FC = () => {
77
height="14"
88
viewBox="0 0 14 14"
99
fill="none"
10+
role="tooltip"
1011
xmlns="http://www.w3.org/2000/svg"
1112
>
1213
<path

kafka-ui-react-app/src/lib/fixtures/brokers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { BrokerConfig, BrokersLogdirs, ConfigSource } from 'generated-sources';
22

33
export const brokersPayload = [
4-
{ id: 1, host: 'b-1.test.kafka.amazonaws.com', port: 9092 },
5-
{ id: 2, host: 'b-2.test.kafka.amazonaws.com', port: 9092 },
4+
{ id: 100, host: 'b-1.test.kafka.amazonaws.com', port: 9092 },
5+
{ id: 200, host: 'b-2.test.kafka.amazonaws.com', port: 9092 },
66
];
77

88
const partition = {

kafka-ui-react-app/src/lib/fixtures/clusters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ export const clustersPayload: Cluster[] = [
3232

3333
export const clusterStatsPayload = {
3434
brokerCount: 2,
35-
activeControllers: 1,
35+
activeControllers: 100,
3636
onlinePartitionCount: 138,
3737
offlinePartitionCount: 0,
3838
inSyncReplicasCount: 239,
3939
outOfSyncReplicasCount: 0,
4040
underReplicatedPartitionCount: 0,
4141
diskUsage: [
42-
{ brokerId: 0, segmentSize: 334567, segmentCount: 245 },
43-
{ brokerId: 1, segmentSize: 12345678, segmentCount: 121 },
42+
{ brokerId: 100, segmentSize: 334567, segmentCount: 245 },
43+
{ brokerId: 200, segmentSize: 12345678, segmentCount: 121 },
4444
],
4545
version: '2.2.1',
4646
};

0 commit comments

Comments
 (0)