mirror of https://github.com/apache/superset.git
fix: refine shouldUseLegacyApi and add tests (#10148)
* fix: refine shouldUseLegacyApi and add tests * address review comments
This commit is contained in:
parent
4e71491d86
commit
38667b72b1
|
@ -23,8 +23,10 @@ import {
|
||||||
buildV1ChartDataPayload,
|
buildV1ChartDataPayload,
|
||||||
getExploreUrl,
|
getExploreUrl,
|
||||||
getExploreLongUrl,
|
getExploreLongUrl,
|
||||||
|
shouldUseLegacyApi,
|
||||||
} from 'src/explore/exploreUtils';
|
} from 'src/explore/exploreUtils';
|
||||||
import * as hostNamesConfig from 'src/utils/hostNamesConfig';
|
import * as hostNamesConfig from 'src/utils/hostNamesConfig';
|
||||||
|
import { getChartMetadataRegistry } from '@superset-ui/chart';
|
||||||
|
|
||||||
describe('exploreUtils', () => {
|
describe('exploreUtils', () => {
|
||||||
const location = window.location;
|
const location = window.location;
|
||||||
|
@ -202,4 +204,45 @@ describe('exploreUtils', () => {
|
||||||
expect(v1RequestPayload).hasOwnProperty('queries');
|
expect(v1RequestPayload).hasOwnProperty('queries');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('shouldUseLegacyApi', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
getChartMetadataRegistry()
|
||||||
|
.registerValue('my_legacy_viz', { useLegacyApi: true })
|
||||||
|
.registerValue('my_v1_viz', { useLegacyApi: false });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
getChartMetadataRegistry().remove('my_legacy_viz').remove('my_v1_viz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true for legacy viz', () => {
|
||||||
|
const useLegacyApi = shouldUseLegacyApi({
|
||||||
|
...formData,
|
||||||
|
viz_type: 'my_legacy_viz',
|
||||||
|
});
|
||||||
|
expect(useLegacyApi).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false for v1 viz', () => {
|
||||||
|
const useLegacyApi = shouldUseLegacyApi({
|
||||||
|
...formData,
|
||||||
|
viz_type: 'my_v1_viz',
|
||||||
|
});
|
||||||
|
expect(useLegacyApi).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false for formData with unregistered viz_type', () => {
|
||||||
|
const useLegacyApi = shouldUseLegacyApi({
|
||||||
|
...formData,
|
||||||
|
viz_type: 'undefined_viz',
|
||||||
|
});
|
||||||
|
expect(useLegacyApi).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false for formData without viz_type', () => {
|
||||||
|
const useLegacyApi = shouldUseLegacyApi(formData);
|
||||||
|
expect(useLegacyApi).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -194,8 +194,8 @@ export function getExploreUrl({
|
||||||
}
|
}
|
||||||
|
|
||||||
export const shouldUseLegacyApi = formData => {
|
export const shouldUseLegacyApi = formData => {
|
||||||
const { useLegacyApi } = getChartMetadataRegistry().get(formData.viz_type);
|
const vizMetadata = getChartMetadataRegistry().get(formData.viz_type);
|
||||||
return useLegacyApi || false;
|
return vizMetadata ? vizMetadata.useLegacyApi : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const buildV1ChartDataPayload = ({
|
export const buildV1ChartDataPayload = ({
|
||||||
|
|
Loading…
Reference in New Issue