chore(explore): migrate enzyme to RTL (#26272)

This commit is contained in:
JUST.in DO IT
2024-01-30 15:16:20 -08:00
committed by GitHub
parent 63ded0fc58
commit 55846992d2
2 changed files with 208 additions and 158 deletions

View File

@@ -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 = {
@@ -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();
});
it('render null if type is not valid', () => {
render(
setup({
type: 'UnknownControl',
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});
it('render null if isVisible is false', () => {
render(
setup({
isVisible: false,
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});
it('call setControlValue if isVisible is false', () => {
const wrapper = mount(
setup({
isVisible: true,
default: false,
}),
);
wrapper.setProps({
isVisible: false,
default: false,
});
promiseTimeout(() => {
expect(defaultProps.actions.setControlValue).toBeCalled();
}, 100);
});
const checkbox = screen.getByRole('checkbox');
expect(checkbox).toBeVisible();
});
test('render null if type is not exit', () => {
render(
setup({
type: undefined,
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});
test('render null if type is not valid', () => {
render(
setup({
type: 'UnknownControl',
}),
);
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});
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,
}),
);
expect(defaultProps.actions.setControlValue).not.toBeCalled();
rerender(setup({ isVisible: false, default: false }));
await waitFor(() =>
expect(defaultProps.actions.setControlValue).toBeCalled(),
);
});