Files
fotospiel-app/resources/js/admin/mobile/lib/packageSummary.test.ts
Codex Agent 6fe363640f
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Reapply photobooth uploader changes after sync
2026-01-12 17:10:47 +01:00

69 lines
2.2 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}}'))
.replace('{{count}}', String(options?.count ?? '{{count}}'));
};
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('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', () => {
const result = formatEventUsage(3, 10, t);
expect(result).toBe('3 of 10 events created');
});
});