Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE: Consumers: Fix lag is displayed as 'N/A' in case of null value #720

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/components/ConsumerGroups/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const List = () => {
header: 'Consumer Lag',
accessorKey: 'consumerLag',
cell: (args) => {
return args.getValue() || 'N/A';
return args.getValue() ?? 'N/A';
},
},
{
Expand Down
55 changes: 55 additions & 0 deletions frontend/src/components/ConsumerGroups/__test__/List.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { screen } from '@testing-library/react';
import { render } from 'lib/testHelpers';
import { useConsumerGroups } from 'lib/hooks/api/consumers';
import List from 'components/ConsumerGroups/List';

// Mock hooks
jest.mock('lib/hooks/api/consumers', () => ({
useConsumerGroups: jest.fn(),
}));

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useSearchParams: () => [new URLSearchParams(), jest.fn()],
useNavigate: () => jest.fn(),
}));

const mockUseConsumerGroups = useConsumerGroups as jest.Mock;

describe('ConsumerGroups List', () => {
beforeEach(() => {
mockUseConsumerGroups.mockImplementation(() => ({
data: {
consumerGroups: [
{
groupId: 'group1',
consumerLag: 0,
members: 1,
topics: 1,
coordinator: { id: 1 },
state: 'STABLE',
},
{
groupId: 'group2',
consumerLag: null,
members: 1,
topics: 1,
coordinator: { id: 2 },
state: 'STABLE',
},
],
pageCount: 1,
},
isSuccess: true,
isFetching: false,
}));
});

it('renders consumer lag values correctly', () => {
render(<List />);
const tableRows = screen.getAllByRole('row');
expect(tableRows[1]).toHaveTextContent('0');
expect(tableRows[2]).toHaveTextContent('N/A');
});
});
Loading