Addon-Kauf im Event admin korrigiert.
This commit is contained in:
50
resources/js/admin/lib/__tests__/limitWarnings.test.ts
Normal file
50
resources/js/admin/lib/__tests__/limitWarnings.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildLimitWarnings } from '../limitWarnings';
|
||||
|
||||
describe('buildLimitWarnings', () => {
|
||||
it('renders gallery warning in hours when less than two days remain', () => {
|
||||
const warnings = buildLimitWarnings(
|
||||
{
|
||||
photos: null,
|
||||
guests: null,
|
||||
gallery: {
|
||||
state: 'warning',
|
||||
expires_at: null,
|
||||
days_remaining: 1.2,
|
||||
warning_thresholds: [],
|
||||
warning_triggered: null,
|
||||
warning_sent_at: null,
|
||||
expired_notified_at: null,
|
||||
},
|
||||
can_upload_photos: true,
|
||||
can_add_guests: true,
|
||||
},
|
||||
(key, options) => (key === 'galleryWarningHours' ? `hours:${options?.hours}` : key),
|
||||
);
|
||||
|
||||
expect(warnings[0]?.message).toBe('hours:29');
|
||||
});
|
||||
|
||||
it('renders gallery warning in days when two or more days remain', () => {
|
||||
const warnings = buildLimitWarnings(
|
||||
{
|
||||
photos: null,
|
||||
guests: null,
|
||||
gallery: {
|
||||
state: 'warning',
|
||||
expires_at: null,
|
||||
days_remaining: 2.1,
|
||||
warning_thresholds: [],
|
||||
warning_triggered: null,
|
||||
warning_sent_at: null,
|
||||
expired_notified_at: null,
|
||||
},
|
||||
can_upload_photos: true,
|
||||
can_add_guests: true,
|
||||
},
|
||||
(key, options) => (key === 'galleryWarningDays' ? `days:${options?.days}` : key),
|
||||
);
|
||||
|
||||
expect(warnings[0]?.message).toBe('days:3');
|
||||
});
|
||||
});
|
||||
@@ -104,12 +104,21 @@ export function buildLimitWarnings(limits: EventLimitSummary, t: TranslateFn): L
|
||||
} else if (limits.gallery.state === 'warning') {
|
||||
const days = limits.gallery.days_remaining ?? 0;
|
||||
const safeDays = Math.max(0, days);
|
||||
const key = safeDays === 1 ? 'galleryWarningDay' : 'galleryWarningDays';
|
||||
const useHours = safeDays > 0 && safeDays < 2;
|
||||
const roundedDays = Math.max(1, Math.ceil(safeDays));
|
||||
const roundedHours = Math.max(1, Math.ceil(safeDays * 24));
|
||||
const key = useHours
|
||||
? roundedHours === 1
|
||||
? 'galleryWarningHour'
|
||||
: 'galleryWarningHours'
|
||||
: roundedDays === 1
|
||||
? 'galleryWarningDay'
|
||||
: 'galleryWarningDays';
|
||||
warnings.push({
|
||||
id: 'gallery-warning',
|
||||
scope: 'gallery',
|
||||
tone: 'warning',
|
||||
message: t(key, { days: safeDays }),
|
||||
message: t(key, useHours ? { hours: roundedHours } : { days: roundedDays }),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user