import { HydrationMap, mergeMaps, mergeManyMaps, mergeNestedMaps, } from '../../src/hydration/util' const mapToObj = (map: HydrationMap) => { const obj: Record = {} for (const [key, value] of map) { obj[key] = value } return obj } describe('hydration util', () => { it(`mergeMaps: merges two maps`, () => { const compare = new HydrationMap() compare.set('a', 'a') compare.set('b', 'b') const a = new HydrationMap().set('a', 'a') const b = new HydrationMap().set('b', 'b') const merged = mergeMaps(a, b) expect(mapToObj(merged!)).toEqual(mapToObj(compare)) }) it(`mergeManyMaps: merges three maps`, () => { const compare = new HydrationMap() compare.set('a', 'a') compare.set('b', 'b') compare.set('c', 'c') const a = new HydrationMap().set('a', 'a') const b = new HydrationMap().set('b', 'b') const c = new HydrationMap().set('c', 'c') const merged = mergeManyMaps(a, b, c) expect(mapToObj(merged!)).toEqual(mapToObj(compare)) }) it(`mergeNestedMaps: merges two nested maps`, () => { const compare = new HydrationMap>() const compareA = new HydrationMap().set('a', 'a') const compareB = new HydrationMap().set('b', 'b') compare.set('a', compareA) compare.set('b', compareB) const a = new HydrationMap>().set( 'a', new HydrationMap().set('a', 'a'), ) const b = new HydrationMap>().set( 'b', new HydrationMap().set('b', 'b'), ) const merged = mergeNestedMaps(a, b) expect(mapToObj(merged!)).toEqual(mapToObj(compare)) }) it(`mergeNestedMaps: merges two nested maps with common keys`, () => { const compare = new HydrationMap>() const compareA = new HydrationMap() compareA.set('b', true) compareA.set('c', true) compare.set('a', compareA) const a = new HydrationMap>().set( 'a', new HydrationMap().set('b', true), ) const b = new HydrationMap>().set( 'a', new HydrationMap().set('c', true), ) const merged = mergeNestedMaps(a, b) expect(mapToObj(merged!)).toEqual(mapToObj(compare)) }) })