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

rusackas pushed a commit to branch chore/ts-migration-dashboard
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/chore/ts-migration-dashboard 
by this push:
     new b2510ebca0c fix(world-map): add proper TypeScript types to WorldMap 
tests
b2510ebca0c is described below

commit b2510ebca0c715ba1380079c3f42598ca8313bf6
Author: Evan Rusackas <[email protected]>
AuthorDate: Fri Feb 6 10:59:12 2026 -0800

    fix(world-map): add proper TypeScript types to WorldMap tests
    
    - Export WorldMapProps interface from WorldMap.ts
    - Add proper type definitions in test file
    - Use getNumberFormatter() instead of jest mock for formatter
    - Add missing latitude/longitude to test data
    - Import and use ColorBy enum properly
    - Cast d3 properly for jest.spyOn
    
    Co-Authored-By: Claude Opus 4.5 <[email protected]>
---
 .../legacy-plugin-chart-world-map/src/WorldMap.ts  |  2 +-
 .../test/WorldMap.test.ts                          | 74 +++++++++++++++++++---
 2 files changed, 65 insertions(+), 11 deletions(-)

diff --git 
a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.ts 
b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.ts
index e1f6fe8ef85..f5c873b2ef2 100644
--- a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.ts
+++ b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/WorldMap.ts
@@ -49,7 +49,7 @@ interface WorldMapFilterState {
   [key: string]: unknown;
 }
 
-interface WorldMapProps {
+export interface WorldMapProps {
   countryFieldtype: string;
   entity: string;
   data: WorldMapDataEntry[];
diff --git 
a/superset-frontend/plugins/legacy-plugin-chart-world-map/test/WorldMap.test.ts 
b/superset-frontend/plugins/legacy-plugin-chart-world-map/test/WorldMap.test.ts
index b7439406589..8ae4109ea41 100644
--- 
a/superset-frontend/plugins/legacy-plugin-chart-world-map/test/WorldMap.test.ts
+++ 
b/superset-frontend/plugins/legacy-plugin-chart-world-map/test/WorldMap.test.ts
@@ -18,7 +18,45 @@
  */
 
 import d3 from 'd3';
+import { getNumberFormatter, ValueFormatter } from '@superset-ui/core';
 import WorldMap from '../src/WorldMap';
+import { ColorBy } from '../src/utils';
+
+interface WorldMapDataEntry {
+  country: string;
+  code: string;
+  latitude: number;
+  longitude: number;
+  name: string;
+  m1: number;
+  m2: number;
+}
+
+interface WorldMapProps {
+  countryFieldtype: string;
+  entity: string;
+  data: WorldMapDataEntry[];
+  width: number;
+  height: number;
+  maxBubbleSize: number;
+  showBubbles: boolean;
+  linearColorScheme: string;
+  color: string;
+  colorBy: ColorBy;
+  colorScheme: string;
+  sliceId: number;
+  theme: Record<string, unknown>;
+  onContextMenu: (
+    x: number,
+    y: number,
+    payload: Record<string, unknown>,
+  ) => void;
+  setDataMask: (dataMask: Record<string, unknown>) => void;
+  inContextMenu: boolean;
+  filterState: { selectedValues?: string[] };
+  emitCrossFilters: boolean;
+  formatter: ValueFormatter;
+}
 
 type MouseEventHandler = (this: HTMLElement) => void;
 
@@ -56,12 +94,28 @@ jest.mock('datamaps/dist/datamaps.all.min', () => {
 });
 
 let container: HTMLElement;
-const mockFormatter = jest.fn(val => String(val));
+const formatter = getNumberFormatter();
 
-const baseProps = {
+const baseProps: WorldMapProps = {
   data: [
-    { country: 'USA', name: 'United States', m1: 100, m2: 200, code: 'US' },
-    { country: 'CAN', name: 'Canada', m1: 50, m2: 100, code: 'CA' },
+    {
+      country: 'USA',
+      name: 'United States',
+      m1: 100,
+      m2: 200,
+      code: 'US',
+      latitude: 37.0902,
+      longitude: -95.7129,
+    },
+    {
+      country: 'CAN',
+      name: 'Canada',
+      m1: 50,
+      m2: 100,
+      code: 'CA',
+      latitude: 56.1304,
+      longitude: -106.3468,
+    },
   ],
   width: 600,
   height: 400,
@@ -69,7 +123,7 @@ const baseProps = {
   showBubbles: false,
   linearColorScheme: 'schemeRdYlBu',
   color: '#61B0B7',
-  colorBy: 'country',
+  colorBy: ColorBy.Country,
   colorScheme: 'supersetColors',
   sliceId: 123,
   theme: {
@@ -85,7 +139,7 @@ const baseProps = {
   inContextMenu: false,
   filterState: { selectedValues: [] },
   emitCrossFilters: false,
-  formatter: mockFormatter,
+  formatter,
 };
 
 beforeEach(() => {
@@ -143,7 +197,7 @@ test('stores original fill color on mouseover', () => {
     selectAll: jest.fn().mockReturnValue({ remove: jest.fn() }),
   };
 
-  jest.spyOn(d3, 'select').mockReturnValue(mockD3Selection as any);
+  jest.spyOn(d3 as any, 'select').mockReturnValue(mockD3Selection as any);
 
   // Capture the mouseover handler
   mockSvg.on.mockImplementation((event: string, handler: MouseEventHandler) => 
{
@@ -198,7 +252,7 @@ test('restores original fill color on mouseout for country 
with data', () => {
     selectAll: jest.fn().mockReturnValue({ remove: jest.fn() }),
   };
 
-  jest.spyOn(d3, 'select').mockReturnValue(mockD3Selection as any);
+  jest.spyOn(d3 as any, 'select').mockReturnValue(mockD3Selection as any);
 
   // Capture the mouseout handler
   mockSvg.on.mockImplementation((event: string, handler: MouseEventHandler) => 
{
@@ -254,7 +308,7 @@ test('restores default fill color on mouseout for country 
with no data', () => {
     selectAll: jest.fn().mockReturnValue({ remove: jest.fn() }),
   };
 
-  jest.spyOn(d3, 'select').mockReturnValue(mockD3Selection as any);
+  jest.spyOn(d3 as any, 'select').mockReturnValue(mockD3Selection as any);
 
   mockSvg.on.mockImplementation((event: string, handler: MouseEventHandler) => 
{
     if (event === 'mouseout') {
@@ -296,7 +350,7 @@ test('does not handle mouse events when inContextMenu is 
true', () => {
     selectAll: jest.fn().mockReturnValue({ remove: jest.fn() }),
   };
 
-  jest.spyOn(d3, 'select').mockReturnValue(mockD3Selection as any);
+  jest.spyOn(d3 as any, 'select').mockReturnValue(mockD3Selection as any);
 
   mockSvg.on.mockImplementation((event: string, handler: MouseEventHandler) => 
{
     if (event === 'mouseover') {

Reply via email to