feat(Pairing): add comboKey natural-key derivation

This commit is contained in:
Ilia Mashkov
2026-06-24 13:21:29 +03:00
parent d37d01e6d8
commit f680fe01ea
2 changed files with 33 additions and 0 deletions
@@ -0,0 +1,20 @@
import {
describe,
expect,
it,
} from 'vitest';
import { comboKey } from './comboKey';
describe('comboKey', () => {
it('derives a key from the two font ids', () => {
expect(comboKey({ id: 'x', headerFontId: 'Inter', bodyFontId: 'Lora' })).toBe('Inter|Lora');
});
it('ignores the surrogate id (content not identity)', () => {
const a = comboKey({ id: 'a', headerFontId: 'Inter', bodyFontId: 'Lora' });
const b = comboKey({ id: 'b', headerFontId: 'Inter', bodyFontId: 'Lora' });
expect(a).toBe(b);
});
it('is order-sensitive on role', () => {
expect(comboKey({ id: 'x', headerFontId: 'Lora', bodyFontId: 'Inter' })).toBe('Lora|Inter');
});
});
@@ -0,0 +1,13 @@
import type { Pairing } from '../types';
/**
* Natural key describing a Pairing's current fonts (not its identity).
* Used for URL share-encoding and "is this combo already on the board" checks.
* Recomputed on swap; two cards may share a comboKey but never an id.
*
* @param pairing - The pairing whose fonts form the key (its `id` is ignored).
* @returns The `headerFontId|bodyFontId` key.
*/
export function comboKey(pairing: Pairing): string {
return `${pairing.headerFontId}|${pairing.bodyFontId}`;
}