// Copyright (c) 2025-2026, RTE (https://www.rte-france.com)
// This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0.
// If a copy of the Mozilla Public License, version 2.0 was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0
import { describe, expect, it } from 'vitest';
import { getIdMap, invalidateIdMapCache } from './idMap';
const makeContainer = (innerHtml: string): HTMLElement => {
const div = document.createElement('div');
div.innerHTML = innerHtml;
return div;
};
describe('getIdMap', () => {
it('collects every id-bearing descendant', () => {
const c = makeContainer(`
`);
const map = getIdMap(c);
expect(map.size).toBe(3);
expect(map.get('a')?.tagName).toBe('g');
expect(map.get('b')?.tagName).toBe('circle');
expect(map.get('c')?.tagName).toBe('text');
});
it('returns the same Map instance on repeated calls (cache hit)', () => {
const c = makeContainer('');
const a = getIdMap(c);
const b = getIdMap(c);
expect(a).toBe(b);
});
it('rebuilds the map when the inner