import { describe, it, expect } from 'vitest';
import { CONFIG_GROUPS, USER_SECTIONS } from './SettingsSidebar';

// Fix #4: Pets is a per-user personal preference, not a per-workspace setting.
// It must live under the "Preference" group and be reachable without admin
// (and in no-auth, where the group is shown because it is not adminOnly).
describe('Settings sidebar — Preference group', () => {
  const preference = CONFIG_GROUPS.find(g => g.label === 'Preference');

  it('has a Preference group', () => {
    expect(preference).toBeDefined();
  });

  it('the Preference group is not admin-only (visible to every user incl. no-auth)', () => {
    expect(preference && 'adminOnly' in preference ? preference.adminOnly : false).toBeFalsy();
  });

  it('Pets lives under the Preference group', () => {
    const ids = preference?.sections.map(s => s.id) ?? [];
    expect(ids).toContain('pets');
  });

  it('Pets is reachable by non-admin users (in USER_SECTIONS)', () => {
    expect(USER_SECTIONS).toContain('pets');
  });

  it('the Pets nav uses the conventional settings-nav-pets testid (id-derived)', () => {
    // SettingsSidebar renders data-testid={`settings-nav-${s.id}`}, so the
    // section id alone determines the testid.
    const pets = preference?.sections.find(s => s.id === 'pets');
    expect(pets).toBeDefined();
    expect(`settings-nav-${pets!.id}`).toBe('settings-nav-pets');
  });
});
