Files
fotospiel-app/resources/js/admin/mobile/lib/packageSummary.test.ts
Codex Agent e69c94ad20
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
bd sync: 2026-01-12 17:07:55
2026-01-12 17:07:55 +01:00

62 lines
2.0 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
collectPackageFeatures,
formatEventUsage,
formatPackageLimit,
getPackageFeatureLabel,
getPackageLimitEntries,
} from './packageSummary';
const t = (key: string, options?: Record<string, unknown> | string) => {
if (typeof options === 'string') {
return options;
}
const template = (options?.defaultValue as string | undefined) ?? key;
return template
.replace('{{used}}', String(options?.used ?? '{{used}}'))
.replace('{{limit}}', String(options?.limit ?? '{{limit}}'))
.replace('{{remaining}}', String(options?.remaining ?? '{{remaining}}'));
};
describe('packageSummary helpers', () => {
it('returns translated labels for known features', () => {
expect(getPackageFeatureLabel('priority_support', t)).toBe('Priority support');
});
it('falls back to raw feature key for unknown features', () => {
expect(getPackageFeatureLabel('custom_feature', t)).toBe('custom_feature');
});
it('formats unlimited package limits', () => {
expect(formatPackageLimit(null, t)).toBe('Unlimited');
});
it('formats numeric package limits', () => {
expect(formatPackageLimit(12, t)).toBe('12');
});
it('collects features from package and limit payloads', () => {
const result = collectPackageFeatures({
features: ['custom_branding'],
package_limits: { features: ['reseller_dashboard'] },
branding_allowed: true,
watermark_allowed: false,
} as any);
expect(result).toEqual(expect.arrayContaining(['custom_branding', 'reseller_dashboard', 'branding_allowed']));
});
it('returns labeled limit entries', () => {
const result = getPackageLimitEntries({ max_photos: 120, remaining_photos: 30 }, t);
expect(result[0].label).toBe('Photos');
expect(result[0].value).toBe('30 of 120 remaining');
});
it('formats event usage copy', () => {
const result = formatEventUsage(3, 10, t);
expect(result).toBe('3 of 10 events created');
});
});