import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it, vi } from 'vitest';
import { IdentityBatchToolbar, identityBatchActionCopy } from './IdentityBatchToolbar';
import { pruneSelectedIds, updateSelectedIds } from './IdentityManagementPanels';

describe('identity batch operations', () => {
  it('renders enable, disable and delete actions with the current selection count', () => {
    const html = renderToStaticMarkup(
      <IdentityBatchToolbar entityLabel="用户" loading={false} selectedCount={2} onAction={vi.fn()} />,
    );
    expect(html).toContain('已选');
    expect(html).toContain('批量启用');
    expect(html).toContain('批量禁用');
    expect(html).toContain('批量删除');
    expect(identityBatchActionCopy('delete', '用户组', 3).description).toContain('3 个用户组');
  });

  it('adds, removes and prunes selections after list updates', () => {
    const selected = updateSelectedIds(new Set(['a']), 'b', true);
    expect(Array.from(selected).sort()).toEqual(['a', 'b']);
    expect(Array.from(updateSelectedIds(selected, 'a', false))).toEqual(['b']);
    expect(Array.from(pruneSelectedIds(selected, ['b', 'c']))).toEqual(['b']);
  });
});
