Skip to content

Commit

Permalink
chore(explore): migrate enzyme to RTL (#26272)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored Jan 30, 2024
1 parent 63ded0f commit 5584699
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 152 deletions.
93 changes: 42 additions & 51 deletions superset-frontend/src/explore/components/Control.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
import { mount } from 'enzyme';
import {
ThemeProvider,
supersetTheme,
promiseTimeout,
} from '@superset-ui/core';
import { ThemeProvider, supersetTheme } from '@superset-ui/core';
import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import { render, screen, waitFor } from 'spec/helpers/testing-library';
import Control, { ControlProps } from 'src/explore/components/Control';

const defaultProps: ControlProps = {
Expand All @@ -41,54 +36,50 @@ const setup = (overrides = {}) => (
</ThemeProvider>
);

describe('Control', () => {
it('render a control', () => {
render(setup());
test('render a control', () => {
render(setup());

const checkbox = screen.getByRole('checkbox');
expect(checkbox).toBeVisible();
});

it('render null if type is not exit', () => {
render(
setup({
type: undefined,
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});
const checkbox = screen.getByRole('checkbox');
expect(checkbox).toBeVisible();
});

it('render null if type is not valid', () => {
render(
setup({
type: 'UnknownControl',
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});
test('render null if type is not exit', () => {
render(
setup({
type: undefined,
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});

it('render null if isVisible is false', () => {
render(
setup({
isVisible: false,
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});
test('render null if type is not valid', () => {
render(
setup({
type: 'UnknownControl',
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});

it('call setControlValue if isVisible is false', () => {
const wrapper = mount(
setup({
isVisible: true,
default: false,
}),
);
wrapper.setProps({
test('render null if isVisible is false', () => {
render(
setup({
isVisible: false,
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});

test('call setControlValue if isVisible is false', async () => {
const { rerender } = render(
setup({
isVisible: true,
default: false,
});
promiseTimeout(() => {
expect(defaultProps.actions.setControlValue).toBeCalled();
}, 100);
});
}),
);
expect(defaultProps.actions.setControlValue).not.toBeCalled();
rerender(setup({ isVisible: false, default: false }));
await waitFor(() =>
expect(defaultProps.actions.setControlValue).toBeCalled(),
);
});
Loading

0 comments on commit 5584699

Please sign in to comment.