import {
  describe,
  it,
  expect
} from 'vitest';
import { aggregateComponentCountsByDomain, detectSuspectedComponentLeaks } from './component-tree.rules';

describe('aggregateComponentCountsByDomain', () => {
  it('groups component counts under inferred domains', () => {
    expect(aggregateComponentCountsByDomain({
      VoiceChannelPanelComponent: 2,
      DmChatComponent: 1,
      App: 1
    })).toEqual({
      'voice-connection': 2,
      'direct-message': 1,
      core: 1
    });
  });
});

describe('detectSuspectedComponentLeaks', () => {
  it('flags components that exceed the expected live count', () => {
    expect(detectSuspectedComponentLeaks({
      DmChatComponent: 3,
      App: 1
    }, {
      DmChatComponent: 0,
      App: 1
    })).toEqual([
      {
        name: 'DmChatComponent',
        count: 3,
        expected: 0
      }
    ]);
  });

  it('returns an empty list when counts are within expectations', () => {
    expect(detectSuspectedComponentLeaks({
      App: 1
    }, {
      App: 1
    })).toEqual([]);
  });
});
