Add hierarchical geography and cloud-hosted profile images
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
const test=require('node:test'),assert=require('node:assert/strict');
|
||||
const geo=require('./web/geography.js');
|
||||
test('legacy known China path upgrades losslessly',()=>{
|
||||
const v=geo.infer({province:'山东省',city:'烟台市',district:'莱阳市'});
|
||||
assert.equal(v.mode,'china');assert.equal(v.districtCode,'370682');
|
||||
assert.match(geo.label(v),/山东省 · 烟台市 · 莱阳市/);
|
||||
});
|
||||
test('unknown historic names are preserved in custom mode',()=>{
|
||||
const v=geo.infer({nativeCountry:'中国',nativeProvince:'山东',nativeCity:'登州府'},'native');
|
||||
assert.equal(v.mode,'custom');assert.equal(v.city,'登州府');
|
||||
});
|
||||
test('changing an ancestor clears every lower selection',()=>{
|
||||
let v=geo.infer({province:'山东省',city:'烟台市',district:'莱阳市'});
|
||||
v=geo.change(v,'provinceCode','11');assert.equal(v.province,'北京市');
|
||||
assert.equal(v.city,'');assert.equal(v.cityCode,'');assert.equal(v.districtCode,'');
|
||||
v=geo.change(v,'mode','world');assert.equal(v.provinceCode,'');assert.equal(v.countryCode,'');
|
||||
v=geo.change(v,'countryCode','US');assert.equal(v.country,'美国');
|
||||
v=geo.change({...v,city:'Boston'},'countryCode','JP');assert.equal(v.city,'');
|
||||
});
|
||||
test('self-defined celestial names and deep paths display without pretending to be administrative codes',()=>{
|
||||
const v=geo.infer({geography:{mode:'custom',body:'火星',path:'基地 / 居住区 / 一栋 / 二层'}});
|
||||
assert.equal(geo.label(v),'火星 · 基地 / 居住区 / 一栋 / 二层');
|
||||
});
|
||||
test('world selection can return to China cascade',()=>{
|
||||
assert.equal(geo.change({mode:'world'},'countryCode','CN').mode,'china');
|
||||
});
|
||||
Reference in New Issue
Block a user