chore: Removes icon warnings from tests (#23054)

This commit is contained in:
Michael S. Molina 2023-02-13 12:31:09 -05:00 committed by GitHub
parent d3d59ee0ae
commit 49aa9b4ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 43 additions and 122 deletions

View File

@ -89,4 +89,34 @@ jest.mock('react-markdown', () => (props: any) => <>{props.children}</>);
jest.mock('rehype-sanitize', () => () => jest.fn());
jest.mock('rehype-raw', () => () => jest.fn());
// Mocks the Icon component due to its async nature
// Tests should override this when needed
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({
fileName,
role,
'aria-label': ariaLabel,
...rest
}: {
fileName: string;
role: string;
'aria-label': React.AriaAttributes['aria-label'];
}) => (
<span
role={role ?? 'img'}
aria-label={ariaLabel || fileName.replace('_', '-')}
{...rest}
/>
),
StyledIcon: ({
role,
'aria-label': ariaLabel,
...rest
}: {
role: string;
'aria-label': React.AriaAttributes['aria-label'];
}) => <span role={role ?? 'img'} aria-label={ariaLabel} {...rest} />,
}));
process.env.WEBPACK_MODE = 'test';

View File

@ -42,9 +42,6 @@ jest.mock('src/components/Select/Select', () => () => (
jest.mock('src/components/Select/AsyncSelect', () => () => (
<div data-test="mock-deprecated-async-select" />
));
jest.mock('src/components/Icons/Icon', () => () => (
<div data-test="mock-icons-icon" />
));
const defaultQueryLimit = 100;

View File

@ -33,8 +33,6 @@ import {
fakePluginControls,
} from './AlteredSliceTagMocks';
jest.mock('src/components/Icons/Icon', () => () => <span />);
const getTableWrapperFromModalBody = modalBody =>
modalBody.find(TableView).find(TableCollection);

View File

@ -24,18 +24,6 @@ import DatasourceEditor from 'src/components/Datasource/DatasourceEditor';
import mockDatasource from 'spec/fixtures/mockDatasource';
import * as featureFlags from 'src/featureFlags';
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({ fileName, role, ...rest }) => (
<span
role={role ?? 'img'}
aria-label={fileName.replace('_', '-')}
{...rest}
/>
),
StyledIcon: () => <span />,
}));
const props = {
datasource: mockDatasource['7__table'],
addSuccessToast: () => {},

View File

@ -20,8 +20,6 @@ import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import ErrorBoundary from '.';
jest.mock('src/components/Icons/Icon', () => () => <span />);
const mockedProps = {
children: <span>Error children</span>,
onError: () => null,

View File

@ -35,12 +35,6 @@ import Pagination from 'src/components/Pagination/Wrapper';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: () => <span />,
StyledIcon: () => <span />,
}));
function makeMockLocation(query) {
const queryStr = encodeURIComponent(query);
return {

View File

@ -23,8 +23,6 @@ import Toast from 'src/components/MessageToasts/Toast';
import { act } from 'react-dom/test-utils';
import mockMessageToasts from './mockMessageToasts';
jest.mock('src/components/Icons/Icon', () => () => <span />);
const props = {
toast: mockMessageToasts[0],
onCloseToast() {},

View File

@ -23,8 +23,6 @@ import userEvent from '@testing-library/user-event';
import { PageHeaderWithActions, PageHeaderWithActionsProps } from './index';
import { Menu } from '../Menu';
jest.mock('src/components/Icons/Icon', () => () => <span />);
const defaultProps: PageHeaderWithActionsProps = {
editableTitleProps: {
title: 'Test title',

View File

@ -24,12 +24,6 @@ import HeaderReportDropdown, { HeaderReportProps } from '.';
let isFeatureEnabledMock: jest.MockInstance<boolean, [string]>;
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: () => <span />,
StyledIcon: () => <span />,
}));
const createProps = () => ({
dashboardId: 1,
useTextMenu: false,

View File

@ -33,12 +33,6 @@ fetchMock.get(REPORT_ENDPOINT, {});
const NOOP = () => {};
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: () => <span />,
StyledIcon: () => <span />,
}));
const defaultProps = {
addDangerToast: NOOP,
addSuccessToast: NOOP,

View File

@ -511,9 +511,9 @@ const AsyncSelect = forwardRef(
suffixIcon={getSuffixIcon(isLoading, showSearch, isDropdownVisible)}
menuItemSelectedIcon={
invertSelection ? (
<StyledStopOutlined iconSize="m" />
<StyledStopOutlined iconSize="m" aria-label="stop" />
) : (
<StyledCheckOutlined iconSize="m" />
<StyledCheckOutlined iconSize="m" aria-label="check" />
)
}
oneLine={oneLine}

View File

@ -486,9 +486,9 @@ const Select = forwardRef(
)}
menuItemSelectedIcon={
invertSelection ? (
<StyledStopOutlined iconSize="m" />
<StyledStopOutlined iconSize="m" aria-label="stop" />
) : (
<StyledCheckOutlined iconSize="m" />
<StyledCheckOutlined iconSize="m" aria-label="check" />
)
}
oneLine={oneLine}

View File

@ -44,8 +44,6 @@ const mockedProps: TableViewProps = {
pageSize: 1,
};
jest.mock('src/components/Icons/Icon', () => () => <span />);
test('should render', () => {
const { container } = render(<TableView {...mockedProps} />);
expect(container).toBeInTheDocument();

View File

@ -49,9 +49,6 @@ jest.mock('src/featureFlags');
jest.mock('src/components/ResizableSidebar/useStoredSidebarWidth');
// mock following dependant components to fix the prop warnings
jest.mock('src/components/Icons/Icon', () => () => (
<div data-test="mock-icon" />
));
jest.mock('src/components/DeprecatedSelect/WindowedSelect', () => () => (
<div data-test="mock-windowed-select" />
));

View File

@ -27,25 +27,6 @@ import DatasourceControl from '.';
const SupersetClientGet = jest.spyOn(SupersetClient, 'get');
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({
fileName,
role,
...rest
}: {
fileName: string;
role: string;
}) => (
<span
role={role ?? 'img'}
aria-label={fileName.replace('_', '-')}
{...rest}
/>
),
StyledIcon: () => <span />,
}));
const createProps = (overrides: JsonObject = {}) => ({
hovered: false,
type: 'DatasourceControl',

View File

@ -30,14 +30,6 @@ import { DndMetricSelect } from 'src/explore/components/controls/DndColumnSelect
import { AGGREGATES } from 'src/explore/constants';
import { EXPRESSION_TYPES } from '../MetricControl/AdhocMetric';
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({ fileName }: { fileName: string }) => (
<span role="img" aria-label={fileName.replace('_', '-')} />
),
StyledIcon: () => <span />,
}));
const defaultProps = {
savedMetrics: [
{

View File

@ -25,14 +25,6 @@ import AdhocFilter, {
} from 'src/explore/components/controls/FilterControl/AdhocFilter';
import AdhocFilterOption, { AdhocFilterOptionProps } from '.';
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({ fileName, role }: { fileName: string; role: string }) => (
<span role={role ?? 'img'} aria-label={fileName.replace('_', '-')} />
),
StyledIcon: () => <span />,
}));
const simpleAdhocFilter = new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: 'value',

View File

@ -213,7 +213,9 @@ export const FastVizSwitcher = React.memo(
) {
vizTiles.unshift({
name: currentSelection,
icon: <Icons.MonitorOutlined {...antdIconProps} />,
icon: (
<Icons.MonitorOutlined {...antdIconProps} aria-label="monitor" />
),
});
}
if (
@ -224,7 +226,12 @@ export const FastVizSwitcher = React.memo(
) {
vizTiles.unshift({
name: currentViz,
icon: <Icons.CheckSquareOutlined {...antdIconProps} />,
icon: (
<Icons.CheckSquareOutlined
{...antdIconProps}
aria-label="check-square"
/>
),
});
}
return vizTiles;

View File

@ -64,14 +64,6 @@ jest.mock('react-redux', () => ({
useSelector: jest.fn(),
}));
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({ fileName, role }) => (
<span role={role ?? 'img'} aria-label={fileName.replace('_', '-')} />
),
StyledIcon: () => <span />,
}));
fetchMock.get(databasesInfoEndpoint, {
permissions: ['can_write'],
});

View File

@ -45,25 +45,6 @@ jest.mock('@superset-ui/core', () => ({
isFeatureEnabled: () => true,
}));
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({
fileName,
role,
...rest
}: {
fileName: string;
role: string;
}) => (
<span
role={role ?? 'img'}
aria-label={fileName.replace('_', '-')}
{...rest}
/>
),
StyledIcon: () => <span />,
}));
const mockHistoryPush = jest.fn();
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),

View File

@ -35,14 +35,6 @@ import SyntaxHighlighter from 'react-syntax-highlighter/dist/cjs/light';
import SubMenu from 'src/views/components/SubMenu';
import { QueryState } from '@superset-ui/core';
jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({ fileName, role }: { fileName: string; role: string }) => (
<span role={role ?? 'img'} aria-label={fileName.replace('_', '-')} />
),
StyledIcon: () => <span />,
}));
// store needed for withToasts
const mockStore = configureStore([thunk]);
const store = mockStore({});