Compare commits

...

1 Commits

Author SHA1 Message Date
rusackas
85a4903fcc fix(viz): correct duplicate/incorrect ISO codes in Iran country map
Tehran and Alborz provinces both used IR-07 in the Iran GeoJSON, and
Razavi Khorasan was assigned IR-30 (Alborz's actual code), leaving
IR-09 unused. This made it impossible to color Tehran and Alborz
independently on the country map viz and mapped Razavi Khorasan data
to the wrong region. Alborz now uses IR-30 and Razavi Khorasan uses
IR-09, matching ISO 3166-2:IR, with a test pinning uniqueness of the
ISO codes.

Fixes #31991
2026-07-26 06:44:19 -07:00
2 changed files with 61 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,59 @@
/**
* 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 fs from 'fs';
import path from 'path';
// The geojson is loaded via fs rather than a normal import because the
// webpack/jest loaders treat *.geojson as an opaque asset (a URL string in
// the browser build, an empty mock object under jest), so neither exposes
// the actual feature data to a unit test.
const iranGeojsonPath = path.join(
__dirname,
'..',
'..',
'src',
'countries',
'iran.geojson',
);
type IranFeature = {
properties: { ISO: string; NAME_1: string };
};
const getIranFeatures = (): IranFeature[] =>
JSON.parse(fs.readFileSync(iranGeojsonPath, 'utf-8')).features;
test('every province in the Iran map has a unique ISO code', () => {
const isoCodes = getIranFeatures().map(feature => feature.properties.ISO);
const uniqueIsoCodes = new Set(isoCodes);
expect(uniqueIsoCodes.size).toBe(isoCodes.length);
});
test('Tehran, Alborz and Razavi Khorasan have their correct, distinct ISO codes', () => {
const provincesByIso = Object.fromEntries(
getIranFeatures().map(feature => [
feature.properties.NAME_1,
feature.properties.ISO,
]),
);
expect(provincesByIso.Tehran).toBe('IR-07');
expect(provincesByIso.Alborz).toBe('IR-30');
expect(provincesByIso['Razavi Khorasan']).toBe('IR-09');
});