You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by am...@apache.org on 2026/09/01 16:22:03 UTC
(superset) 13/15: test(embedded): cover the fabricated hydrate payload
This is an automated email from the ASF dual-hosted git repository.
amaannawab923 pushed a commit to branch feat/embedded-chart
in repository https://gitbox.apache.org/repos/asf/superset.git
commit f31d15e64f30bf6b20b498199fa265c6a3bc0741
Author: amaannawab923 <am...@gmail.com>
AuthorDate: Tue Sep 1 20:55:24 2026 +0530
test(embedded): cover the fabricated hydrate payload
Runs the real dashboard reducers against the real payload, so a slice that a
HYDRATE_DASHBOARD handler dereferences without optional chaining cannot go
missing again. That failure only surfaces at runtime and only in the embedded
path, which is why it went unnoticed. Also fills in dashboardLayout and
nativeFilters on HydrateEmbeddedAction, which had gone stale.
---
.../embedded/embeddedChart/hydrateEmbedded.test.ts | 100 +++++++++++++++++++++
.../src/embedded/embeddedChart/hydrateEmbedded.ts | 10 ++-
2 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/src/embedded/embeddedChart/hydrateEmbedded.test.ts b/superset-frontend/src/embedded/embeddedChart/hydrateEmbedded.test.ts
new file mode 100644
index 00000000000..17f5ce3ba8a
--- /dev/null
+++ b/superset-frontend/src/embedded/embeddedChart/hydrateEmbedded.test.ts
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { HYDRATE_DASHBOARD } from 'src/dashboard/actions/hydrate';
+import dashboardLayout from 'src/dashboard/reducers/dashboardLayout';
+import nativeFilters from 'src/dashboard/reducers/nativeFilters';
+import dashboardStateReducer from 'src/dashboard/reducers/dashboardState';
+import sliceEntities from 'src/dashboard/reducers/sliceEntities';
+import { CommonBootstrapData } from 'src/types/bootstrapTypes';
+import hydrateEmbedded, { EmbeddedChartData } from './hydrateEmbedded';
+
+const SLICE_ID = 103;
+
+const chartData = {
+ slice: {
+ slice_id: SLICE_ID,
+ slice_url: `/explore/?slice_id=${SLICE_ID}`,
+ slice_name: 'Preferred Employment Style',
+ form_data: {
+ viz_type: 'treemap_v2',
+ datasource: '4__table',
+ slice_id: SLICE_ID,
+ },
+ description: null,
+ changed_on: '2026-01-01T00:00:00',
+ },
+ dataset: { uid: '4__table', id: 4 },
+} as unknown as EmbeddedChartData;
+
+const common = { locale: 'en' } as unknown as CommonBootstrapData;
+
+const build = () => hydrateEmbedded(chartData, common);
+
+test('dispatches HYDRATE_DASHBOARD rather than a parallel action', () => {
+ expect(build().type).toEqual(HYDRATE_DASHBOARD);
+});
+
+test('keys the fabricated state by slice id', () => {
+ const { data } = build();
+ expect(Object.keys(data.charts)).toEqual([String(SLICE_ID)]);
+ expect(data.sliceEntities.slices[SLICE_ID].slice_name).toEqual(
+ 'Preferred Employment Style',
+ );
+ expect(data.dataMask[SLICE_ID]).toBeDefined();
+ expect(data.dashboardState.sliceIds).toEqual([SLICE_ID]);
+});
+
+test('keeps the actions that would navigate out of the iframe switched off', () => {
+ const { dashboardInfo } = build().data;
+ expect(dashboardInfo.superset_can_explore).toBe(false);
+ expect(dashboardInfo.superset_can_share).toBe(false);
+ expect(dashboardInfo.crossFiltersEnabled).toBe(false);
+ // Chart.tsx reads this one, so downloads stay available.
+ expect(dashboardInfo.superset_can_download).toBe(true);
+});
+
+/**
+ * The regression this file exists for. `nativeFilters` and `dashboardLayout`
+ * read `action.data.<slice>` with no optional chaining, so omitting either one
+ * throws at runtime — and only in the embedded path, where a dashboard
+ * developer would never see it. Run the real reducers against the real payload
+ * rather than asserting on shape, so this keeps holding if they change.
+ */
+describe('every HYDRATE_DASHBOARD handler survives the fabricated payload', () => {
+ const cases: [string, (state: any, action: any) => unknown][] = [
+ ['dashboardLayout', dashboardLayout],
+ ['nativeFilters', nativeFilters],
+ ['dashboardState', dashboardStateReducer],
+ ['sliceEntities', sliceEntities],
+ ];
+
+ test.each(cases)('%s', (_name, reducer) => {
+ expect(() => reducer(undefined, build())).not.toThrow();
+ });
+});
+
+test('carries a layout tree so the layout reducer has a root to hydrate', () => {
+ const layout = build().data.dashboardLayout.present;
+ expect(layout.ROOT_ID).toBeDefined();
+ expect(layout.GRID_ID).toBeDefined();
+});
+
+test('carries an empty native filter map', () => {
+ expect(build().data.nativeFilters.filters).toEqual({});
+});
diff --git a/superset-frontend/src/embedded/embeddedChart/hydrateEmbedded.ts b/superset-frontend/src/embedded/embeddedChart/hydrateEmbedded.ts
index 0ac775555cd..63f2b8821c5 100644
--- a/superset-frontend/src/embedded/embeddedChart/hydrateEmbedded.ts
+++ b/superset-frontend/src/embedded/embeddedChart/hydrateEmbedded.ts
@@ -41,8 +41,14 @@ import {
* It reuses HYDRATE_DASHBOARD rather than introducing a parallel action, so
* every dashboard reducer stays untouched: `charts`, `sliceEntities`,
* `dataMask`, `dashboardInfo` and `dashboardState` all already handle it.
- * `datasources` is the one slice with no hydrate handler, so the caller
+ * `dashboardLayout` and `nativeFilters` handle it too but dereference their
+ * slice unconditionally, so the payload carries an empty stand-in for each.
+ * `datasources` is the one slice with no hydrate handler at all, so the caller
* dispatches `setDatasources` for it separately.
+ *
+ * Every slice any HYDRATE_DASHBOARD handler reads has to appear here; the
+ * accompanying test asserts that, because a missing one only fails at runtime
+ * and only in the embedded path.
*/
export interface EmbeddedChartData {
@@ -67,6 +73,8 @@ export interface HydrateEmbeddedAction {
dataMask: Record<number, DataMaskWithId>;
dashboardInfo: JsonObject;
dashboardState: JsonObject;
+ dashboardLayout: { present: JsonObject };
+ nativeFilters: { filters: JsonObject };
};
}