import { describe, expect, it } from 'vitest';

import { normalizeTableTreeData } from '../helpers/tableTree';

describe('normalizeTableTreeData', () => {
  it('removes empty children from leaf nodes at every level', () => {
    const source = [
      {
        children: [{ children: [], id: 'child' }],
        id: 'parent',
      },
      { children: [], id: 'leaf' },
    ];

    expect(normalizeTableTreeData(source)).toEqual([
      {
        children: [{ id: 'child' }],
        id: 'parent',
      },
      { id: 'leaf' },
    ]);
    expect(source[0]?.children?.[0]).toHaveProperty('children', []);
  });
});
