Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix act errors in LeftPanel test #21383

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { SupersetClient } from '@superset-ui/core';
import userEvent from '@testing-library/user-event';
import { render, screen, waitFor } from 'spec/helpers/testing-library';
import LeftPanel from 'src/views/CRUD/data/dataset/AddDataset/LeftPanel';
import { act } from 'react-dom/test-utils';

describe('LeftPanel', () => {
const mockFun = jest.fn();
Expand Down Expand Up @@ -160,17 +159,21 @@ describe('LeftPanel', () => {
},
} as any);

it('should render', () => {
test('should render', async () => {
const { container } = render(<LeftPanel setDataset={mockFun} />, {
useRedux: true,
});

expect(
await screen.findByText(/select database & schema/i),
).toBeInTheDocument();
expect(container).toBeInTheDocument();
});

it('should render tableselector and databaselector container and selects', () => {
test('should render tableselector and databaselector container and selects', async () => {
render(<LeftPanel setDataset={mockFun} />, { useRedux: true });

expect(screen.getByText(/select database & schema/i)).toBeVisible();
expect(await screen.findByText(/select database & schema/i)).toBeVisible();

const databaseSelect = screen.getByRole('combobox', {
name: 'Select database or type database name',
Expand All @@ -181,12 +184,18 @@ describe('LeftPanel', () => {
expect(databaseSelect).toBeInTheDocument();
expect(schemaSelect).toBeInTheDocument();
});
it('does not render blank state if there is nothing selected', () => {

test('does not render blank state if there is nothing selected', async () => {
render(<LeftPanel setDataset={mockFun} />, { useRedux: true });

expect(
await screen.findByText(/select database & schema/i),
).toBeInTheDocument();
const emptyState = screen.queryByRole('img', { name: /empty/i });
expect(emptyState).not.toBeInTheDocument();
});
it('renders list of options when user clicks on schema', async () => {

test('renders list of options when user clicks on schema', async () => {
render(<LeftPanel setDataset={mockFun} schema="schema_a" dbId={1} />, {
useRedux: true,
});
Expand All @@ -197,9 +206,7 @@ describe('LeftPanel', () => {
userEvent.click(databaseSelect);
expect(await screen.findByText('test-postgres')).toBeInTheDocument();

act(() => {
userEvent.click(screen.getAllByText('test-postgres')[0]);
});
userEvent.click(screen.getAllByText('test-postgres')[0]);
const tableSelect = screen.getByRole('combobox', {
name: /select schema or type schema name/i,
});
Expand All @@ -217,11 +224,9 @@ describe('LeftPanel', () => {
).toBeInTheDocument();

SupersetClientGet.mockImplementation(getTableMockFunction);
act(() => {
userEvent.click(screen.getAllByText('public')[1]);
});

// Todo: (Phillip) finish testing for showing list of options once table is implemented
// userEvent.click(screen.getAllByText('public')[1]);
// expect(screen.getByTestId('options-list')).toBeInTheDocument();
});
});