diff --git a/src/features/dns/Analysis.tsx b/src/features/dns/Analysis.tsx index 69ae0a78..599ec7d2 100644 --- a/src/features/dns/Analysis.tsx +++ b/src/features/dns/Analysis.tsx @@ -183,7 +183,7 @@ function CacheCard({listed, href}: {listed: boolean; href: string | null}) { {vm.card.usage && (
- {vm.card.usage.facts} +
)}

{vm.card.coverage}

diff --git a/src/features/dns/cache.test.ts b/src/features/dns/cache.test.ts index e3e3d1ad..7d69db11 100644 --- a/src/features/dns/cache.test.ts +++ b/src/features/dns/cache.test.ts @@ -15,19 +15,23 @@ const list = (usage?: DnsCacheList['usage']) => usage }) as DnsCacheList; -it('fills the bar by the entry count, its only limit, and states it as a fraction per locale', async () => { +it('fills the bar by the entry count, its only limit, and states entries and capacity apart', async () => { const card = cacheCard(list({entries: '4096', entry_capacity: '100000'}), 'en-US', t)!; expect(card.usage?.pct).toBe(4.1); - expect(card.usage?.facts).toBe('Entries: 4,096 / 100,000'); + expect(card.usage?.facts).toEqual([ + {label: 'Entries', value: '4,096'}, + {label: 'Capacity', value: '100,000'} + ]); expect(card.note).toBeUndefined(); expect(card.coverage).toBe('Caches Positive answers; held in memory only, cleared on restart'); expect(cacheCard(list({entries: '5', entry_capacity: '100000'}), 'en-US', t)!.usage?.value).toBe('<1%'); - // Chinese writes the fraction with a full-width slash and no spaces. - await Promise.all([loadLanguage('zh-TW'), loadLanguage('zh-CN')]); - for (const lang of ['zh-TW', 'zh-CN'] as const) - expect(cacheCard(list({entries: '322', entry_capacity: '100000'}), lang, (key, params) => translate(lang, key, params))!.usage?.facts).toMatch( - /322\uFF0F100,000$/ - ); + // A capacity past Number's exact range keeps every digit. + expect(cacheCard(list({entries: '1', entry_capacity: '18446744073709551615'}), 'en-US', t)!.usage?.facts[1].value).toBe('18,446,744,073,709,551,615'); + await loadLanguage('zh-TW'); + expect(cacheCard(list({entries: '322', entry_capacity: '100000'}), 'zh-TW', (key, params) => translate('zh-TW', key, params))!.usage?.facts).toEqual([ + {label: '條目', value: '322'}, + {label: '容量', value: '100,000'} + ]); }); it('claims no capacity when the backend does not report usage', () => { diff --git a/src/features/dns/cache.ts b/src/features/dns/cache.ts index d4b4cb4b..a31e10a7 100644 --- a/src/features/dns/cache.ts +++ b/src/features/dns/cache.ts @@ -23,7 +23,10 @@ export function cacheCard(list: DnsCacheList | undefined, locale: string, t: Tra pct, // A cache in use never reads as 0%. value: pct > 0 && pct < 0.5 ? '<' + t('ui.percent', {n: 1}) : t('ui.percent', {n: Math.round(pct)}), - facts: t('dns.chart.usageFacts', {entries: t('ui.fraction', {part: count(usage.entries), whole: count(capacity)})}) + facts: [ + {label: t('dns.chart.entries'), value: count(usage.entries)}, + {label: t('dns.chart.capacity'), value: count(capacity)} + ] } : null, coverage: t('dns.chart.coverage', { diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 49663c87..78531711 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -387,11 +387,13 @@ "dns.chart.cache": "Cache", "dns.chart.cacheNote": "Entries: {n}, capacity limit: not reported", "dns.chart.cacheRate": "Cache hit rate", + "dns.chart.capacity": "Capacity", "dns.chart.count": { "one": "{n} lookup", "other": "{n} lookups" }, "dns.chart.coverage": "Caches {kinds}; {persistent}", + "dns.chart.entries": "Entries", "dns.chart.failureRate": "Failure rate", "dns.chart.median": "Median", "dns.chart.medianKey": "Median per upstream", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index 46c27ac1..40d2fb82 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -330,8 +330,10 @@ "dns.chart.cache": "缓存状态", "dns.chart.cacheNote": "条目:{n},容量上限:未上报", "dns.chart.cacheRate": "缓存命中率", + "dns.chart.capacity": "容量", "dns.chart.count": "{n} 条", "dns.chart.coverage": "缓存范围:{kinds};{persistent}", + "dns.chart.entries": "条目", "dns.chart.failureRate": "失败率", "dns.chart.median": "中位数", "dns.chart.medianKey": "各上游的中位数", diff --git a/src/i18n/locales/zh-TW.json b/src/i18n/locales/zh-TW.json index b328ea55..05aa7f3d 100644 --- a/src/i18n/locales/zh-TW.json +++ b/src/i18n/locales/zh-TW.json @@ -330,8 +330,10 @@ "dns.chart.cache": "快取狀態", "dns.chart.cacheNote": "條目:{n},容量上限:未回報", "dns.chart.cacheRate": "快取命中率", + "dns.chart.capacity": "容量", "dns.chart.count": "{n} 筆", "dns.chart.coverage": "快取範圍:{kinds};{persistent}", + "dns.chart.entries": "條目", "dns.chart.failureRate": "失敗率", "dns.chart.median": "中位數", "dns.chart.medianKey": "各上游的中位數",