Skip to content

Commit

Permalink
chore: Removes icon warnings from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Feb 9, 2023
1 parent 5e64211 commit 345264d
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 122 deletions.
30 changes: 30 additions & 0 deletions superset-frontend/spec/helpers/shim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import {
fakePluginControls,
} from './AlteredSliceTagMocks';

jest.mock('src/components/Icons/Icon', () => () => <span />);

const getTableWrapperFromModalBody = modalBody =>
modalBody.find(TableView).find(TableCollection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions superset-frontend/src/components/ListView/ListView.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions superset-frontend/src/components/MessageToasts/Toast.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/components/Select/AsyncSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 0 additions & 2 deletions superset-frontend/src/components/TableView/TableView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down

0 comments on commit 345264d

Please sign in to comment.