Skip to content

Commit

Permalink
FE: Added test code for changing default value notation of ConsumerGr…
Browse files Browse the repository at this point in the history
…oups component
  • Loading branch information
K-Diger committed Dec 22, 2024
1 parent f03f496 commit 06a3cf4
Showing 1 changed file with 55 additions and 0 deletions.
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';

Check failure on line 4 in frontend/src/components/ConsumerGroups/__test__/List.spec.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

There should be at least one empty line between import groups
import List from '../List';

Check failure on line 5 in frontend/src/components/ConsumerGroups/__test__/List.spec.tsx

View workflow job for this annotation

GitHub Actions / build / build-and-test

Relative imports from parent directories are not allowed. Please either pass what you're importing through at runtime (dependency injection), move `List.spec.tsx` to same directory as `../List` or consider making `../List` a package

// 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');
});
});

0 comments on commit 06a3cf4

Please sign in to comment.