mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
test(frontend): Migrate from describe/it to flat test() pattern (#35305)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,7 @@ import { DashboardStandaloneMode } from 'src/dashboard/util/constants';
|
||||
import * as hostNamesConfig from 'src/utils/hostNamesConfig';
|
||||
import { getChartMetadataRegistry, SupersetClient } from '@superset-ui/core';
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('exploreUtils', () => {
|
||||
const { location } = window;
|
||||
const formData = {
|
||||
@@ -39,8 +40,9 @@ describe('exploreUtils', () => {
|
||||
expect(uri1.toString()).toBe(uri2.toString());
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('getExploreUrl', () => {
|
||||
it('generates proper base url', () => {
|
||||
test('generates proper base url', () => {
|
||||
// This assertion is to show clearly the value of location.href
|
||||
// in the context of unit tests.
|
||||
expect(location.href).toBe('http://localhost/');
|
||||
@@ -53,7 +55,7 @@ describe('exploreUtils', () => {
|
||||
});
|
||||
compareURI(URI(url), URI('/explore/'));
|
||||
});
|
||||
it('generates proper json url', () => {
|
||||
test('generates proper json url', () => {
|
||||
const url = getExploreUrl({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
@@ -62,7 +64,7 @@ describe('exploreUtils', () => {
|
||||
});
|
||||
compareURI(URI(url), URI('/superset/explore_json/'));
|
||||
});
|
||||
it('generates proper json forced url', () => {
|
||||
test('generates proper json forced url', () => {
|
||||
const url = getExploreUrl({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
@@ -74,7 +76,7 @@ describe('exploreUtils', () => {
|
||||
URI('/superset/explore_json/').search({ force: 'true' }),
|
||||
);
|
||||
});
|
||||
it('generates proper csv URL', () => {
|
||||
test('generates proper csv URL', () => {
|
||||
const url = getExploreUrl({
|
||||
formData,
|
||||
endpointType: 'csv',
|
||||
@@ -86,7 +88,7 @@ describe('exploreUtils', () => {
|
||||
URI('/superset/explore_json/').search({ csv: 'true' }),
|
||||
);
|
||||
});
|
||||
it('generates proper standalone URL', () => {
|
||||
test('generates proper standalone URL', () => {
|
||||
const url = getExploreUrl({
|
||||
formData,
|
||||
endpointType: 'standalone',
|
||||
@@ -100,7 +102,7 @@ describe('exploreUtils', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
it('preserves main URLs params', () => {
|
||||
test('preserves main URLs params', () => {
|
||||
const url = getExploreUrl({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
@@ -112,7 +114,7 @@ describe('exploreUtils', () => {
|
||||
URI('/superset/explore_json/').search({ foo: 'bar' }),
|
||||
);
|
||||
});
|
||||
it('generate proper save slice url', () => {
|
||||
test('generate proper save slice url', () => {
|
||||
const url = getExploreUrl({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
@@ -126,6 +128,7 @@ describe('exploreUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('domain sharding', () => {
|
||||
let stub;
|
||||
const availableDomains = [
|
||||
@@ -143,7 +146,7 @@ describe('exploreUtils', () => {
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
it('generate url to different domains', () => {
|
||||
test('generate url to different domains', () => {
|
||||
let url = getExploreUrl({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
@@ -175,7 +178,7 @@ describe('exploreUtils', () => {
|
||||
});
|
||||
expect(url).toMatch(availableDomains[1]);
|
||||
});
|
||||
it('not generate url to different domains without flag', () => {
|
||||
test('not generate url to different domains without flag', () => {
|
||||
let csvURL = getExploreUrl({
|
||||
formData,
|
||||
endpointType: 'csv',
|
||||
@@ -190,8 +193,9 @@ describe('exploreUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('buildV1ChartDataPayload', () => {
|
||||
it('generate valid request payload despite no registered buildQuery', async () => {
|
||||
test('generate valid request payload despite no registered buildQuery', async () => {
|
||||
const v1RequestPayload = await buildV1ChartDataPayload({
|
||||
formData: { ...formData, viz_type: 'my_custom_viz' },
|
||||
});
|
||||
@@ -199,6 +203,7 @@ describe('exploreUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('getQuerySettings', () => {
|
||||
beforeAll(() => {
|
||||
getChartMetadataRegistry()
|
||||
@@ -210,7 +215,7 @@ describe('exploreUtils', () => {
|
||||
getChartMetadataRegistry().remove('my_legacy_viz').remove('my_v1_viz');
|
||||
});
|
||||
|
||||
it('returns true for legacy viz', () => {
|
||||
test('returns true for legacy viz', () => {
|
||||
const [useLegacyApi, parseMethod] = getQuerySettings({
|
||||
...formData,
|
||||
viz_type: 'my_legacy_viz',
|
||||
@@ -219,7 +224,7 @@ describe('exploreUtils', () => {
|
||||
expect(parseMethod).toBe('json-bigint');
|
||||
});
|
||||
|
||||
it('returns false for v1 viz', () => {
|
||||
test('returns false for v1 viz', () => {
|
||||
const [useLegacyApi, parseMethod] = getQuerySettings({
|
||||
...formData,
|
||||
viz_type: 'my_v1_viz',
|
||||
@@ -228,7 +233,7 @@ describe('exploreUtils', () => {
|
||||
expect(parseMethod).toBe('json-bigint');
|
||||
});
|
||||
|
||||
it('returns false for formData with unregistered viz_type', () => {
|
||||
test('returns false for formData with unregistered viz_type', () => {
|
||||
const [useLegacyApi, parseMethod] = getQuerySettings({
|
||||
...formData,
|
||||
viz_type: 'undefined_viz',
|
||||
@@ -237,28 +242,29 @@ describe('exploreUtils', () => {
|
||||
expect(parseMethod).toBe('json-bigint');
|
||||
});
|
||||
|
||||
it('returns false for formData without viz_type', () => {
|
||||
test('returns false for formData without viz_type', () => {
|
||||
const [useLegacyApi, parseMethod] = getQuerySettings(formData);
|
||||
expect(useLegacyApi).toBe(false);
|
||||
expect(parseMethod).toBe('json-bigint');
|
||||
});
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('getSimpleSQLExpression', () => {
|
||||
it('returns empty string when subject is undefined', () => {
|
||||
test('returns empty string when subject is undefined', () => {
|
||||
expect(getSimpleSQLExpression(undefined, '=', 10)).toBe('');
|
||||
expect(getSimpleSQLExpression()).toBe('');
|
||||
});
|
||||
it("returns subject when it's provided and operator is undefined", () => {
|
||||
test("returns subject when it's provided and operator is undefined", () => {
|
||||
expect(getSimpleSQLExpression('col', undefined, 10)).toBe('col');
|
||||
expect(getSimpleSQLExpression('col')).toBe('col');
|
||||
});
|
||||
it("returns subject and operator when they're provided and comparator is undefined", () => {
|
||||
test("returns subject and operator when they're provided and comparator is undefined", () => {
|
||||
expect(getSimpleSQLExpression('col', '=')).toBe('col =');
|
||||
expect(getSimpleSQLExpression('col', 'IN')).toBe('col IN');
|
||||
expect(getSimpleSQLExpression('col', 'IN', [])).toBe('col IN');
|
||||
});
|
||||
it('returns full expression when subject, operator and comparator are provided', () => {
|
||||
test('returns full expression when subject, operator and comparator are provided', () => {
|
||||
expect(getSimpleSQLExpression('col', '=', 'comp')).toBe("col = 'comp'");
|
||||
expect(getSimpleSQLExpression('col', '=', "it's an apostrophe")).toBe(
|
||||
"col = 'it''s an apostrophe'",
|
||||
@@ -281,8 +287,9 @@ describe('exploreUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('.exploreChart()', () => {
|
||||
it('postForm', () => {
|
||||
test('postForm', () => {
|
||||
const postFormSpy = jest.spyOn(SupersetClient, 'postForm');
|
||||
postFormSpy.mockImplementation(jest.fn());
|
||||
|
||||
|
||||
@@ -21,12 +21,13 @@ import { getChartDataUri } from '.';
|
||||
|
||||
jest.mock('src/utils/pathUtils');
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('Get ChartUri', () => {
|
||||
(ensureAppRoot as jest.Mock).mockImplementation(
|
||||
(path: string) => `/prefix${path}`,
|
||||
);
|
||||
|
||||
it('Get ChartUri when allowDomainSharding:false', () => {
|
||||
test('Get ChartUri when allowDomainSharding:false', () => {
|
||||
expect(
|
||||
getChartDataUri({
|
||||
path: '/path',
|
||||
@@ -53,7 +54,7 @@ describe('Get ChartUri', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Get ChartUri when allowDomainSharding:true', () => {
|
||||
test('Get ChartUri when allowDomainSharding:true', () => {
|
||||
expect(
|
||||
getChartDataUri({
|
||||
path: '/path-allowDomainSharding-true',
|
||||
|
||||
Reference in New Issue
Block a user