diff --git a/src/entities/Pairing/domain/comboKey/comboKey.test.ts b/src/entities/Pairing/domain/comboKey/comboKey.test.ts new file mode 100644 index 0000000..5924bd4 --- /dev/null +++ b/src/entities/Pairing/domain/comboKey/comboKey.test.ts @@ -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'); + }); +}); diff --git a/src/entities/Pairing/domain/comboKey/comboKey.ts b/src/entities/Pairing/domain/comboKey/comboKey.ts new file mode 100644 index 0000000..1cf0c46 --- /dev/null +++ b/src/entities/Pairing/domain/comboKey/comboKey.ts @@ -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}`; +}