// REQ-USR-001: PermissionTabs 权限页签条单测（权限组 active + 5 占位页签 disabled，D9）
import { describe, it, expect } from 'vitest';
import { screen } from '@testing-library/react';
import { renderShell } from './renderShell';
import PermissionTabs from '../../src/pages/usr/UserDetail/PermissionTabs';
import { PLACEHOLDER_TABS } from '../../src/pages/usr/UserDetail/constants';

function setup() {
  renderShell(
    <PermissionTabs>
      <div data-testid="perm-children">权限列表内容</div>
    </PermissionTabs>,
    { preloadedAuth: { token: 't', user: { id: 1, sUserName: 'a', sUserType: 'x', sLanguage: '中文' } } },
  );
}

describe('PermissionTabs', () => {
  it('renders 权限组 active with children', () => {
    setup();
    const groupTab = screen.getByRole('tab', { name: '权限组' });
    expect(groupTab).toBeInTheDocument();
    expect(groupTab.getAttribute('aria-selected')).toBe('true');
    expect(screen.getByTestId('perm-children')).toBeInTheDocument();
  });

  it('renders 5 placeholder tabs disabled', () => {
    setup();
    for (const name of PLACEHOLDER_TABS) {
      const tab = screen.getByRole('tab', { name });
      expect(tab).toBeInTheDocument();
      expect(tab.getAttribute('aria-disabled')).toBe('true');
    }
  });

  it('placeholder tabs do not render permission list content', () => {
    setup();
    // 占位页签 disabled 无法切换，权限列表内容只在权限组面板内渲染（只 1 处）
    expect(screen.getAllByTestId('perm-children')).toHaveLength(1);
  });
});
