Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refine shouldUseLegacyApi and add tests #10148

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions superset-frontend/spec/javascripts/explore/utils_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import {
buildV1ChartDataPayload,
getExploreUrl,
getExploreLongUrl,
shouldUseLegacyApi,
} from 'src/explore/exploreUtils';
import * as hostNamesConfig from 'src/utils/hostNamesConfig';
import { getChartMetadataRegistry } from '@superset-ui/chart';

describe('exploreUtils', () => {
const location = window.location;
Expand Down Expand Up @@ -202,4 +204,45 @@ describe('exploreUtils', () => {
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('return true for legacy viz', () => {
Copy link
Member

@rusackas rusackas Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT, but maybe "returns" for these so it('reads like a sentence')

const useLegacyApi = shouldUseLegacyApi({
...formData,
viz_type: 'my_legacy_viz',
});
expect(useLegacyApi).toBe(true);
});

it('return false for v1 viz', () => {
const useLegacyApi = shouldUseLegacyApi({
...formData,
viz_type: 'my_v1_viz',
});
expect(useLegacyApi).toBe(false);
});

it('return false for formData with unregistered viz_type', () => {
const useLegacyApi = shouldUseLegacyApi({
...formData,
viz_type: 'undefined_viz',
});
expect(useLegacyApi).toBe(false);
});

it('return false for formData without viz_type', () => {
const useLegacyApi = shouldUseLegacyApi(formData);
expect(useLegacyApi).toBe(false);
});
});
});
4 changes: 2 additions & 2 deletions superset-frontend/src/explore/exploreUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export function getExploreUrl({
}

export const shouldUseLegacyApi = formData => {
const { useLegacyApi } = getChartMetadataRegistry().get(formData.viz_type);
return useLegacyApi || false;
const vizMetadata = getChartMetadataRegistry().get(formData.viz_type);
return vizMetadata ? vizMetadata.useLegacyApi : false;
};

export const buildV1ChartDataPayload = ({
Expand Down