feat(Pairing): add comboKey natural-key derivation
This commit is contained in:
@@ -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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user