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

asoare pushed a commit to branch alexandrusoare/fix/world-map
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 2a7b69754c98a882a6efde633364d8d43490be40
Author: alexandrusoare <[email protected]>
AuthorDate: Tue Feb 17 14:32:46 2026 +0200

    adding tests
---
 .../test/WorldMap.test.ts                          | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)

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 096c558bc63..ec3df0fe743 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
@@ -387,3 +387,46 @@ test('does not handle mouse events when inContextMenu is 
true', () => {
   expect(fillChangeCalls.length).toBe(0);
   expect(fillStyleChangeCalls.length).toBe(0);
 });
+
+test('does not throw error when onContextMenu is undefined', () => {
+  const propsWithoutContextMenu = {
+    ...baseProps,
+    onContextMenu: undefined,
+  };
+
+  // Should not throw
+  expect(() => {
+    WorldMap(container, propsWithoutContextMenu as any);
+  }).not.toThrow();
+});
+
+test('calls onContextMenu when provided and right-click occurs', () => {
+  const mockOnContextMenu = jest.fn();
+  const propsWithContextMenu = {
+    ...baseProps,
+    onContextMenu: mockOnContextMenu,
+  };
+
+  let contextMenuHandler: ((source: any) => void) | undefined;
+
+  mockSvg.on.mockImplementation((event: string, handler: any) => {
+    if (event === 'contextmenu') {
+      contextMenuHandler = handler;
+    }
+    return mockSvg;
+  });
+
+  // Mock d3.event
+  (d3 as any).event = {
+    preventDefault: jest.fn(),
+    clientX: 100,
+    clientY: 200,
+  };
+
+  WorldMap(container, propsWithContextMenu);
+
+  expect(contextMenuHandler).toBeDefined();
+  contextMenuHandler!({ country: 'USA' });
+
+  expect(mockOnContextMenu).toHaveBeenCalledWith(100, 200, expect.any(Object));
+});

Reply via email to