87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import type { EventPackageLimits } from '../../services/eventApi';
|
|
import { buildLimitSummaries } from '../limitSummaries';
|
|
|
|
const translations = new Map<string, string>([
|
|
['upload.limitSummary.cards.photos.title', 'Fotos'],
|
|
['upload.limitSummary.cards.photos.remaining', 'Noch {remaining} von {limit}'],
|
|
['upload.limitSummary.cards.photos.unlimited', 'Unbegrenzte Uploads'],
|
|
['upload.limitSummary.cards.guests.title', 'Gäste'],
|
|
['upload.limitSummary.cards.guests.remaining', '{remaining} Gäste frei (max. {limit})'],
|
|
['upload.limitSummary.cards.guests.unlimited', 'Unbegrenzte Gäste'],
|
|
['upload.limitSummary.badges.ok', 'OK'],
|
|
['upload.limitSummary.badges.warning', 'Warnung'],
|
|
['upload.limitSummary.badges.limit_reached', 'Limit erreicht'],
|
|
['upload.limitSummary.badges.unlimited', 'Unbegrenzt'],
|
|
]);
|
|
|
|
const t = (key: string) => translations.get(key) ?? key;
|
|
|
|
describe('buildLimitSummaries', () => {
|
|
it('builds photo summary with progress and warning tone', () => {
|
|
const limits: EventPackageLimits = {
|
|
photos: {
|
|
limit: 100,
|
|
used: 80,
|
|
remaining: 20,
|
|
percentage: 80,
|
|
state: 'warning',
|
|
threshold_reached: 80,
|
|
next_threshold: 95,
|
|
thresholds: [80, 95],
|
|
},
|
|
guests: null,
|
|
gallery: null,
|
|
can_upload_photos: true,
|
|
can_add_guests: true,
|
|
};
|
|
|
|
const cards = buildLimitSummaries(limits, t);
|
|
|
|
expect(cards).toHaveLength(1);
|
|
const card = cards[0];
|
|
expect(card.id).toBe('photos');
|
|
expect(card.tone).toBe('warning');
|
|
expect(card.progress).toBe(80);
|
|
expect(card.valueLabel).toBe('80 / 100');
|
|
expect(card.description).toBe('Noch 20 von 100');
|
|
expect(card.badgeLabel).toBe('Warnung');
|
|
});
|
|
|
|
it('builds unlimited guest summary without progress', () => {
|
|
const limits: EventPackageLimits = {
|
|
photos: null,
|
|
guests: {
|
|
limit: null,
|
|
used: 5,
|
|
remaining: null,
|
|
percentage: null,
|
|
state: 'unlimited',
|
|
threshold_reached: null,
|
|
next_threshold: null,
|
|
thresholds: [],
|
|
},
|
|
gallery: null,
|
|
can_upload_photos: true,
|
|
can_add_guests: true,
|
|
};
|
|
|
|
const cards = buildLimitSummaries(limits, t);
|
|
|
|
expect(cards).toHaveLength(1);
|
|
const card = cards[0];
|
|
expect(card.id).toBe('guests');
|
|
expect(card.progress).toBeNull();
|
|
expect(card.tone).toBe('neutral');
|
|
expect(card.valueLabel).toBe('Unbegrenzt');
|
|
expect(card.description).toBe('Unbegrenzte Gäste');
|
|
expect(card.badgeLabel).toBe('Unbegrenzt');
|
|
});
|
|
|
|
it('returns empty list when no limits are provided', () => {
|
|
expect(buildLimitSummaries(null, t)).toEqual([]);
|
|
expect(buildLimitSummaries(undefined, t)).toEqual([]);
|
|
});
|
|
});
|