refactor: Upgrade to React 17 (#31961)

This commit is contained in:
Kamil Gabryjelski
2025-01-28 16:44:42 +01:00
committed by GitHub
parent aa74ba3da2
commit 7e2b7941f3
101 changed files with 18988 additions and 61350 deletions

View File

@@ -17,8 +17,7 @@
* under the License.
*/
import fetchMock from 'fetch-mock';
import * as uiCore from '@superset-ui/core';
import { FeatureFlag, QueryState } from '@superset-ui/core';
import { FeatureFlag, isFeatureEnabled, QueryState } from '@superset-ui/core';
import { render, screen, waitFor } from 'spec/helpers/testing-library';
import QueryHistory from 'src/SqlLab/components/QueryHistory';
import { initialState } from 'src/SqlLab/fixtures';
@@ -67,6 +66,13 @@ const fakeApiResult = {
],
};
jest.mock('@superset-ui/core', () => ({
...jest.requireActual('@superset-ui/core'),
isFeatureEnabled: jest.fn(),
}));
const mockedIsFeatureEnabled = isFeatureEnabled as jest.Mock;
const setup = (overrides = {}) => (
<QueryHistory {...mockedProps} {...overrides} />
);
@@ -82,11 +88,9 @@ test('Renders an empty state for query history', () => {
});
test('fetches the query history when the persistence mode is enabled', async () => {
const isFeatureEnabledMock = jest
.spyOn(uiCore, 'isFeatureEnabled')
.mockImplementation(
featureFlag => featureFlag === FeatureFlag.SqllabBackendPersistence,
);
const isFeatureEnabledMock = mockedIsFeatureEnabled.mockImplementation(
featureFlag => featureFlag === FeatureFlag.SqllabBackendPersistence,
);
const editorQueryApiRoute = `glob:*/api/v1/query/?q=*`;
fetchMock.get(editorQueryApiRoute, fakeApiResult);

View File

@@ -20,9 +20,12 @@ import { FC } from 'react';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock from 'fetch-mock';
import * as uiCore from '@superset-ui/core';
import { Provider } from 'react-redux';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import {
supersetTheme,
ThemeProvider,
isFeatureEnabled,
} from '@superset-ui/core';
import { render, screen, act, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
@@ -56,7 +59,13 @@ const mockState = {
},
};
const store = mockStore(mockState);
let isFeatureEnabledMock: jest.SpyInstance;
jest.mock('@superset-ui/core', () => ({
...jest.requireActual('@superset-ui/core'),
isFeatureEnabled: jest.fn(),
}));
const mockedIsFeatureEnabled = isFeatureEnabled as jest.Mock;
const standardProvider: FC = ({ children }) => (
<ThemeProvider theme={supersetTheme}>
@@ -110,13 +119,11 @@ describe('ShareSqlLabQuery', () => {
describe('via permalink api', () => {
beforeAll(() => {
isFeatureEnabledMock = jest
.spyOn(uiCore, 'isFeatureEnabled')
.mockImplementation(() => true);
mockedIsFeatureEnabled.mockImplementation(() => true);
});
afterAll(() => {
isFeatureEnabledMock.mockReset();
mockedIsFeatureEnabled.mockReset();
});
it('calls storeQuery() with the query when getCopyUrl() is called', async () => {

View File

@@ -17,8 +17,12 @@
* under the License.
*/
import { FocusEventHandler } from 'react';
import * as uiCore from '@superset-ui/core';
import { act } from 'react-dom/test-utils';
import {
isFeatureEnabled,
getExtensionsRegistry,
FeatureFlag,
} from '@superset-ui/core';
import { fireEvent, render, waitFor } from 'spec/helpers/testing-library';
import fetchMock from 'fetch-mock';
import reducers from 'spec/helpers/reducerIndex';
@@ -32,7 +36,6 @@ import {
import SqlEditorLeftBar from 'src/SqlLab/components/SqlEditorLeftBar';
import ResultSet from 'src/SqlLab/components/ResultSet';
import { api } from 'src/hooks/apiResources/queryApi';
import { getExtensionsRegistry, FeatureFlag } from '@superset-ui/core';
import setupExtensions from 'src/setup/setupExtensions';
import type { Action, Middleware, Store } from 'redux';
import SqlEditor, { Props } from '.';
@@ -102,6 +105,12 @@ const mockInitialState = {
},
};
jest.mock('@superset-ui/core', () => ({
...jest.requireActual('@superset-ui/core'),
isFeatureEnabled: jest.fn(),
}));
const mockIsFeatureEnabled = isFeatureEnabled as jest.Mock;
const setup = (props: Props, store: Store) =>
render(<SqlEditor {...props} />, {
useRedux: true,
@@ -317,19 +326,13 @@ describe('SqlEditor', () => {
});
describe('with EstimateQueryCost enabled', () => {
let isFeatureEnabledMock: jest.MockInstance<
boolean,
[feature: FeatureFlag]
>;
beforeEach(() => {
isFeatureEnabledMock = jest
.spyOn(uiCore, 'isFeatureEnabled')
.mockImplementation(
featureFlag => featureFlag === uiCore.FeatureFlag.EstimateQueryCost,
);
mockIsFeatureEnabled.mockImplementation(
featureFlag => featureFlag === FeatureFlag.EstimateQueryCost,
);
});
afterEach(() => {
isFeatureEnabledMock.mockClear();
mockIsFeatureEnabled.mockClear();
});
it('sends the catalog and schema to the endpoint', async () => {
@@ -399,20 +402,13 @@ describe('SqlEditor', () => {
});
describe('with SqllabBackendPersistence enabled', () => {
let isFeatureEnabledMock: jest.MockInstance<
boolean,
[feature: FeatureFlag]
>;
beforeEach(() => {
isFeatureEnabledMock = jest
.spyOn(uiCore, 'isFeatureEnabled')
.mockImplementation(
featureFlag =>
featureFlag === uiCore.FeatureFlag.SqllabBackendPersistence,
);
mockIsFeatureEnabled.mockImplementation(
featureFlag => featureFlag === FeatureFlag.SqllabBackendPersistence,
);
});
afterEach(() => {
isFeatureEnabledMock.mockClear();
mockIsFeatureEnabled.mockClear();
});
it('should render loading state when its Editor is not loaded', async () => {

View File

@@ -485,20 +485,28 @@ const SqlEditor: FC<Props> = ({
const cursorPosition = editor.getCursorPosition();
const totalLine = session.getLength();
const currentRow = editor.getFirstVisibleRow();
let end = editor.find(';', {
const semicolonEnd = editor.find(';', {
backwards: false,
skipCurrent: true,
})?.end;
});
let end;
if (semicolonEnd) {
({ end } = semicolonEnd);
}
if (!end || end.row < cursorPosition.row) {
end = {
row: totalLine + 1,
column: 0,
};
}
let start = editor.find(';', {
const semicolonStart = editor.find(';', {
backwards: true,
skipCurrent: true,
})?.end;
});
let start;
if (semicolonStart) {
start = semicolonStart.end;
}
let currentLine = start?.row;
if (
!currentLine ||

View File

@@ -18,12 +18,18 @@
*/
import { isValidElement } from 'react';
import fetchMock from 'fetch-mock';
import * as uiCore from '@superset-ui/core';
import { FeatureFlag } from '@superset-ui/core';
import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
import TableElement, { Column } from 'src/SqlLab/components/TableElement';
import { table, initialState } from 'src/SqlLab/fixtures';
import { render, waitFor, fireEvent } from 'spec/helpers/testing-library';
jest.mock('@superset-ui/core', () => ({
...jest.requireActual('@superset-ui/core'),
isFeatureEnabled: jest.fn(),
}));
const mockedIsFeatureEnabled = isFeatureEnabled as jest.Mock;
jest.mock('src/components/Loading', () => () => (
<div data-test="mock-loading" />
));
@@ -143,11 +149,9 @@ test('sorts columns', async () => {
test('removes the table', async () => {
const updateTableSchemaEndpoint = 'glob:*/tableschemaview/*';
fetchMock.delete(updateTableSchemaEndpoint, {});
const isFeatureEnabledMock = jest
.spyOn(uiCore, 'isFeatureEnabled')
.mockImplementation(
featureFlag => featureFlag === FeatureFlag.SqllabBackendPersistence,
);
mockedIsFeatureEnabled.mockImplementation(
featureFlag => featureFlag === FeatureFlag.SqllabBackendPersistence,
);
const { getAllByTestId, getByText } = render(
<TableElement {...mockedProps} />,
{
@@ -163,7 +167,7 @@ test('removes the table', async () => {
await waitFor(() =>
expect(fetchMock.calls(updateTableSchemaEndpoint)).toHaveLength(1),
);
isFeatureEnabledMock.mockClear();
mockedIsFeatureEnabled.mockClear();
});
test('fetches table metadata when expanded', async () => {