From e688084f0040d0018d14d2d12440558bd6b4bff4 Mon Sep 17 00:00:00 2001 From: Abhishek Porwal <80886271+Abhishek332@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:27:24 +0530 Subject: [PATCH] added unit test for BotsPageV1 (#15138) * added unit test for BotsPageV1 * addressed comments --- .../src/pages/BotsPageV1/BotsPageV1.test.tsx | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 openmetadata-ui/src/main/resources/ui/src/pages/BotsPageV1/BotsPageV1.test.tsx diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/BotsPageV1/BotsPageV1.test.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/BotsPageV1/BotsPageV1.test.tsx new file mode 100644 index 00000000000..1a0ff4268fe --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/pages/BotsPageV1/BotsPageV1.test.tsx @@ -0,0 +1,68 @@ +/* + * Copyright 2024 Collate. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import React from 'react'; +import BotsPageV1 from './BotsPageV1.component'; + +const mockPush = jest.fn(); + +jest.mock('react-router-dom', () => ({ + useHistory: jest.fn().mockImplementation(() => ({ + push: mockPush, + })), +})); + +jest.mock('../../components/BotListV1/BotListV1.component', () => + jest + .fn() + .mockImplementation( + ({ handleAddBotClick, handleShowDeleted, showDeleted }) => ( + <> +

{showDeleted ? 'Bot Deleted' : ''}

+ + + + ) + ) +); + +jest.mock('../../components/PageLayoutV1/PageLayoutV1', () => + jest.fn(({ children }) =>
{children}
) +); + +describe('BotsPageV1 component', () => { + it('Add bot should call mockPush', () => { + render(); + + userEvent.click(screen.getByRole('button', { name: 'Add Bot' })); + + expect(mockPush).toHaveBeenCalled(); + }); + + it('Bot deleted should not present by default', () => { + render(); + + expect(screen.queryByText('Bot Deleted')).not.toBeInTheDocument(); + }); + + it('Delete Bot button should delete bot', () => { + render(); + + expect(screen.queryByText('Bot Deleted')).not.toBeInTheDocument(); + + userEvent.click(screen.getByRole('button', { name: 'Delete Bot' })); + + expect(screen.getByText('Bot Deleted')).toBeInTheDocument(); + }); +});