mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix(world-map): add fallback fill color when colorFn returns null (#38602)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit ba7271b4d8)
This commit is contained in:
committed by
Michael S. Molina
parent
4baedcc794
commit
aaaead02f1
@@ -489,6 +489,59 @@ test('popupTemplate returns tooltip HTML when country data exists', () => {
|
||||
expect(tooltipHtml).toContain('hoverinfo');
|
||||
});
|
||||
|
||||
test('assigns fill colors from sequential scheme when colorBy is metric', () => {
|
||||
WorldMap(container, {
|
||||
...baseProps,
|
||||
colorBy: ColorBy.Metric,
|
||||
});
|
||||
|
||||
const data = lastDatamapConfig?.data as Record<
|
||||
string,
|
||||
WorldMapDataEntry & { fillColor: string }
|
||||
>;
|
||||
expect(data).toHaveProperty('USA');
|
||||
expect(data).toHaveProperty('CAN');
|
||||
expect(data.USA).toMatchObject({
|
||||
country: 'USA',
|
||||
name: 'United States',
|
||||
m1: 100,
|
||||
});
|
||||
// fillColor should be a valid color string from the sequential scale
|
||||
expect(data.USA.fillColor).toMatch(/^(#|rgb)/);
|
||||
expect(data.CAN.fillColor).toMatch(/^(#|rgb)/);
|
||||
});
|
||||
|
||||
test('falls back to theme.colorBorder when metric values are null', () => {
|
||||
WorldMap(container, {
|
||||
...baseProps,
|
||||
colorBy: ColorBy.Metric,
|
||||
data: [
|
||||
{
|
||||
country: 'USA',
|
||||
name: 'United States',
|
||||
m1: null as unknown as number,
|
||||
m2: 200,
|
||||
code: 'US',
|
||||
latitude: 37.0902,
|
||||
longitude: -95.7129,
|
||||
},
|
||||
],
|
||||
} as any);
|
||||
|
||||
const data = lastDatamapConfig?.data as Record<string, { fillColor: string }>;
|
||||
expect(data.USA.fillColor).toBe('#e0e0e0');
|
||||
});
|
||||
|
||||
test('does not throw with empty data and metric coloring', () => {
|
||||
expect(() => {
|
||||
WorldMap(container, {
|
||||
...baseProps,
|
||||
colorBy: ColorBy.Metric,
|
||||
data: [],
|
||||
});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
test('popupTemplate handles null/undefined country data gracefully', () => {
|
||||
WorldMap(container, baseProps);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user