diff --git a/catalog-rest-service/src/main/resources/ui/src/components/Modals/AddServiceModal/AddServiceModal.test.tsx b/catalog-rest-service/src/main/resources/ui/src/components/Modals/AddServiceModal/AddServiceModal.test.tsx index 64fe5d93d5e..e66fef8264d 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/Modals/AddServiceModal/AddServiceModal.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/Modals/AddServiceModal/AddServiceModal.test.tsx @@ -5,12 +5,10 @@ import { render, } from '@testing-library/react'; import React from 'react'; -import { AddServiceModal } from './AddServiceModal'; +import { AddServiceModal, ServiceDataObj } from './AddServiceModal'; const mockData = { - connectionUrl: 'string', description: 'string', - driverClass: 'string', href: 'string', id: 'string', jdbc: { driverClass: 'string', connectionUrl: 'string' }, @@ -22,7 +20,7 @@ const mockData = { const mockOnSave = jest.fn(); const mockOnCancel = jest.fn(); -const mockServiceList = [mockData, mockData, mockData]; +const mockServiceList: Array = [{ name: mockData.name }]; jest.mock('../../common/editor/MarkdownWithPreview', () => { return jest @@ -68,29 +66,7 @@ describe('Test AddServiceModal Component', () => { expect(mockOnCancel).toBeCalledTimes(1); }); - it('on click of cancel onCancel should be call', async () => { - const { container } = render( - - ); - const cancel = await findByTestId(container, 'cancel'); - fireEvent.click( - cancel, - new MouseEvent('click', { - bubbles: true, - cancelable: true, - }) - ); - - expect(mockOnCancel).toBeCalledTimes(1); - }); - - it('form with all the fild should render', async () => { + it('form with all the Field should render for databaseService', async () => { const { container } = render( { const selectService = await findByTestId(container, 'selectService'); const name = await findByTestId(container, 'name'); const url = await findByTestId(container, 'url'); - // const port = await findByTestId(container, 'port'); - // const userName = await findByTestId(container, 'userName'); - // const password = await findByTestId(container, 'password'); const database = await findByTestId(container, 'database'); const driverClass = await findByTestId(container, 'driverClass'); const description = await findByTestId(container, 'description'); @@ -116,9 +89,6 @@ describe('Test AddServiceModal Component', () => { expect(selectService).toBeInTheDocument(); expect(name).toBeInTheDocument(); expect(url).toBeInTheDocument(); - // expect(port).toBeInTheDocument(); - // expect(userName).toBeInTheDocument(); - // expect(password).toBeInTheDocument(); expect(database).toBeInTheDocument(); expect(driverClass).toBeInTheDocument(); expect(description).toBeInTheDocument(); @@ -128,6 +98,68 @@ describe('Test AddServiceModal Component', () => { expect(queryByText(container, /minute/i)).not.toBeInTheDocument(); }); + it('form with all the Field should render for dashboardServices', async () => { + const { container } = render( + + ); + const form = await findByTestId(container, 'form'); + const selectService = await findByTestId(container, 'selectService'); + const name = await findByTestId(container, 'name'); + const url = await findByTestId(container, 'dashboard-url'); + const userName = await findByTestId(container, 'username'); + const password = await findByTestId(container, 'password'); + const description = await findByTestId(container, 'description'); + const ingestionSwitch = await findByTestId(container, 'ingestion-switch'); + + expect(form).toBeInTheDocument(); + expect(selectService).toBeInTheDocument(); + expect(name).toBeInTheDocument(); + expect(url).toBeInTheDocument(); + expect(userName).toBeInTheDocument(); + expect(password).toBeInTheDocument(); + expect(description).toBeInTheDocument(); + expect(ingestionSwitch).toBeInTheDocument(); + expect(queryByText(container, /day/i)).not.toBeInTheDocument(); + expect(queryByText(container, /hour/i)).not.toBeInTheDocument(); + expect(queryByText(container, /minute/i)).not.toBeInTheDocument(); + }); + + it('form with all the Field should render for messagingServices', async () => { + const { container } = render( + + ); + const form = await findByTestId(container, 'form'); + const selectService = await findByTestId(container, 'selectService'); + const name = await findByTestId(container, 'name'); + const url = await findByTestId(container, 'broker-url'); + const schemaRegistry = await findByTestId(container, 'schema-registry'); + const description = await findByTestId(container, 'description'); + const ingestionSwitch = await findByTestId(container, 'ingestion-switch'); + + expect(form).toBeInTheDocument(); + expect(selectService).toBeInTheDocument(); + expect(name).toBeInTheDocument(); + expect(url).toBeInTheDocument(); + expect(schemaRegistry).toBeInTheDocument(); + expect(description).toBeInTheDocument(); + expect(ingestionSwitch).toBeInTheDocument(); + expect(queryByText(container, /day/i)).not.toBeInTheDocument(); + expect(queryByText(container, /hour/i)).not.toBeInTheDocument(); + expect(queryByText(container, /minute/i)).not.toBeInTheDocument(); + }); + it('frequency fileds should be visible when ingestionSwitch is on', async () => { const { container } = render( { target: { value: 'test.123' }, }); - // const port = await findByTestId(container, 'port'); - - // fireEvent.change(port, { - // target: { value: 123 }, - // }); - - // const userName = await findByTestId(container, 'userName'); - - // fireEvent.change(userName, { - // target: { value: 'testUser' }, - // }); - - // const password = await findByTestId(container, 'password'); - - // fireEvent.change(password, { - // target: { value: 'testPwd' }, - // }); - const database = await findByTestId(container, 'database'); fireEvent.change(database, { @@ -270,9 +284,6 @@ describe('Test AddServiceModal Component', () => { expect(selectService).toHaveValue('MySQL'); expect(name).toHaveValue('test'); expect(url).toHaveValue('test.123'); - // expect(port).toHaveValue(123); - // expect(userName).toHaveValue('testUser'); - // expect(password).toHaveValue('testPwd'); expect(database).toHaveValue('testdb'); expect(driverClass).toHaveValue('jdbc'); expect(frequency).toHaveValue('1'); diff --git a/catalog-rest-service/src/main/resources/ui/src/components/Modals/AddServiceModal/AddServiceModal.tsx b/catalog-rest-service/src/main/resources/ui/src/components/Modals/AddServiceModal/AddServiceModal.tsx index 51005f97bcb..c2794c3e793 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/Modals/AddServiceModal/AddServiceModal.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/Modals/AddServiceModal/AddServiceModal.tsx @@ -568,6 +568,7 @@ export const AddServiceModal: FunctionComponent = ({ = ({ = ({ = ({ = ({ ({ getServiceDetails: jest .fn() .mockImplementation(() => Promise.resolve({ data: mockServiceDetails })), - getServices: jest.fn().mockImplementation(() => Promise.resolve(mockService)), + getServices: jest.fn().mockImplementation((type) => { + switch (type) { + case 'databaseServices': + return Promise.resolve(mockDatabaseService); + + case 'messagingServices': + return Promise.resolve(mockMessagingService); + + default: + return Promise.resolve(mockDashboardService); + } + }), postService: jest.fn(), updateService: jest.fn(), })); @@ -66,13 +141,122 @@ jest.mock( } ); +jest.mock('../../components/common/non-admin-action/NonAdminAction', () => { + return jest + .fn() + .mockImplementation(({ children }: { children: ReactNode }) => ( +
{children}
+ )); +}); + +jest.mock('../../components/Modals/AddServiceModal/AddServiceModal', () => ({ + AddServiceModal: jest + .fn() + .mockReturnValue(

AddServiceModal

), +})); + describe('Test Service page', () => { it('Check if there is an element in the page', async () => { const { container } = render(, { wrapper: MemoryRouter, }); const services = await findByTestId(container, 'services-container'); + const tabs = await findAllByTestId(container, 'tab'); + const dataContainer = await findByTestId(container, 'data-container'); expect(services).toBeInTheDocument(); + expect(tabs.length).toBe(mockServiceDetails.data.length); + expect(dataContainer).toBeInTheDocument(); + + // mockService.data.data.length + 1 because it has add service card as well + expect(dataContainer.childElementCount).toBe( + mockDatabaseService.data.data.length + 1 + ); + }); + + it('On page load database service should be active tab with corresponding data', async () => { + const { container } = render(, { + wrapper: MemoryRouter, + }); + const tabs = await findAllByTestId(container, 'tab'); + const serviceNames = await findAllByTestId(container, 'service-name'); + + expect(tabs[0]).toHaveClass('active'); + expect(serviceNames.map((s) => s.textContent)).toEqual( + mockDatabaseService.data.data.map((d) => d.name) + ); + }); + + it('OnClick tab and data should change', async () => { + const { container } = render(, { + wrapper: MemoryRouter, + }); + let tabs = await findAllByTestId(container, 'tab'); + + expect(tabs[0]).toHaveClass('active'); + + fireEvent.click(tabs[1]); + tabs = await findAllByTestId(container, 'tab'); + const serviceNames = await findAllByTestId(container, 'service-name'); + + expect(tabs[1]).toHaveClass('active'); + expect(serviceNames.map((s) => s.textContent)).toEqual( + mockMessagingService.data.data.map((d) => d.name) + ); + }); + + it('OnClick of add service, AddServiceModal should open', async () => { + const { container } = render(, { + wrapper: MemoryRouter, + }); + const addService = await findByTestId(container, 'add-services'); + fireEvent.click(addService); + + expect( + await findByTestId(container, 'add-service-modal') + ).toBeInTheDocument(); + }); + + it('OnClick of edit service, AddServiceModal should open', async () => { + const { container } = render(, { + wrapper: MemoryRouter, + }); + const editService = await findAllByTestId(container, 'edit-service'); + fireEvent.click(editService[0]); + + expect( + await findByTestId(container, 'add-service-modal') + ).toBeInTheDocument(); + }); + + it('Card details should be display properly', async () => { + const { container } = render(, { + wrapper: MemoryRouter, + }); + const serviceName = await findAllByTestId(container, 'service-name'); + const serviceDescription = await findAllByTestId( + container, + 'service-description' + ); + const additionalField = await findAllByTestId( + container, + 'additional-field' + ); + const ingestion = await findAllByTestId(container, 'service-ingestion'); + const type = await findAllByTestId(container, 'service-type'); + const edit = await findAllByTestId(container, 'edit-service'); + const deleteIcon = await findAllByTestId(container, 'delete-service'); + const icon = await findAllByTestId(container, 'service-icon'); + + expect(serviceName.length).toBe(mockDatabaseService.data.data.length); + expect(serviceDescription.length).toBe( + mockDatabaseService.data.data.length + ); + expect(additionalField.length).toBe(mockDatabaseService.data.data.length); + expect(ingestion.length).toBe(mockDatabaseService.data.data.length); + expect(type.length).toBe(mockDatabaseService.data.data.length); + expect(edit.length).toBe(mockDatabaseService.data.data.length); + expect(deleteIcon.length).toBe(mockDatabaseService.data.data.length); + expect(icon.length).toBe(mockDatabaseService.data.data.length); }); }); diff --git a/catalog-rest-service/src/main/resources/ui/src/pages/services/index.tsx b/catalog-rest-service/src/main/resources/ui/src/pages/services/index.tsx index 2cda191bb22..a5175a5b8ba 100644 --- a/catalog-rest-service/src/main/resources/ui/src/pages/services/index.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/pages/services/index.tsx @@ -226,7 +226,7 @@ const ServicesPage = () => { return ( <> -
+
{databaseService.jdbc.driverClass} @@ -240,7 +240,7 @@ const ServicesPage = () => { return ( <> -
+
{messagingService.brokers.join(', ')} @@ -254,7 +254,7 @@ const ServicesPage = () => { return ( <> -
+