chore: Working toward killing enzyme and cleaning up test noise. (#32207)

This commit is contained in:
Evan Rusackas
2025-02-11 12:14:36 -07:00
committed by GitHub
parent d3b854a833
commit 319a860f23
238 changed files with 4167 additions and 6334 deletions

View File

@@ -17,8 +17,14 @@
* under the License.
*/
import { ReactChild } from 'react';
import { render, screen, waitFor, within } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import {
cleanup,
render,
screen,
userEvent,
waitFor,
within,
} from 'spec/helpers/testing-library';
import DatasourcePanel, {
IDatasource,
Props as DatasourcePanelProps,
@@ -111,6 +117,7 @@ test('should display items in controls', async () => {
});
test('should render the metrics', async () => {
jest.setTimeout(10000);
render(
<ExploreContainer>
<DatasourcePanel {...props} />
@@ -144,30 +151,45 @@ test('should render the columns', async () => {
).toBeInTheDocument();
});
test('should render 0 search results', async () => {
render(<DatasourcePanel {...props} />, { useRedux: true, useDnd: true });
const searchInput = screen.getByPlaceholderText('Search Metrics & Columns');
search('nothing', searchInput);
expect(await screen.findAllByText('Showing 0 of 0')).toHaveLength(2);
});
test('should search and render matching columns', async () => {
render(
<ExploreContainer>
<DatasourcePanel {...props} />
<DndMetricSelect {...metricProps} />
</ExploreContainer>,
{ useRedux: true, useDnd: true },
);
const searchInput = screen.getByPlaceholderText('Search Metrics & Columns');
search(columns[0].column_name, searchInput);
await waitFor(() => {
expect(screen.getByText(columns[0].column_name)).toBeInTheDocument();
expect(screen.queryByText(columns[1].column_name)).not.toBeInTheDocument();
describe('DatasourcePanel', () => {
beforeAll(() => {
jest.setTimeout(30000);
});
afterEach(async () => {
cleanup();
await new Promise(resolve => setTimeout(resolve, 0));
});
test('should search and render matching columns', async () => {
const { unmount } = render(
<ExploreContainer>
<DatasourcePanel {...props} />
<DndMetricSelect {...metricProps} />
</ExploreContainer>,
{ useRedux: true, useDnd: true },
);
const searchInput = screen.getByPlaceholderText('Search Metrics & Columns');
await waitFor(() => {
expect(searchInput).toBeInTheDocument();
});
search(columns[0].column_name, searchInput);
await waitFor(
() => {
expect(screen.getByText(columns[0].column_name)).toBeInTheDocument();
expect(
screen.queryByText(columns[1].column_name),
).not.toBeInTheDocument();
},
{ timeout: 10000 },
);
unmount();
}, 15000);
});
test('should search and render matching metrics', async () => {
@@ -261,7 +283,7 @@ test('should render only droppable metrics and columns', async () => {
],
actions: { setControlValue: jest.fn() },
};
const { getByTestId } = render(
const { getByTestId, unmount } = render(
<ExploreContainer>
<DatasourcePanel {...props} />
<DndColumnSelect {...column1FilterProps} />
@@ -269,14 +291,22 @@ test('should render only droppable metrics and columns', async () => {
</ExploreContainer>,
{ useRedux: true, useDnd: true },
);
const selections = getByTestId('fieldSelections');
expect(
within(selections).queryByText(columns[0].column_name),
).not.toBeInTheDocument();
expect(
within(selections).queryByText(columns[1].column_name),
).toBeInTheDocument();
expect(
within(selections).queryByText(columns[2].column_name),
).toBeInTheDocument();
await waitFor(
() => {
const selections = getByTestId('fieldSelections');
expect(
within(selections).queryByText(columns[0].column_name),
).not.toBeInTheDocument();
expect(
within(selections).getByText(columns[1].column_name),
).toBeInTheDocument();
expect(
within(selections).getByText(columns[2].column_name),
).toBeInTheDocument();
},
{ timeout: 10000 },
);
unmount();
});