This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch feat/glyph-single-file
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/feat/glyph-single-file by this 
push:
     new 8ed06d48adb test(glyph): fix TS errors in glyph test files
8ed06d48adb is described below

commit 8ed06d48adbd658f83d83ed1805e78cc40cdee7c
Author: Evan Rusackas <[email protected]>
AuthorDate: Fri May 22 12:40:26 2026 -0700

    test(glyph): fix TS errors in glyph test files
    
    - defineChart.test.tsx: cast formDataOverrides via `unknown` first
      because SqlaFormData (required datasource/viz_type) doesn't overlap
      with the looser Record<string, unknown> signature used in the test.
    - generators.test.ts: add a glyphMap() helper to widen Map value type
      to `typeof Argument | GlyphArgConfig`. `new Map([...])` narrows from
      the first tuple, which broke mixed Metric/Checkbox entries.
    - GlyphOptionsPanel.test.tsx: add `datasource: '1__table'` to every
      formData literal so they satisfy the SqlaFormData shape, and move
      imports above the jest.mock blocks to satisfy import/first.
    
    Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
---
 .../test/defineChart.test.tsx                      |  7 ++-
 .../superset-ui-glyph-core/test/generators.test.ts | 43 ++++++++++++++-----
 .../explore/components/GlyphOptionsPanel.test.tsx  | 50 +++++++++++++---------
 3 files changed, 67 insertions(+), 33 deletions(-)

diff --git 
a/superset-frontend/packages/superset-ui-glyph-core/test/defineChart.test.tsx 
b/superset-frontend/packages/superset-ui-glyph-core/test/defineChart.test.tsx
index 57e0ff7e169..c3b84f103a9 100644
--- 
a/superset-frontend/packages/superset-ui-glyph-core/test/defineChart.test.tsx
+++ 
b/superset-frontend/packages/superset-ui-glyph-core/test/defineChart.test.tsx
@@ -33,6 +33,7 @@ import {
   Select,
   Text,
 } from '@superset-ui/glyph-core';
+import type { ChartDefinition } from '@superset-ui/glyph-core/defineChart';
 
 // Helper: instantiate a plugin and reach its controlPanel config.
 function instantiate(PluginClass: ReturnType<typeof defineChart>) {
@@ -422,10 +423,12 @@ describe('defineChart - overrides + formDataOverrides + 
onInit', () => {
   });
 
   test('formDataOverrides is preserved on controlPanel', () => {
-    const fdo = (formData: Record<string, unknown>) => ({
+    const fdo = ((formData: Record<string, unknown>) => ({
       ...formData,
       custom: 'extra',
-    });
+    })) as unknown as ChartDefinition<
+      Record<string, never>
+    >['formDataOverrides'];
     const Plugin = defineChart({
       metadata: { name: 'Test', thumbnail: MIN_THUMBNAIL },
       arguments: {},
diff --git 
a/superset-frontend/packages/superset-ui-glyph-core/test/generators.test.ts 
b/superset-frontend/packages/superset-ui-glyph-core/test/generators.test.ts
index a22458c3cf4..808468afcb8 100644
--- a/superset-frontend/packages/superset-ui-glyph-core/test/generators.test.ts
+++ b/superset-frontend/packages/superset-ui-glyph-core/test/generators.test.ts
@@ -31,7 +31,18 @@ import {
   Temporal,
   Text,
 } from '@superset-ui/glyph-core';
-import type { GlyphArguments } from '@superset-ui/glyph-core/generators';
+import type { Argument } from '@superset-ui/glyph-core';
+import type {
+  GlyphArgConfig,
+  GlyphArguments,
+} from '@superset-ui/glyph-core/generators';
+
+// `new Map([...])` narrows its value type from the first tuple, which trips
+// up TS when an args map mixes Metric / Checkbox / Select entries. This
+// helper widens the value type to typeof Argument | GlyphArgConfig.
+type GlyphArgValue = typeof Argument | GlyphArgConfig;
+const glyphMap = (entries: Array<readonly [string, GlyphArgValue]>) =>
+  new Map<string, GlyphArgValue>(entries) as GlyphArguments;
 
 describe('getControlConfig - per argument type', () => {
   test('Select → SelectControl with options and clearable=false', () => {
@@ -59,7 +70,13 @@ describe('getControlConfig - per argument type', () => {
   });
 
   test('Int → SliderControl with min/max/step', () => {
-    const I = Int.with({ label: 'Limit', default: 50, min: 0, max: 1000, step: 
5 });
+    const I = Int.with({
+      label: 'Limit',
+      default: 50,
+      min: 0,
+      max: 1000,
+      step: 5,
+    });
     const cfg = getControlConfig(I, 'limit');
     expect(cfg.type).toBe('SliderControl');
     expect(cfg.label).toBe('Limit');
@@ -102,7 +119,7 @@ describe('getControlConfig - per argument type', () => {
 
 describe('generateControlPanel', () => {
   test('produces Query and Chart Options sections', () => {
-    const args: GlyphArguments = new Map([
+    const args = glyphMap([
       ['metric', Metric],
       ['showLegend', Checkbox.with({ label: 'Legend', default: true })],
     ]);
@@ -121,7 +138,8 @@ describe('generateControlPanel', () => {
       s => s && 'label' in s && s.label === 'Query',
     );
     expect(querySection).toBeDefined();
-    const rows = (querySection as { controlSetRows: unknown[][] 
}).controlSetRows;
+    const rows = (querySection as { controlSetRows: unknown[][] })
+      .controlSetRows;
     expect(rows).toContainEqual(['metric']);
   });
 
@@ -131,7 +149,8 @@ describe('generateControlPanel', () => {
     const querySection = cp.controlPanelSections.find(
       s => s && 'label' in s && s.label === 'Query',
     );
-    const rows = (querySection as { controlSetRows: unknown[][] 
}).controlSetRows;
+    const rows = (querySection as { controlSetRows: unknown[][] })
+      .controlSetRows;
     expect(rows).toContainEqual(['groupby']);
   });
 
@@ -141,7 +160,8 @@ describe('generateControlPanel', () => {
     const querySection = cp.controlPanelSections.find(
       s => s && 'label' in s && s.label === 'Query',
     );
-    const rows = (querySection as { controlSetRows: unknown[][] 
}).controlSetRows;
+    const rows = (querySection as { controlSetRows: unknown[][] })
+      .controlSetRows;
     expect(rows).toContainEqual(['x_axis']);
     expect(rows).toContainEqual(['time_grain_sqla']);
   });
@@ -152,7 +172,8 @@ describe('generateControlPanel', () => {
     const querySection = cp.controlPanelSections.find(
       s => s && 'label' in s && s.label === 'Query',
     );
-    const rows = (querySection as { controlSetRows: unknown[][] 
}).controlSetRows;
+    const rows = (querySection as { controlSetRows: unknown[][] })
+      .controlSetRows;
     expect(rows).toContainEqual(['adhoc_filters']);
   });
 
@@ -194,7 +215,8 @@ describe('generateControlPanel', () => {
     const chartOpts = cp.controlPanelSections.find(
       s => s && 'label' in s && s.label === 'Chart Options',
     );
-    const row = (chartOpts as { controlSetRows: unknown[][] 
}).controlSetRows[0];
+    const row = (chartOpts as { controlSetRows: unknown[][] })
+      .controlSetRows[0];
     const item = (row as Array<{ config: Record<string, unknown> }>)[0];
     expect(item.config.visibility).toBe(visibility);
     expect(item.config.resetOnHide).toBe(true);
@@ -226,7 +248,8 @@ describe('generateControlPanel', () => {
     const chartOpts = cp.controlPanelSections.find(
       s => s && 'label' in s && s.label === 'Chart Options',
     );
-    const optRows = (chartOpts as { controlSetRows: unknown[][] 
}).controlSetRows;
+    const optRows = (chartOpts as { controlSetRows: unknown[][] })
+      .controlSetRows;
     expect(optRows).toContainEqual(['custom_chart_opt']);
   });
 });
@@ -389,7 +412,7 @@ describe('generateTransformProps', () => {
 
 describe('createGlyphPlugin', () => {
   test('returns both controlPanel and transformProps', () => {
-    const args: GlyphArguments = new Map([
+    const args = glyphMap([
       ['metric', Metric],
       ['show', Checkbox.with({ label: 'S', default: true })],
     ]);
diff --git 
a/superset-frontend/src/explore/components/GlyphOptionsPanel.test.tsx 
b/superset-frontend/src/explore/components/GlyphOptionsPanel.test.tsx
index f5d844f3d4f..4138d3924ed 100644
--- a/superset-frontend/src/explore/components/GlyphOptionsPanel.test.tsx
+++ b/superset-frontend/src/explore/components/GlyphOptionsPanel.test.tsx
@@ -27,6 +27,8 @@ import {
   Temporal,
   Text,
 } from '@superset-ui/glyph-core';
+import GlyphOptionsPanel from './GlyphOptionsPanel';
+import type { ExpandedControlPanelSectionConfig } from 
'./ControlPanelsContainer';
 
 // Capture the props that Control receives so we can assert on them.
 const controlPropsCaptured: Array<Record<string, unknown>> = [];
@@ -55,9 +57,6 @@ jest.mock('./StashFormDataContainer', () => ({
   ),
 }));
 
-import GlyphOptionsPanel from './GlyphOptionsPanel';
-import type { ExpandedControlPanelSectionConfig } from 
'./ControlPanelsContainer';
-
 function makeSection(controlSetRows: unknown[][]) {
   return {
     label: 'Chart Options',
@@ -65,11 +64,13 @@ function makeSection(controlSetRows: unknown[][]) {
   } as unknown as ExpandedControlPanelSectionConfig;
 }
 
-function defaultProps(overrides: Partial<Parameters<typeof 
GlyphOptionsPanel>[0]> = {}) {
+function defaultProps(
+  overrides: Partial<Parameters<typeof GlyphOptionsPanel>[0]> = {},
+) {
   return {
     glyphArgs: {},
     chartOptionsSection: makeSection([]),
-    formData: { viz_type: 'test' } as Parameters<
+    formData: { datasource: '1__table', viz_type: 'test' } as Parameters<
       typeof GlyphOptionsPanel
     >[0]['formData'],
     controls: {},
@@ -89,9 +90,7 @@ beforeEach(() => {
 
 describe('GlyphOptionsPanel - empty/null behavior', () => {
   test('returns null when there are no rows', () => {
-    const { container } = render(
-      <GlyphOptionsPanel {...defaultProps()} />,
-    );
+    const { container } = render(<GlyphOptionsPanel {...defaultProps()} />);
     expect(container.firstChild).toBeNull();
   });
 
@@ -117,9 +116,11 @@ describe('GlyphOptionsPanel - glyph-arg rendering', () => {
           chartOptionsSection: makeSection([
             [{ name: 'showLegend', config: { type: 'CheckboxControl' } }],
           ]),
-          formData: { viz_type: 'test', showLegend: true } as Parameters<
-            typeof GlyphOptionsPanel
-          >[0]['formData'],
+          formData: {
+            datasource: '1__table',
+            viz_type: 'test',
+            showLegend: true,
+          } as Parameters<typeof GlyphOptionsPanel>[0]['formData'],
         })}
       />,
     );
@@ -142,9 +143,11 @@ describe('GlyphOptionsPanel - glyph-arg rendering', () => {
           chartOptionsSection: makeSection([
             [{ name: 'title', config: { type: 'TextControl' } }],
           ]),
-          formData: { viz_type: 'test', title: 'From form data' } as 
Parameters<
-            typeof GlyphOptionsPanel
-          >[0]['formData'],
+          formData: {
+            datasource: '1__table',
+            viz_type: 'test',
+            title: 'From form data',
+          } as Parameters<typeof GlyphOptionsPanel>[0]['formData'],
           // controls has a STALE value - panel should ignore it
           controls: {
             title: {
@@ -229,6 +232,7 @@ describe('GlyphOptionsPanel - visibility (visibleWhen)', () 
=> {
             [{ name: 'legendPosition', config: { type: 'SelectControl' } }],
           ]),
           formData: {
+            datasource: '1__table',
             viz_type: 'test',
             showLegend: false,
           } as Parameters<typeof GlyphOptionsPanel>[0]['formData'],
@@ -236,7 +240,9 @@ describe('GlyphOptionsPanel - visibility (visibleWhen)', () 
=> {
       />,
     );
 
-    const posProps = controlPropsCaptured.find(p => p.name === 
'legendPosition');
+    const posProps = controlPropsCaptured.find(
+      p => p.name === 'legendPosition',
+    );
     expect(posProps).toBeDefined();
     expect(posProps!.isVisible).toBe(false);
   });
@@ -263,6 +269,7 @@ describe('GlyphOptionsPanel - visibility (visibleWhen)', () 
=> {
             [{ name: 'legendPosition', config: { type: 'SelectControl' } }],
           ]),
           formData: {
+            datasource: '1__table',
             viz_type: 'test',
             showLegend: true,
           } as Parameters<typeof GlyphOptionsPanel>[0]['formData'],
@@ -270,7 +277,9 @@ describe('GlyphOptionsPanel - visibility (visibleWhen)', () 
=> {
       />,
     );
 
-    const posProps = controlPropsCaptured.find(p => p.name === 
'legendPosition');
+    const posProps = controlPropsCaptured.find(
+      p => p.name === 'legendPosition',
+    );
     expect(posProps!.isVisible).toBe(true);
   });
 
@@ -377,7 +386,9 @@ describe('GlyphOptionsPanel - fallback to renderControl', 
() => {
     );
 
     // Glyph arg went through Control mock
-    expect(controlPropsCaptured.find(p => p.name === 
'showLegend')).toBeDefined();
+    expect(
+      controlPropsCaptured.find(p => p.name === 'showLegend'),
+    ).toBeDefined();
     // Non-glyph item went through renderControl
     expect(renderControl).toHaveBeenCalledWith(
       expect.objectContaining({ name: 'color_scheme' }),
@@ -406,9 +417,7 @@ describe('GlyphOptionsPanel - section header', () => {
     const Show = Checkbox.with({ label: 'Show', default: true });
     const section = {
       label: 'My Custom Section',
-      controlSetRows: [
-        [{ name: 'show', config: { type: 'CheckboxControl' } }],
-      ],
+      controlSetRows: [[{ name: 'show', config: { type: 'CheckboxControl' } 
}]],
     } as unknown as ExpandedControlPanelSectionConfig;
 
     render(
@@ -422,4 +431,3 @@ describe('GlyphOptionsPanel - section header', () => {
     expect(screen.getAllByText('My Custom Section').length).toBeGreaterThan(0);
   });
 });
-

Reply via email to