fix: setupPlugin in chart list page (#16413)
* fix: setupPlugin in chart list page
* fix the order of setupPlugins call
* Fix jest test on loading geojson
* add jest changes
* fix unit tests
Co-authored-by: Jesse Yang <jesse.yang@airbnb.com>
(cherry picked from commit 08b8aa277f120771a178ddd135e77c28ecadeb52)
diff --git a/superset-frontend/jest.config.js b/superset-frontend/jest.config.js
index 191f7a5..2d9529f 100644
--- a/superset-frontend/jest.config.js
+++ b/superset-frontend/jest.config.js
@@ -19,8 +19,8 @@
module.exports = {
testRegex: '(\\/spec|\\/src)\\/.*(_spec|\\.test)\\.(j|t)sx?$',
moduleNameMapper: {
- '\\.(css|less)$': '<rootDir>/spec/__mocks__/styleMock.js',
- '\\.(gif|ttf|eot|png|jpg)$': '<rootDir>/spec/__mocks__/fileMock.js',
+ '\\.(css|less|geojson)$': '<rootDir>/spec/__mocks__/mockExportObject.js',
+ '\\.(gif|ttf|eot|png|jpg)$': '<rootDir>/spec/__mocks__/mockExportString.js',
'\\.svg$': '<rootDir>/spec/__mocks__/svgrMock.tsx',
'^src/(.*)$': '<rootDir>/src/$1',
'^spec/(.*)$': '<rootDir>/spec/$1',
diff --git a/superset-frontend/spec/__mocks__/styleMock.js b/superset-frontend/spec/__mocks__/mockExportObject.js
similarity index 100%
rename from superset-frontend/spec/__mocks__/styleMock.js
rename to superset-frontend/spec/__mocks__/mockExportObject.js
diff --git a/superset-frontend/spec/__mocks__/fileMock.js b/superset-frontend/spec/__mocks__/mockExportString.js
similarity index 100%
rename from superset-frontend/spec/__mocks__/fileMock.js
rename to superset-frontend/spec/__mocks__/mockExportString.js
diff --git a/superset-frontend/spec/helpers/setup.ts b/superset-frontend/spec/helpers/setup.ts
index 28abd96..c2c991f 100644
--- a/superset-frontend/spec/helpers/setup.ts
+++ b/superset-frontend/spec/helpers/setup.ts
@@ -23,3 +23,5 @@
configureTestingLibrary({
testIdAttribute: 'data-test',
});
+
+document.body.innerHTML = '<div id="app" data-bootstrap="{}"></div>';
diff --git a/superset-frontend/src/components/OmniContainer/OmniContainer.test.tsx b/superset-frontend/src/components/OmniContainer/OmniContainer.test.tsx
index d797727..dd926b6 100644
--- a/superset-frontend/src/components/OmniContainer/OmniContainer.test.tsx
+++ b/superset-frontend/src/components/OmniContainer/OmniContainer.test.tsx
@@ -25,6 +25,7 @@
jest.mock('src/featureFlags', () => ({
isFeatureEnabled: jest.fn(),
FeatureFlag: { OMNIBAR: 'OMNIBAR' },
+ initFeatureFlags: jest.fn(),
}));
test('Do not open Omnibar with the featureflag disabled', () => {
diff --git a/superset-frontend/src/explore/exploreUtils/getChartDataUri.test.ts b/superset-frontend/src/explore/exploreUtils/getChartDataUri.test.ts
index c61612d..797b5de 100644
--- a/superset-frontend/src/explore/exploreUtils/getChartDataUri.test.ts
+++ b/superset-frontend/src/explore/exploreUtils/getChartDataUri.test.ts
@@ -31,7 +31,7 @@
duplicateQueryParameters: false,
escapeQuerySpace: true,
fragment: null,
- hostname: undefined,
+ hostname: 'localhost',
password: null,
path: '/path',
port: '',
diff --git a/superset-frontend/src/explore/exploreUtils/getExploreUrl.test.ts b/superset-frontend/src/explore/exploreUtils/getExploreUrl.test.ts
index efa4b6e..7457b46 100644
--- a/superset-frontend/src/explore/exploreUtils/getExploreUrl.test.ts
+++ b/superset-frontend/src/explore/exploreUtils/getExploreUrl.test.ts
@@ -33,13 +33,13 @@
test('Get ExploreUrl with default params', () => {
const params = createParams();
- expect(getExploreUrl(params)).toBe('http:///superset/explore/');
+ expect(getExploreUrl(params)).toBe('http://localhost/superset/explore/');
});
test('Get ExploreUrl with endpointType:full', () => {
const params = createParams();
expect(getExploreUrl({ ...params, endpointType: 'full' })).toBe(
- 'http:///superset/explore_json/',
+ 'http://localhost/superset/explore_json/',
);
});
@@ -47,5 +47,5 @@
const params = createParams();
expect(
getExploreUrl({ ...params, endpointType: 'full', method: 'GET' }),
- ).toBe('http:///superset/explore_json/');
+ ).toBe('http://localhost/superset/explore_json/');
});
diff --git a/superset-frontend/src/views/CRUD/chart/ChartList.tsx b/superset-frontend/src/views/CRUD/chart/ChartList.tsx
index e4aff81..76e3809 100644
--- a/superset-frontend/src/views/CRUD/chart/ChartList.tsx
+++ b/superset-frontend/src/views/CRUD/chart/ChartList.tsx
@@ -57,6 +57,7 @@
import { Tooltip } from 'src/components/Tooltip';
import Icons from 'src/components/Icons';
import { nativeFilterGate } from 'src/dashboard/components/nativeFilters/utils';
+import setupPlugins from 'src/setup/setupPlugins';
import ChartCard from './ChartCard';
const PAGE_SIZE = 25;
@@ -73,6 +74,7 @@
'sure you want to overwrite?',
);
+setupPlugins();
const registry = getChartMetadataRegistry();
const createFetchDatasets = (handleError: (err: Response) => void) => async (