From 6ef73722885478cbe86c2b36aa74184ff71b2781 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Mon, 1 Apr 2024 22:50:38 -0700 Subject: [PATCH] Add tests for conditional rendering of data connection tabs Signed-off-by: Ryan Liang --- .../__tests__/data_connection.test.tsx | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/public/components/datasources/components/__tests__/data_connection.test.tsx b/public/components/datasources/components/__tests__/data_connection.test.tsx index 32f30a6a8..51bfe867c 100644 --- a/public/components/datasources/components/__tests__/data_connection.test.tsx +++ b/public/components/datasources/components/__tests__/data_connection.test.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { act } from '@testing-library/react'; +import { act, render, waitFor } from '@testing-library/react'; import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import React from 'react'; @@ -65,4 +65,44 @@ describe('Data Connection Page test', () => { }); expect(container).toMatchSnapshot(); }); + + it('Does not render Associated Objects, Accelerations, and Installed Integrations tabs for Prometheus data source', async () => { + CatalogCacheManager.saveDataSourceCache(mockDataSourceCacheData); + CatalogCacheManager.saveAccelerationsCache(mockAccelerationCacheData); + + (coreRefs.http!.get as jest.Mock).mockResolvedValue(describePrometheusDataConnection); + + const { container, queryByText } = render(); + + await waitFor(() => { + expect(queryByText('Associated Objects')).not.toBeInTheDocument(); + expect(queryByText('Accelerations')).not.toBeInTheDocument(); + expect(queryByText('Installed Integrations')).not.toBeInTheDocument(); + + const accessControlTabs = Array.from(container.querySelectorAll('.euiTab__content')).filter( + (el) => el.textContent === 'Access control' + ); + expect(accessControlTabs.length).toBeGreaterThan(0); + }); + }); + + it('Renders all tabs for S3Glue data source', async () => { + CatalogCacheManager.saveDataSourceCache(mockDataSourceCacheData); + CatalogCacheManager.saveAccelerationsCache(mockAccelerationCacheData); + + (coreRefs.http!.get as jest.Mock).mockResolvedValue(describeS3Dataconnection); + + const { container, getByText } = render(); + + await waitFor(() => { + expect(getByText('Associated Objects')).toBeInTheDocument(); + expect(getByText('Accelerations')).toBeInTheDocument(); + expect(getByText('Installed Integrations')).toBeInTheDocument(); + + const accessControlTabs = Array.from(container.querySelectorAll('.euiTab__content')).filter( + (el) => el.textContent === 'Access control' + ); + expect(accessControlTabs.length).toBeGreaterThan(0); + }); + }); });