|
26 | 26 | import { describe, it, expect } from 'vitest'; |
27 | 27 | import { resolveNavItemLabel, type NavTargetLabelResolver } from '@object-ui/layout'; |
28 | 28 | import type { NavigationItem } from '@object-ui/types'; |
| 29 | +import { resolveI18nLabel, type I18nLabel } from '@objectstack/spec/ui'; |
29 | 30 | import { |
30 | 31 | clearedLabel, |
31 | 32 | inheritedNavEntryText, |
32 | 33 | navEntryLabelText, |
| 34 | + navItemLabelText, |
| 35 | + renamedLabel, |
33 | 36 | type NavEntryLike, |
34 | 37 | } from './navItemLabel'; |
35 | 38 |
|
@@ -150,3 +153,57 @@ describe('objectui#11196 — clearedLabel restores inheritance, the inverse of r |
150 | 153 | expect(clearedLabel({ 'zh-CN': '客户' }, 'zh-CN')).toBeUndefined(); |
151 | 154 | }); |
152 | 155 | }); |
| 156 | + |
| 157 | +/** |
| 158 | + * #30910 — where the platform table splits a language by script, the resolver |
| 159 | + * reads a sibling of the locale's own script over a bare language of the other |
| 160 | + * one (`zh-TW` under `zh-Hant` in `{ zh, 'zh-TW' }`, bare `zh` meaning |
| 161 | + * `zh-Hans`). The entry a rename writes and a clear deletes must be that same |
| 162 | + * entry, or a Traditional editor overwrites the Simplified text while the |
| 163 | + * Traditional text stays on screen. Pinned against `resolveI18nLabel` itself. |
| 164 | + */ |
| 165 | +describe('#30910 — renamedLabel and clearedLabel change the entry the resolver shows', () => { |
| 166 | + /** `[map, designer locale, the key the resolver reads and an edit owns]` */ |
| 167 | + const OWNED: ReadonlyArray<readonly [Record<string, string>, string, string]> = [ |
| 168 | + [{ en: 'Customer', zh: '客户', 'zh-TW': '客戶' }, 'zh-Hant', 'zh-TW'], |
| 169 | + [{ en: 'Customer', zh: '客户', 'zh-TW': '客戶' }, 'zh-TW', 'zh-TW'], |
| 170 | + [{ en: 'Customer', zh: '客户', 'zh-HK': '客戶' }, 'zh-HK', 'zh-HK'], |
| 171 | + [{ en: 'Customer', zh: '客户', 'zh-Hant': '客戶' }, 'zh-HK', 'zh-Hant'], |
| 172 | + [{ en: 'Customer', 'zh-TW': '客戶', zh: '客户' }, 'zh-CN', 'zh'], |
| 173 | + [{ en: 'Customer', 'zh-TW': '客戶', zh: '客户' }, 'zh-Hans', 'zh'], |
| 174 | + ]; |
| 175 | + |
| 176 | + it.each(OWNED)('%j in %s: the resolver reads %s', (map, locale, key) => { |
| 177 | + expect(resolveI18nLabel(map as I18nLabel, locale)).toBe(map[key]); |
| 178 | + }); |
| 179 | + |
| 180 | + it.each(OWNED)('%j renamed in %s writes %s, shows the new text, and keeps every other entry', (map, locale, key) => { |
| 181 | + const next = renamedLabel(map as I18nLabel, 'RENAMED', locale) as Record<string, string>; |
| 182 | + expect(next[key]).toBe('RENAMED'); |
| 183 | + for (const other of Object.keys(map).filter((k) => k !== key)) expect(next[other]).toBe(map[other]); |
| 184 | + expect(Object.keys(next)).toEqual(Object.keys(map)); |
| 185 | + expect(navItemLabelText(next as I18nLabel, locale)).toBe('RENAMED'); |
| 186 | + }); |
| 187 | + |
| 188 | + it.each(OWNED)('%j cleared in %s deletes %s and nothing else', (map, locale, key) => { |
| 189 | + const rest = Object.fromEntries(Object.entries(map).filter(([k]) => k !== key)); |
| 190 | + expect(clearedLabel(map as I18nLabel, locale)).toEqual(rest); |
| 191 | + }); |
| 192 | + |
| 193 | + /** Byte-identical controls: `[map, locale, what main's rename wrote]`. */ |
| 194 | + const UNCHANGED: ReadonlyArray<readonly [Record<string, string>, string, Record<string, string>]> = [ |
| 195 | + // Neither the exact tag nor the bare language: the exact tag is added, a sibling region is not owned. |
| 196 | + [{ en: 'Customer', 'zh-CN': '客户', 'zh-TW': '客戶' }, 'zh-Hant', { en: 'Customer', 'zh-CN': '客户', 'zh-TW': '客戶', 'zh-Hant': 'RENAMED' }], |
| 197 | + [{ en: 'Customer', 'zh-TW': '客戶' }, 'zh-Hant', { en: 'Customer', 'zh-TW': '客戶', 'zh-Hant': 'RENAMED' }], |
| 198 | + // The bare language with no sibling of the locale's script: the bare language, as before. |
| 199 | + [{ en: 'Customer', zh: '客户' }, 'zh-Hant', { en: 'Customer', zh: 'RENAMED' }], |
| 200 | + [{ en: 'Customer', zh: '客户', 'zh-TW': '客戶' }, 'zh-CN', { en: 'Customer', zh: 'RENAMED', 'zh-TW': '客戶' }], |
| 201 | + // Languages the table names once. |
| 202 | + [{ en: 'Accounts', 'en-GB': 'Accounts (GB)' }, 'en-US', { en: 'RENAMED', 'en-GB': 'Accounts (GB)' }], |
| 203 | + [{ pt: 'Contas', 'pt-PT': 'Contas (PT)' }, 'pt-BR', { pt: 'RENAMED', 'pt-PT': 'Contas (PT)' }], |
| 204 | + ]; |
| 205 | + |
| 206 | + it.each(UNCHANGED)('%j renamed in %s writes exactly as before', (map, locale, expected) => { |
| 207 | + expect(renamedLabel(map as I18nLabel, 'RENAMED', locale)).toEqual(expected); |
| 208 | + }); |
| 209 | +}); |
0 commit comments