Compare commits

...
Author SHA1 Message Date
rusackasandClaude Opus 4.8 01fe0c8e77 fix: rename provincesByIso to isoByProvince in Iran test
The map is keyed by province name (NAME_1) and maps to ISO codes, not
the other way around; the old name implied the opposite.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 14:53:49 -07:00
rusackasandClaude Opus 4.8 d9349d2759 test: assert Iran province count and non-empty ISO codes
Guards against a silently deleted province: the uniqueness check alone
would still pass on an incomplete or empty feature set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 14:53:17 -07:00
rusackas a621000078 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-08-12 14:53:17 -07:00
@@ -0,0 +1,66 @@
/**
* 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, non-empty ISO code', () => {
const features = getIranFeatures();
// Iran has 31 provinces; assert the count so a deleted feature is caught,
// not just a duplicated ISO code among whatever features remain.
expect(features).toHaveLength(31);
const isoCodes = features.map(feature => feature.properties.ISO);
isoCodes.forEach(iso => expect(iso).toBeTruthy());
const uniqueIsoCodes = new Set(isoCodes);
expect(uniqueIsoCodes.size).toBe(isoCodes.length);
});
test('Tehran, Alborz and Razavi Khorasan have their correct, distinct ISO codes', () => {
const isoByProvince = Object.fromEntries(
getIranFeatures().map(feature => [
feature.properties.NAME_1,
feature.properties.ISO,
]),
);
expect(isoByProvince.Tehran).toBe('IR-07');
expect(isoByProvince.Alborz).toBe('IR-30');
expect(isoByProvince['Razavi Khorasan']).toBe('IR-09');
});