|
@@ -6,16 +6,15 @@ import { externalTopicPayload, topicsPayload } from 'lib/fixtures/topics';
|
|
|
import ClusterContext from 'components/contexts/ClusterContext';
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
import {
|
|
|
+ useClearTopicMessages,
|
|
|
useDeleteTopic,
|
|
|
useRecreateTopic,
|
|
|
useTopics,
|
|
|
} from 'lib/hooks/api/topics';
|
|
|
import TopicTable from 'components/Topics/List/TopicTable';
|
|
|
import { clusterTopicsPath } from 'lib/paths';
|
|
|
-import { useAppDispatch } from 'lib/hooks/redux';
|
|
|
|
|
|
const clusterName = 'test-cluster';
|
|
|
-const unwrapMock = jest.fn();
|
|
|
|
|
|
jest.mock('lib/hooks/redux', () => ({
|
|
|
...jest.requireActual('lib/hooks/redux'),
|
|
@@ -29,22 +28,24 @@ jest.mock('lib/hooks/api/topics', () => ({
|
|
|
useDeleteTopic: jest.fn(),
|
|
|
useRecreateTopic: jest.fn(),
|
|
|
useTopics: jest.fn(),
|
|
|
+ useClearTopicMessages: jest.fn(),
|
|
|
}));
|
|
|
|
|
|
const deleteTopicMock = jest.fn();
|
|
|
const recreateTopicMock = jest.fn();
|
|
|
+const clearTopicMessages = jest.fn();
|
|
|
|
|
|
describe('TopicTable Components', () => {
|
|
|
beforeEach(() => {
|
|
|
(useDeleteTopic as jest.Mock).mockImplementation(() => ({
|
|
|
mutateAsync: deleteTopicMock,
|
|
|
}));
|
|
|
+ (useClearTopicMessages as jest.Mock).mockImplementation(() => ({
|
|
|
+ mutateAsync: clearTopicMessages,
|
|
|
+ }));
|
|
|
(useRecreateTopic as jest.Mock).mockImplementation(() => ({
|
|
|
mutateAsync: recreateTopicMock,
|
|
|
}));
|
|
|
- (useAppDispatch as jest.Mock).mockImplementation(() => () => ({
|
|
|
- unwrap: unwrapMock,
|
|
|
- }));
|
|
|
});
|
|
|
|
|
|
const renderComponent = (
|
|
@@ -185,9 +186,9 @@ describe('TopicTable Components', () => {
|
|
|
).toBeInTheDocument();
|
|
|
const confirmBtn = getButtonByName('Confirm');
|
|
|
expect(confirmBtn).toBeInTheDocument();
|
|
|
- expect(unwrapMock).not.toHaveBeenCalled();
|
|
|
+ expect(clearTopicMessages).not.toHaveBeenCalled();
|
|
|
await userEvent.click(confirmBtn);
|
|
|
- expect(unwrapMock).toHaveBeenCalledTimes(2);
|
|
|
+ expect(clearTopicMessages).toHaveBeenCalledTimes(2);
|
|
|
expect(screen.getAllByRole('checkbox')[1]).not.toBeChecked();
|
|
|
expect(screen.getAllByRole('checkbox')[2]).not.toBeChecked();
|
|
|
});
|
|
@@ -282,7 +283,7 @@ describe('TopicTable Components', () => {
|
|
|
await userEvent.click(
|
|
|
screen.getByRole('button', { name: 'Confirm' })
|
|
|
);
|
|
|
- expect(unwrapMock).toHaveBeenCalled();
|
|
|
+ expect(clearTopicMessages).toHaveBeenCalled();
|
|
|
});
|
|
|
});
|
|
|
|