From ba795ccfa0705f0cd1d4eae0a2d296228073b408 Mon Sep 17 00:00:00 2001 From: Evan Date: Wed, 8 Jul 2026 04:38:50 -0700 Subject: [PATCH] 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 --- .../src/Multi/Multi.color.test.tsx | 54 ++++++++++++++----- .../preset-chart-deckgl/src/Multi/Multi.tsx | 3 +- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx b/superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx index 52daea45156..c7404b5d0d3 100644 --- a/superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx +++ b/superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx @@ -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) => ({ + 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] }] }], }, }); diff --git a/superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx b/superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx index 50387dd0744..a0db73367b7 100644 --- a/superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx +++ b/superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx @@ -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, ), ), [],