Skip to content

Commit

Permalink
Add tests for conditional rendering of data connection tabs
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Apr 29, 2024
1 parent 751fa52 commit 6ef7372
Showing 1 changed file with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(<DataConnection dataSource="PROMETHEUS" />);

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(<DataConnection dataSource="S3GLUE" />);

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);
});
});
});

0 comments on commit 6ef7372

Please sign in to comment.