fix: format Multi.tsx and update Multi.color.test.tsx for registry-based layer loading

Multi.tsx now resolves sublayer buildQuery/transformProps via the chart
plugin registries instead of the removed legacy explore.ts helper; update
the color test's mocks to register deck_scatter/deck_arc stubs and mock
SupersetClient.post (matching the new fetch call) instead of .get.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Evan
2026-07-08 04:38:50 -07:00
committed by rusackas
parent 6a5049daed
commit ba795ccfa0
2 changed files with 42 additions and 15 deletions

View File

@@ -21,7 +21,7 @@ import '@testing-library/jest-dom';
import { supersetTheme, ThemeProvider } from '@apache-superset/core/theme';
import { Provider } from 'react-redux';
import { configureStore } from '@reduxjs/toolkit';
import { DatasourceType, SupersetClient } from '@superset-ui/core';
import { DatasourceType, JsonObject, SupersetClient } from '@superset-ui/core';
import DeckMulti from './Multi';
// Capture the layers handed to the DeckGL container so we can inspect the
@@ -48,10 +48,38 @@ jest.mock('../DeckGLContainer', () => ({
jest.mock('@superset-ui/core', () => ({
...jest.requireActual('@superset-ui/core'),
SupersetClient: {
get: jest.fn(),
post: jest.fn(),
},
}));
// register stub buildQuery/transformProps for the layer types the tests use.
// The stub transformProps simply echoes the fetched records through as
// layer features, so `addColorToFeatures` (exercised in Multi.tsx) resolves
// colors from the same raw records the tests assert against.
const { getChartBuildQueryRegistry, getChartTransformPropsRegistry } =
jest.requireActual('@superset-ui/core');
['deck_scatter', 'deck_arc'].forEach(vizType => {
getChartBuildQueryRegistry().registerValue(
vizType,
(formData: Record<string, unknown>) => ({
datasource: 'test_datasource',
queries: [{}],
form_data: formData,
}),
);
getChartTransformPropsRegistry().registerValue(
vizType,
(chartProps: { queriesData: { data: JsonObject[] }[] }) => ({
payload: {
data: {
features: chartProps.queriesData?.[0]?.data || [],
mapboxApiKey: 'test-key',
},
},
}),
);
});
const mockStore = configureStore({
reducer: {
dataMask: () => ({}),
@@ -119,14 +147,16 @@ beforeEach(() => {
jest.clearAllMocks();
mockLayerCapture.layers = [];
// The scatter sublayer query returns features tagged with a category column.
(SupersetClient.get as jest.Mock).mockResolvedValue({
(SupersetClient.post as jest.Mock).mockResolvedValue({
json: {
data: {
features: [
{ position: [0, 0], radius: 1, cat_color: 'A' },
{ position: [1, 1], radius: 1, cat_color: 'B' },
],
},
result: [
{
data: [
{ position: [0, 0], radius: 1, cat_color: 'A' },
{ position: [1, 1], radius: 1, cat_color: 'B' },
],
},
],
},
});
});
@@ -221,11 +251,9 @@ test('keeps fixed source and target colors for arc subslices saved before the co
},
},
};
(SupersetClient.get as jest.Mock).mockResolvedValue({
(SupersetClient.post as jest.Mock).mockResolvedValue({
json: {
data: {
features: [{ sourcePosition: [0, 0], targetPosition: [1, 1] }],
},
result: [{ data: [{ sourcePosition: [0, 0], targetPosition: [1, 1] }] }],
},
});

View File

@@ -476,8 +476,7 @@ const DeckMulti = (props: DeckMultiProps) => {
),
).then(slices =>
slices.filter(
(slice): slice is { slice_id: number } & JsonObject =>
slice !== null,
(slice): slice is { slice_id: number } & JsonObject => slice !== null,
),
),
[],