also looking at this
fix(dashboard): the regions panel says California, not CA
#63
4 files
+145
-9
| @@ -0,0 +1,45 @@ | ||
| 1 | import { describe, expect, it } from 'bun:test' | |
| 2 | import { subdivisionName } from '../../app/Analytics/regions' | |
| 3 | ||
| 4 | /** | |
| 5 | * The regions panel reads `PH-07` out of the database and has to print | |
| 6 | * something a person recognises. These pin the lookup, and the tie-break it | |
| 7 | * needs, because `subdivisions.json` is regenerated from DB-IP and a rebuild | |
| 8 | * that changed either would quietly change what every row says. | |
| 9 | */ | |
| 10 | describe('subdivisionName', () => { | |
| 11 | it('names the codes the panel actually shows', () => { | |
| 12 | expect(subdivisionName('US-CA')).toBe('California') | |
| 13 | expect(subdivisionName('PH-07')).toBe('Central Visayas') | |
| 14 | expect(subdivisionName('GB-ENG')).toBe('England') | |
| 15 | }) | |
| 16 | ||
| 17 | it('keeps the accented spelling when the table carries both', () => { | |
| 18 | // DB-IP has 'Baden-Wurttemberg' and 'Baden-Württemberg' against DE-BW, and | |
| 19 | // the obvious tie-break — shortest wins — picks the mangled one. | |
| 20 | expect(subdivisionName('DE-BW')).toBe('Baden-Württemberg') | |
| 21 | }) | |
| 22 | ||
| 23 | it('prefers the plainest form when neither spelling is accented', () => { | |
| 24 | expect(subdivisionName('DE-BE')).toBe('Berlin') | |
| 25 | expect(subdivisionName('PH-05')).toBe('Bicol') | |
| 26 | }) | |
| 27 | ||
| 28 | it('answers null rather than guessing, so the row keeps its code', () => { | |
| 29 | // A real place the table does not know. `PH-XX` on screen is honest; an | |
| 30 | // invented name is not. | |
| 31 | expect(subdivisionName('PH-XX')).toBeNull() | |
| 32 | expect(subdivisionName('US')).toBeNull() | |
| 33 | expect(subdivisionName('')).toBeNull() | |
| 34 | expect(subdivisionName(null)).toBeNull() | |
| 35 | expect(subdivisionName('nonsense')).toBeNull() | |
| 36 | }) | |
| 37 | ||
| 38 | it('covers enough of the table to be worth having', () => { | |
| 39 | // A guard on the data rather than the code: a regenerated file that lost | |
| 40 | // most of its countries would still pass every assertion above. | |
| 41 | const named = ['US-CA', 'US-NY', 'GB-ENG', 'DE-BY', 'FR-IDF', 'JP-13', 'AU-NSW', 'PH-07', 'CA-ON', 'BR-SP'] | |
| 42 | for (const code of named) | |
| 43 | expect(subdivisionName(code)).toBeTruthy() | |
| 44 | }) | |
| 45 | }) | |