From 20d1d09512bfd61523a996a570360e217250b5ca Mon Sep 17 00:00:00 2001 From: NelyDavtyan <96067981+NelyDavtyan@users.noreply.github.com> Date: Mon, 10 Jan 2022 17:34:36 +0400 Subject: [PATCH] Added a popup warning about deleting topic messages. (#1324) * Added a popup warning about deleting topic messages. * Added test for warning popup. * Small fix. --- .../Topics/Topic/Details/Details.tsx | 12 +++++- .../Topic/Details/__test__/Details.spec.tsx | 41 +++++++++++++++++++ .../__snapshots__/Details.spec.tsx.snap | 5 +++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Details/Details.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Details/Details.tsx index 7328f8a532a..cfa97253125 100644 --- a/kafka-ui-react-app/src/components/Topics/Topic/Details/Details.tsx +++ b/kafka-ui-react-app/src/components/Topics/Topic/Details/Details.tsx @@ -59,6 +59,8 @@ const Details: React.FC = ({ React.useContext(ClusterContext); const [isDeleteTopicConfirmationVisible, setDeleteTopicConfirmationVisible] = React.useState(false); + const [isClearTopicConfirmationVisible, setClearTopicConfirmationVisible] = + React.useState(false); const deleteTopicHandler = React.useCallback(() => { deleteTopic(clusterName, topicName); }, [clusterName, topicName]); @@ -72,6 +74,7 @@ const Details: React.FC = ({ const clearTopicMessagesHandler = React.useCallback(() => { clearTopicMessages(clusterName, topicName); + setClearTopicConfirmationVisible(false); }, [clusterName, topicName]); return ( @@ -103,7 +106,7 @@ const Details: React.FC = ({ setClearTopicConfirmationVisible(true)} > Clear messages @@ -127,6 +130,13 @@ const Details: React.FC = ({ > Are you sure want to remove {topicName} topic? + setClearTopicConfirmationVisible(false)} + onConfirm={clearTopicMessagesHandler} + > + Are you sure want to clear topic messages? + { @@ -15,6 +19,30 @@ describe('Details', () => { const mockClearTopicMessages = jest.fn(); const mockInternalTopicPayload = internalTopicPayload.internal; + const setupComponent = (pathname: string) => + render( + + +
+ + + ); + describe('when it has readonly flag', () => { it('does not render the Action button a Topic', () => { const component = mount( @@ -48,4 +76,17 @@ describe('Details', () => { expect(component).toMatchSnapshot(); }); }); + + it('shows a confirmation popup on deleting topic messages', () => { + setupComponent( + clusterTopicPath(mockClusterName, internalTopicPayload.name) + ); + const { getByText } = screen; + const clearMessagesButton = getByText(/Clear messages/i); + userEvent.click(clearMessagesButton); + + expect( + getByText(/Are you sure want to clear topic messages?/i) + ).toBeInTheDocument(); + }); }); diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Details/__test__/__snapshots__/Details.spec.tsx.snap b/kafka-ui-react-app/src/components/Topics/Topic/Details/__test__/__snapshots__/Details.spec.tsx.snap index 72224186b00..6e883bec3d5 100644 --- a/kafka-ui-react-app/src/components/Topics/Topic/Details/__test__/__snapshots__/Details.spec.tsx.snap +++ b/kafka-ui-react-app/src/components/Topics/Topic/Details/__test__/__snapshots__/Details.spec.tsx.snap @@ -336,6 +336,11 @@ exports[`Details when it has readonly flag does not render the Action button a T onCancel={[Function]} onConfirm={[Function]} /> +