Files
fotospiel-app/resources/js/admin/mobile/__tests__/qrLayoutUtils.test.ts
2025-12-12 08:34:19 +01:00

56 lines
1.9 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import type { EventQrInviteLayout } from '../../api';
import { buildInitialTextFields } from '../QrLayoutCustomizePage';
import { resolveLayoutForFormat } from '../QrPrintPage';
describe('buildInitialTextFields', () => {
it('prefers event name for headline and default copy when customization is missing', () => {
const layoutDefaults = {
id: 'evergreen-vows',
name: 'Evergreen Vows',
description: 'Old description',
} as EventQrInviteLayout;
const fields = buildInitialTextFields({
customization: null,
layoutDefaults,
eventName: 'Sommerfest 2025',
});
expect(fields.headline).toBe('Sommerfest 2025');
expect(fields.description).toBe('Helft uns, diesen besonderen Tag mit euren schönen Momenten festzuhalten.');
expect(fields.instructions).toHaveLength(3);
});
it('uses customization when provided', () => {
const fields = buildInitialTextFields({
customization: {
headline: 'Custom',
description: 'Desc',
instructions: ['One', 'Two'],
},
layoutDefaults: null,
eventName: 'Ignored',
});
expect(fields.headline).toBe('Custom');
expect(fields.description).toBe('Desc');
expect(fields.instructions).toEqual(['One', 'Two']);
});
});
describe('resolveLayoutForFormat', () => {
const layouts: EventQrInviteLayout[] = [
{ id: 'portrait-a4', paper: 'a4', orientation: 'portrait', panel_mode: 'single', format_hint: 'poster-a4' } as EventQrInviteLayout,
{ id: 'foldable', paper: 'a4', orientation: 'landscape', panel_mode: 'double-mirror', format_hint: 'foldable-a5' } as EventQrInviteLayout,
];
it('returns portrait layout for A4 poster', () => {
expect(resolveLayoutForFormat('a4-poster', layouts)).toBe('portrait-a4');
});
it('returns foldable layout for A5 foldable', () => {
expect(resolveLayoutForFormat('a5-foldable', layouts)).toBe('foldable');
});
});