Files
immich-folio/lib/__tests__/config.test.ts
Ralksta 84c7eeef40 experimental: portfolio features (justified layout, unlisted pages, captions, per-album grid, focal point, nav links, cover hero) (#431)
## Was ist das?

Sieben neue Portfolio-Features, alle als **experimental** gekennzeichnet
— in YAML-Kommentaren, Admin-Panel-Labels und Commit-Scopes, damit sie
einzeln nachvollziehbar und revertierbar bleiben.

## Features (je ein Commit)

| Commit | Feature |
| --- | --- |
| `justified rows gallery layout` | Neues Grid-Layout `justified`:
zeilenbasiert, gleiche Höhen, volle Breite — Flexbox ohne JS-Messung,
letzte Zeile bleibt natürlich klein |
| `hide subpages from navigation` | `hidden: true`: Seite aus
Nav/Homepage raus, per Direktlink erreichbar — im Gegensatz zu `enabled:
false` (404) |
| `lightbox captions` | Immich-Asset-Description als Bildunterschrift im
Info-Panel; EXIF-Route liefert bei `exifOnHover: false` jetzt nur noch
die Caption statt 403 |
| `per-album grid overrides` | `grid:` pro Album-Eintrag, Präzedenz
global < Subpage < Album |
| `per-album cover focal point` | `coverPosition:` → `object-position`
auf Cover-Karten, strikt validiert |
| `external links in header navigation` | `navLinks:` in settings.yaml,
nur http(s), sanitisiert |
| `cover splash hero style` | `heroStyle: cover`: Fullscreen-Splash mit
Enter-Link ins Portfolio |

Alle Optionen sind im Admin-Panel editierbar (PageBuilder /
SettingsEditor).

## Tests

- 356 Unit-Tests grün (13 neue: deriveGallery hidden/grid/coverPosition,
sanitizeNavLinks, EXIF-Route-Captions, justified-Layout-Validierung)
- `npx tsc --noEmit`: 0 Fehler
- `npm run build`: sauber
- Justified-Zeilenmathematik und Cover-Splash per Browser-Harness
visuell/numerisch verifiziert (volle Zeilen enden exakt an der
Containerkante, letzte Zeile bleibt natürlich)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: ralksta <ralksta@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: lancetm714 <108419425+lancetm714@users.noreply.github.com>
2026-08-14 17:56:22 +02:00

138 lines
4.1 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
// Mock env.ts so importing config.ts doesn't trigger Zod validation
vi.mock('@/lib/env', () => ({
env: {
IMMICH_API_URL: 'http://localhost:2283',
IMMICH_API_KEY: 'test-key',
SITE_TITLE: 'Test Gallery',
SITE_SUBTITLE: '',
CACHE_TTL: 300,
RATE_LIMIT_RPM: 120,
},
}));
import { slugify, buildSubpageGrid, sanitizeNavLinks } from '@/lib/config';
// EXPERIMENTAL: external navigation links — rendered as <a href> in the
// header, so only http(s) URLs may survive sanitisation.
describe('sanitizeNavLinks', () => {
it('keeps well-formed http(s) links', () => {
expect(
sanitizeNavLinks([
{ label: 'Shop', url: 'https://shop.example.com' },
{ label: 'Blog', url: 'http://blog.example.com/a?b=c' },
]),
).toEqual([
{ label: 'Shop', url: 'https://shop.example.com' },
{ label: 'Blog', url: 'http://blog.example.com/a?b=c' },
]);
});
it('drops non-http schemes and entries without label or url', () => {
expect(
sanitizeNavLinks([
{ label: 'Bad', url: 'javascript:alert(1)' },
{ label: 'AlsoBad', url: 'data:text/html,x' },
{ label: '', url: 'https://x.example' },
{ label: 'NoUrl', url: '' },
]),
).toEqual([]);
});
it('returns empty for undefined input', () => {
expect(sanitizeNavLinks(undefined)).toEqual([]);
});
});
describe('slugify', () => {
it('converts a simple name to lowercase with hyphens', () => {
expect(slugify('Kloster Chorin')).toBe('kloster-chorin');
});
it('strips diacritics', () => {
expect(slugify('Schöne Aussicht')).toBe('schone-aussicht');
expect(slugify('Café Müller')).toBe('cafe-muller');
});
it('replaces special characters with hyphens', () => {
expect(slugify('Hello, World!')).toBe('hello-world');
expect(slugify('foo & bar (baz)')).toBe('foo-bar-baz');
});
it('trims leading and trailing hyphens', () => {
expect(slugify('--leading')).toBe('leading');
expect(slugify('trailing---')).toBe('trailing');
expect(slugify('---both---')).toBe('both');
});
it('collapses consecutive hyphens', () => {
expect(slugify('a b c')).toBe('a-b-c');
});
it('handles an empty string', () => {
expect(slugify('')).toBe('');
});
it('handles all-special-character input', () => {
expect(slugify('!@#$%')).toBe('');
});
it('preserves numbers', () => {
expect(slugify('Album 2024')).toBe('album-2024');
});
});
describe('buildSubpageGrid', () => {
it('returns empty object when called without arguments', () => {
expect(buildSubpageGrid()).toEqual({});
});
it('returns empty object when called with undefined', () => {
expect(buildSubpageGrid(undefined)).toEqual({});
});
it('maps columns and gap correctly', () => {
expect(buildSubpageGrid({ columns: 4, gap: 8 })).toEqual({
grid: { columns: 4, gap: 8 },
});
});
it('maps aspectRatio correctly', () => {
expect(buildSubpageGrid({ aspectRatio: '16/9' })).toEqual({
grid: { aspectRatio: '16/9' },
});
});
it('preserves a valid layout value', () => {
expect(buildSubpageGrid({ layout: 'uniform' })).toEqual({
grid: { layout: 'uniform' },
});
});
it('preserves the experimental justified layout', () => {
expect(buildSubpageGrid({ layout: 'justified' })).toEqual({
grid: { layout: 'justified' },
});
});
it('falls back to masonry for an unknown layout', () => {
expect(buildSubpageGrid({ layout: 'unknown-layout' })).toEqual({
grid: { layout: 'masonry' },
});
});
it('omits fields that are not supplied', () => {
const result = buildSubpageGrid({ columns: 2 });
expect(result).toEqual({ grid: { columns: 2 } });
expect((result as { grid: object }).grid).not.toHaveProperty('gap');
expect((result as { grid: object }).grid).not.toHaveProperty('layout');
});
it('handles all fields together', () => {
expect(buildSubpageGrid({ columns: 3, gap: 16, aspectRatio: '1', layout: 'masonry' })).toEqual({
grid: { columns: 3, gap: 16, aspectRatio: '1', layout: 'masonry' },
});
});
});