mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-23 22:25:05 +00:00
Three places in the codebase JSON.stringify arrays to build opaque composite Map/Set keys (favoritedWidgetsStore, SubgraphNode promotion view keys, promoted-widget storeName). Extract a shared helper. Reverts storeName from NUL-delimited back to JSON.stringify(array) for consistency with the established codebase pattern. Still computed once in the constructor. Amp-Thread-ID: https://ampcode.com/threads/T-019de73b-91ac-76c8-8b10-99552857d285 Co-authored-by: Amp <amp@ampcode.com>
26 lines
845 B
TypeScript
26 lines
845 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { makeCompositeKey } from './compositeKey'
|
|
|
|
describe('makeCompositeKey', () => {
|
|
it('produces a stable string for a tuple of values', () => {
|
|
expect(makeCompositeKey(['a', 'b', 'c'])).toBe('["a","b","c"]')
|
|
})
|
|
|
|
it('distinguishes tuples whose joined parts collide', () => {
|
|
// Without an injective encoding, ['ab', 'c'] and ['a', 'bc'] could collide.
|
|
expect(makeCompositeKey(['ab', 'c'])).not.toBe(
|
|
makeCompositeKey(['a', 'bc'])
|
|
)
|
|
})
|
|
|
|
it('handles empty parts and undefined slots', () => {
|
|
expect(makeCompositeKey(['x', '', 'y'])).toBe('["x","","y"]')
|
|
expect(makeCompositeKey(['x', undefined, 'y'])).toBe('["x",null,"y"]')
|
|
})
|
|
|
|
it('preserves part order', () => {
|
|
expect(makeCompositeKey(['1', '2'])).not.toBe(makeCompositeKey(['2', '1']))
|
|
})
|
|
})
|