Files
superset2/superset-frontend/plugins/plugin-chart-country-map/test/plugin/transformProps.test.ts
Superset Dev adbf5bcff8 feat(plugin-chart-country-map): ship all 33 NE worldviews at Admin 0
Previously the build only emitted the ukr (Ukraine) worldview, so the
worldview dropdown had a single option even though it claimed otherwise.
Build now produces Admin 0 GeoJSON for every NE-published editorial:
default, arg, bdg, bra, chn, deu, egy, esp, fra, gbr, grc, idn, ind, iso,
isr, ita, jpn, kor, mar, nep, nld, pak, pol, prt, pse, rus, sau, swe, tur,
twn, ukr, usa, vnm (33 total).

NE does not publish per-worldview Admin 1 variants, so subdivisions within
a country come from a single shared file. The frontend now always points
Admin 1, regional aggregation, and composite URLs at the ukr-prefixed
shared outputs regardless of the selected worldview — the worldview
control only affects the world (Admin 0) map.

- build.py: expand WORLDVIEWS_ADMIN_0 to 33 worldviews; main() builds
  Admin 0 for all of them, Admin 1 only for ukr
- transformProps.ts: introduce SHARED_ADMIN1_WORLDVIEW = 'ukr'; pin all
  non-Admin-0 URLs to it
- controlPanel.tsx: WORLDVIEW_LABELS now covers all 33 codes; unrecognized
  codes still fall back to raw code for forward-compat
- transformProps.test.ts: cover shared-Admin1 contract (admin1+chn still
  resolves to ukr_admin1_*)
- pre-commit: exclude .geo.json from check-added-large-files (existing
  rule only excluded .geojson and would block these ~2MB worldview files)
- README + SIP: document the worldview model and check off Phase 1 item

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 09:10:04 -07:00

143 lines
4.4 KiB
TypeScript

/**
* 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 { ChartProps } from '@superset-ui/core';
import transformProps from '../../src/plugin/transformProps';
import { CountryMapChartProps, CountryMapFormData } from '../../src/types';
const baseFormData: CountryMapFormData = {
datasource: '3__table',
viz_type: 'country_map',
};
const buildChartProps = (
formData: Partial<CountryMapFormData>,
data: Record<string, unknown>[] = [],
): CountryMapChartProps =>
new ChartProps({
formData: { ...baseFormData, ...formData },
width: 800,
height: 600,
queriesData: [{ data }],
} as any) as CountryMapChartProps;
test('Admin 0 (no country) → world choropleth URL', () => {
const out = transformProps(
buildChartProps({ admin_level: 0, worldview: 'ukr' }),
);
expect(out.geoJsonUrl).toBe(
'/static/assets/country-maps/ukr_admin0.geo.json',
);
});
test('Admin 1 + country → per-country file URL (worldview-agnostic)', () => {
const out = transformProps(
buildChartProps({ admin_level: 1, country: 'FRA', worldview: 'ukr' }),
);
expect(out.geoJsonUrl).toBe(
'/static/assets/country-maps/ukr_admin1_FRA.geo.json',
);
});
test('Admin 1 stays on the shared (ukr) file regardless of worldview', () => {
const out = transformProps(
buildChartProps({ admin_level: 1, country: 'FRA', worldview: 'chn' }),
);
expect(out.geoJsonUrl).toBe(
'/static/assets/country-maps/ukr_admin1_FRA.geo.json',
);
});
test('Region set + country → regional aggregation URL (shared)', () => {
const out = transformProps(
buildChartProps({
admin_level: 1,
country: 'TUR',
region_set: 'nuts_1',
worldview: 'rus', // exotic worldview — regional URL still resolves to ukr
}),
);
expect(out.geoJsonUrl).toBe(
'/static/assets/country-maps/regional_TUR_nuts_1_ukr.geo.json',
);
});
test('Composite overrides admin_level + country (shared across worldviews)', () => {
const out = transformProps(
buildChartProps({
admin_level: 1,
country: 'FRA',
composite: 'france_overseas',
worldview: 'chn',
}),
);
expect(out.geoJsonUrl).toBe(
'/static/assets/country-maps/composite_france_overseas_ukr.geo.json',
);
});
test('Worldview defaults to ukr when not specified', () => {
const out = transformProps(buildChartProps({ admin_level: 0 }));
expect(out.geoJsonUrl).toBe(
'/static/assets/country-maps/ukr_admin0.geo.json',
);
});
test('Different worldview reflected in URL', () => {
const out = transformProps(
buildChartProps({ admin_level: 0, worldview: 'default' }),
);
expect(out.geoJsonUrl).toBe(
'/static/assets/country-maps/default_admin0.geo.json',
);
});
test('Admin 1 without country → no URL (chart UI should prompt)', () => {
const out = transformProps(buildChartProps({ admin_level: 1 }));
expect(out.geoJsonUrl).toBeNull();
});
test('Passes through metricName, numberFormat, linearColorScheme', () => {
const out = transformProps(
buildChartProps({
admin_level: 0,
metric: 'sum__num',
number_format: 'SMART_NUMBER',
linear_color_scheme: 'schemeBlues',
}),
);
expect(out.metricName).toBe('sum__num');
expect(out.numberFormat).toBe('SMART_NUMBER');
expect(out.linearColorScheme).toBe('schemeBlues');
});
test('Passes through query data rows', () => {
const data = [
{ iso: 'FR-75C', sum__num: 100 },
{ iso: 'FR-971', sum__num: 50 },
];
const out = transformProps(buildChartProps({ admin_level: 0 }, data));
expect(out.data).toEqual(data);
});
test('Passes through width/height', () => {
const out = transformProps(buildChartProps({ admin_level: 0 }));
expect(out.width).toBe(800);
expect(out.height).toBe(600);
});