Clamp package summary remaining counts
This commit is contained in:
@@ -15,7 +15,8 @@ const t = (key: string, options?: Record<string, unknown> | string) => {
|
|||||||
return template
|
return template
|
||||||
.replace('{{used}}', String(options?.used ?? '{{used}}'))
|
.replace('{{used}}', String(options?.used ?? '{{used}}'))
|
||||||
.replace('{{limit}}', String(options?.limit ?? '{{limit}}'))
|
.replace('{{limit}}', String(options?.limit ?? '{{limit}}'))
|
||||||
.replace('{{remaining}}', String(options?.remaining ?? '{{remaining}}'));
|
.replace('{{remaining}}', String(options?.remaining ?? '{{remaining}}'))
|
||||||
|
.replace('{{count}}', String(options?.count ?? '{{count}}'));
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('packageSummary helpers', () => {
|
describe('packageSummary helpers', () => {
|
||||||
@@ -53,6 +54,12 @@ describe('packageSummary helpers', () => {
|
|||||||
expect(result[0].value).toBe('30 of 120 remaining');
|
expect(result[0].value).toBe('30 of 120 remaining');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('falls back to remaining count when remaining exceeds limit', () => {
|
||||||
|
const result = getPackageLimitEntries({ max_photos: 120, remaining_photos: 180 }, t);
|
||||||
|
|
||||||
|
expect(result[0].value).toBe('Remaining 180');
|
||||||
|
});
|
||||||
|
|
||||||
it('formats event usage copy', () => {
|
it('formats event usage copy', () => {
|
||||||
const result = formatEventUsage(3, 10, t);
|
const result = formatEventUsage(3, 10, t);
|
||||||
|
|
||||||
|
|||||||
@@ -138,6 +138,12 @@ const formatLimitWithRemaining = (limit: number | null, remaining: number | null
|
|||||||
|
|
||||||
if (remaining !== null && remaining >= 0) {
|
if (remaining !== null && remaining >= 0) {
|
||||||
const normalizedRemaining = Number.isFinite(remaining) ? Math.max(0, Math.round(remaining)) : remaining;
|
const normalizedRemaining = Number.isFinite(remaining) ? Math.max(0, Math.round(remaining)) : remaining;
|
||||||
|
if (normalizedRemaining > limit) {
|
||||||
|
return t('mobileBilling.usage.remaining', {
|
||||||
|
count: normalizedRemaining,
|
||||||
|
defaultValue: 'Remaining {{count}}',
|
||||||
|
});
|
||||||
|
}
|
||||||
return t('mobileBilling.usage.remainingOf', {
|
return t('mobileBilling.usage.remainingOf', {
|
||||||
remaining: normalizedRemaining,
|
remaining: normalizedRemaining,
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
Reference in New Issue
Block a user