|
@@ -5,7 +5,13 @@ import ClusterContext from 'components/contexts/ClusterContext';
|
|
|
import Details from 'components/Topics/Topic/Details/Details';
|
|
|
import { internalTopicPayload } from 'redux/reducers/topics/__test__/fixtures';
|
|
|
import { render } from 'lib/testHelpers';
|
|
|
-import { clusterTopicPath } from 'lib/paths';
|
|
|
+import {
|
|
|
+ clusterTopicEditPath,
|
|
|
+ clusterTopicPath,
|
|
|
+ clusterTopicsPath,
|
|
|
+} from 'lib/paths';
|
|
|
+import { Router } from 'react-router-dom';
|
|
|
+import { createMemoryHistory } from 'history';
|
|
|
|
|
|
describe('Details', () => {
|
|
|
const mockDelete = jest.fn();
|
|
@@ -13,8 +19,20 @@ describe('Details', () => {
|
|
|
const mockClearTopicMessages = jest.fn();
|
|
|
const mockInternalTopicPayload = internalTopicPayload.internal;
|
|
|
const mockRecreateTopic = jest.fn();
|
|
|
+ const defaultPathname = clusterTopicPath(
|
|
|
+ mockClusterName,
|
|
|
+ internalTopicPayload.name
|
|
|
+ );
|
|
|
+ const mockHistory = createMemoryHistory({
|
|
|
+ initialEntries: [defaultPathname],
|
|
|
+ });
|
|
|
+ jest.spyOn(mockHistory, 'push');
|
|
|
|
|
|
- const setupComponent = (pathname: string) =>
|
|
|
+ const setupComponent = (
|
|
|
+ pathname = defaultPathname,
|
|
|
+ history = mockHistory,
|
|
|
+ props = {}
|
|
|
+ ) =>
|
|
|
render(
|
|
|
<ClusterContext.Provider
|
|
|
value={{
|
|
@@ -24,17 +42,20 @@ describe('Details', () => {
|
|
|
isTopicDeletionAllowed: true,
|
|
|
}}
|
|
|
>
|
|
|
- <Details
|
|
|
- clusterName={mockClusterName}
|
|
|
- topicName={internalTopicPayload.name}
|
|
|
- name={internalTopicPayload.name}
|
|
|
- isInternal={false}
|
|
|
- deleteTopic={mockDelete}
|
|
|
- recreateTopic={mockRecreateTopic}
|
|
|
- clearTopicMessages={mockClearTopicMessages}
|
|
|
- isDeleted={false}
|
|
|
- isDeletePolicy
|
|
|
- />
|
|
|
+ <Router history={history}>
|
|
|
+ <Details
|
|
|
+ clusterName={mockClusterName}
|
|
|
+ topicName={internalTopicPayload.name}
|
|
|
+ name={internalTopicPayload.name}
|
|
|
+ isInternal={false}
|
|
|
+ deleteTopic={mockDelete}
|
|
|
+ recreateTopic={mockRecreateTopic}
|
|
|
+ clearTopicMessages={mockClearTopicMessages}
|
|
|
+ isDeleted={false}
|
|
|
+ isDeletePolicy
|
|
|
+ {...props}
|
|
|
+ />
|
|
|
+ </Router>
|
|
|
</ClusterContext.Provider>,
|
|
|
{ pathname }
|
|
|
);
|
|
@@ -68,10 +89,83 @@ describe('Details', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ describe('when remove topic modal is open', () => {
|
|
|
+ beforeEach(() => {
|
|
|
+ setupComponent();
|
|
|
+
|
|
|
+ const openModalButton = screen.getAllByText('Remove topic')[0];
|
|
|
+ userEvent.click(openModalButton);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('calls deleteTopic on confirm', () => {
|
|
|
+ const submitButton = screen.getAllByText('Submit')[0];
|
|
|
+ userEvent.click(submitButton);
|
|
|
+
|
|
|
+ expect(mockDelete).toHaveBeenCalledWith(
|
|
|
+ mockClusterName,
|
|
|
+ internalTopicPayload.name
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ it('closes the modal when cancel button is clicked', () => {
|
|
|
+ const cancelButton = screen.getAllByText('Cancel')[0];
|
|
|
+ userEvent.click(cancelButton);
|
|
|
+
|
|
|
+ expect(cancelButton).not.toBeInTheDocument();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('when clear messages modal is open', () => {
|
|
|
+ beforeEach(() => {
|
|
|
+ setupComponent();
|
|
|
+
|
|
|
+ const confirmButton = screen.getAllByText('Clear messages')[0];
|
|
|
+ userEvent.click(confirmButton);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('it calls clearTopicMessages on confirm', () => {
|
|
|
+ const submitButton = screen.getAllByText('Submit')[0];
|
|
|
+ userEvent.click(submitButton);
|
|
|
+
|
|
|
+ expect(mockClearTopicMessages).toHaveBeenCalledWith(
|
|
|
+ mockClusterName,
|
|
|
+ internalTopicPayload.name
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ it('closes the modal when cancel button is clicked', () => {
|
|
|
+ const cancelButton = screen.getAllByText('Cancel')[0];
|
|
|
+ userEvent.click(cancelButton);
|
|
|
+
|
|
|
+ expect(cancelButton).not.toBeInTheDocument();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('when edit settings is clicked', () => {
|
|
|
+ it('redirects to the edit page', () => {
|
|
|
+ setupComponent();
|
|
|
+
|
|
|
+ const button = screen.getAllByText('Edit settings')[0];
|
|
|
+ userEvent.click(button);
|
|
|
+
|
|
|
+ const redirectRoute = clusterTopicEditPath(
|
|
|
+ mockClusterName,
|
|
|
+ internalTopicPayload.name
|
|
|
+ );
|
|
|
+
|
|
|
+ expect(mockHistory.push).toHaveBeenCalledWith(redirectRoute);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('redirects to the correct route if topic is deleted', () => {
|
|
|
+ setupComponent(defaultPathname, mockHistory, { isDeleted: true });
|
|
|
+ const redirectRoute = clusterTopicsPath(mockClusterName);
|
|
|
+
|
|
|
+ expect(mockHistory.push).toHaveBeenCalledWith(redirectRoute);
|
|
|
+ });
|
|
|
+
|
|
|
it('shows a confirmation popup on deleting topic messages', () => {
|
|
|
- setupComponent(
|
|
|
- clusterTopicPath(mockClusterName, internalTopicPayload.name)
|
|
|
- );
|
|
|
+ setupComponent();
|
|
|
const { getByText } = screen;
|
|
|
const clearMessagesButton = getByText(/Clear messages/i);
|
|
|
userEvent.click(clearMessagesButton);
|
|
@@ -82,9 +176,7 @@ describe('Details', () => {
|
|
|
});
|
|
|
|
|
|
it('shows a confirmation popup on recreating topic', () => {
|
|
|
- setupComponent(
|
|
|
- clusterTopicPath(mockClusterName, internalTopicPayload.name)
|
|
|
- );
|
|
|
+ setupComponent();
|
|
|
const recreateTopicButton = screen.getByText(/Recreate topic/i);
|
|
|
userEvent.click(recreateTopicButton);
|
|
|
|
|
@@ -94,9 +186,7 @@ describe('Details', () => {
|
|
|
});
|
|
|
|
|
|
it('calling recreation function after click on Submit button', () => {
|
|
|
- setupComponent(
|
|
|
- clusterTopicPath(mockClusterName, internalTopicPayload.name)
|
|
|
- );
|
|
|
+ setupComponent();
|
|
|
const recreateTopicButton = screen.getByText(/Recreate topic/i);
|
|
|
userEvent.click(recreateTopicButton);
|
|
|
const confirmBtn = screen.getByRole('button', { name: /submit/i });
|
|
@@ -105,9 +195,7 @@ describe('Details', () => {
|
|
|
});
|
|
|
|
|
|
it('close popup confirmation window after click on Cancel button', () => {
|
|
|
- setupComponent(
|
|
|
- clusterTopicPath(mockClusterName, internalTopicPayload.name)
|
|
|
- );
|
|
|
+ setupComponent();
|
|
|
const recreateTopicButton = screen.getByText(/Recreate topic/i);
|
|
|
userEvent.click(recreateTopicButton);
|
|
|
const cancelBtn = screen.getByRole('button', { name: /cancel/i });
|