mirror of
https://github.com/apache/superset.git
synced 2026-04-27 12:05:24 +00:00
feat: add empty states to sqlab editor and select (#19598)
* feat: add empty states to sqlab editor and select * add suggestions and test * update type * lint fix and add suggestions * fix typo * run lint * remove unused code * fix test * remove redux for propagation and other suggestions * add t * lint * fix text and remove code * ts and fix t in p * fix spelling * remove unused prop * add fn to prop change state * remove unused code * remove unused types * update code and test * fix lint * fix ts * update ts * add type export and fix test * Update superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> * Update superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> * Update superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> * Update superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> * remove handlerror and unused code Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
154f1ea8c9
commit
06ec88eb99
@@ -21,11 +21,12 @@ import React from 'react';
|
||||
import { render, screen, waitFor } from 'spec/helpers/testing-library';
|
||||
import { SupersetClient } from '@superset-ui/core';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import DatabaseSelector from '.';
|
||||
import DatabaseSelector, { DatabaseSelectorProps } from '.';
|
||||
import { EmptyStateSmall } from '../EmptyState';
|
||||
|
||||
const SupersetClientGet = jest.spyOn(SupersetClient, 'get');
|
||||
|
||||
const createProps = () => ({
|
||||
const createProps = (): DatabaseSelectorProps => ({
|
||||
db: {
|
||||
id: 1,
|
||||
database_name: 'test',
|
||||
@@ -38,12 +39,10 @@ const createProps = () => ({
|
||||
schema: undefined,
|
||||
sqlLabMode: true,
|
||||
getDbList: jest.fn(),
|
||||
getTableList: jest.fn(),
|
||||
handleError: jest.fn(),
|
||||
onDbChange: jest.fn(),
|
||||
onSchemaChange: jest.fn(),
|
||||
onSchemasLoad: jest.fn(),
|
||||
onUpdate: jest.fn(),
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -191,12 +190,10 @@ test('Refresh should work', async () => {
|
||||
await waitFor(() => {
|
||||
expect(SupersetClientGet).toBeCalledTimes(2);
|
||||
expect(props.getDbList).toBeCalledTimes(0);
|
||||
expect(props.getTableList).toBeCalledTimes(0);
|
||||
expect(props.handleError).toBeCalledTimes(0);
|
||||
expect(props.onDbChange).toBeCalledTimes(0);
|
||||
expect(props.onSchemaChange).toBeCalledTimes(0);
|
||||
expect(props.onSchemasLoad).toBeCalledTimes(0);
|
||||
expect(props.onUpdate).toBeCalledTimes(0);
|
||||
});
|
||||
|
||||
userEvent.click(screen.getByRole('button', { name: 'refresh' }));
|
||||
@@ -204,12 +201,10 @@ test('Refresh should work', async () => {
|
||||
await waitFor(() => {
|
||||
expect(SupersetClientGet).toBeCalledTimes(3);
|
||||
expect(props.getDbList).toBeCalledTimes(1);
|
||||
expect(props.getTableList).toBeCalledTimes(0);
|
||||
expect(props.handleError).toBeCalledTimes(0);
|
||||
expect(props.onDbChange).toBeCalledTimes(0);
|
||||
expect(props.onSchemaChange).toBeCalledTimes(0);
|
||||
expect(props.onSchemasLoad).toBeCalledTimes(2);
|
||||
expect(props.onUpdate).toBeCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -224,6 +219,28 @@ test('Should database select display options', async () => {
|
||||
expect(await screen.findByText('test-mysql')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('should show empty state if there are no options', async () => {
|
||||
SupersetClientGet.mockImplementation(
|
||||
async () => ({ json: { result: [] } } as any),
|
||||
);
|
||||
const props = createProps();
|
||||
render(
|
||||
<DatabaseSelector
|
||||
{...props}
|
||||
db={undefined}
|
||||
emptyState={<EmptyStateSmall title="empty" image="" />}
|
||||
/>,
|
||||
{ useRedux: true },
|
||||
);
|
||||
const select = screen.getByRole('combobox', {
|
||||
name: 'Select database or type database name',
|
||||
});
|
||||
userEvent.click(select);
|
||||
const emptystate = await screen.findByText('empty');
|
||||
expect(emptystate).toBeInTheDocument();
|
||||
expect(screen.queryByText('test-mysql')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Should schema select display options', async () => {
|
||||
const props = createProps();
|
||||
render(<DatabaseSelector {...props} />, { useRedux: true });
|
||||
|
||||
Reference in New Issue
Block a user