From 08b8aa277f120771a178ddd135e77c28ecadeb52 Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Tue, 24 Aug 2021 23:10:46 -0700 Subject: [PATCH] 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 --- superset-frontend/jest.config.js | 4 ++-- .../spec/__mocks__/{styleMock.js => mockExportObject.js} | 0 .../spec/__mocks__/{fileMock.js => mockExportString.js} | 0 superset-frontend/spec/helpers/setup.ts | 2 ++ .../src/components/OmniContainer/OmniContainer.test.tsx | 1 + .../src/explore/exploreUtils/getChartDataUri.test.ts | 2 +- .../src/explore/exploreUtils/getExploreUrl.test.ts | 6 +++--- superset-frontend/src/views/CRUD/chart/ChartList.tsx | 2 ++ 8 files changed, 11 insertions(+), 6 deletions(-) rename superset-frontend/spec/__mocks__/{styleMock.js => mockExportObject.js} (100%) rename superset-frontend/spec/__mocks__/{fileMock.js => mockExportString.js} (100%) diff --git a/superset-frontend/jest.config.js b/superset-frontend/jest.config.js index 191f7a5e1..2d9529f69 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)$': '/spec/__mocks__/styleMock.js', - '\\.(gif|ttf|eot|png|jpg)$': '/spec/__mocks__/fileMock.js', + '\\.(css|less|geojson)$': '/spec/__mocks__/mockExportObject.js', + '\\.(gif|ttf|eot|png|jpg)$': '/spec/__mocks__/mockExportString.js', '\\.svg$': '/spec/__mocks__/svgrMock.tsx', '^src/(.*)$': '/src/$1', '^spec/(.*)$': '/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 28abd96bc..c2c991f95 100644 --- a/superset-frontend/spec/helpers/setup.ts +++ b/superset-frontend/spec/helpers/setup.ts @@ -23,3 +23,5 @@ import { configure as configureTestingLibrary } from '@testing-library/react'; configureTestingLibrary({ testIdAttribute: 'data-test', }); + +document.body.innerHTML = '
'; diff --git a/superset-frontend/src/components/OmniContainer/OmniContainer.test.tsx b/superset-frontend/src/components/OmniContainer/OmniContainer.test.tsx index d797727ed..dd926b632 100644 --- a/superset-frontend/src/components/OmniContainer/OmniContainer.test.tsx +++ b/superset-frontend/src/components/OmniContainer/OmniContainer.test.tsx @@ -25,6 +25,7 @@ import OmniContainer from './index'; 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 c61612d9c..797b5def3 100644 --- a/superset-frontend/src/explore/exploreUtils/getChartDataUri.test.ts +++ b/superset-frontend/src/explore/exploreUtils/getChartDataUri.test.ts @@ -31,7 +31,7 @@ test('Get ChartUri when allowDomainSharding:false', () => { 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 efa4b6ed8..7457b462b 100644 --- a/superset-frontend/src/explore/exploreUtils/getExploreUrl.test.ts +++ b/superset-frontend/src/explore/exploreUtils/getExploreUrl.test.ts @@ -33,13 +33,13 @@ const createParams = () => ({ 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 @@ test('Get ExploreUrl with endpointType:full and method:GET', () => { 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 e4aff8192..76e3809d6 100644 --- a/superset-frontend/src/views/CRUD/chart/ChartList.tsx +++ b/superset-frontend/src/views/CRUD/chart/ChartList.tsx @@ -57,6 +57,7 @@ import Chart from 'src/types/Chart'; 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 @@ const CONFIRM_OVERWRITE_MESSAGE = t( 'sure you want to overwrite?', ); +setupPlugins(); const registry = getChartMetadataRegistry(); const createFetchDatasets = (handleError: (err: Response) => void) => async (