import { describe, expect, it, vi } from 'vitest';
import { render } from 'svelte/server';
import SettingsEditor from '../../src/lib/ui/components/SettingsEditor.svelte';
import { defaultFleetSettings } from '../../src/lib/fleet-settings.js';
vi.mock('$app/navigation', () => ({ beforeNavigate: vi.fn(), goto: vi.fn() }));
const html = (initial = defaultFleetSettings) =>
render(SettingsEditor, { props: { initial } }).body.replaceAll(//g, '');
describe('grouped Settings editor', () => {
it('shows one section with meaningful defaults, and keeps every category reachable from the rail and mobile selector', () => {
const body = html();
expect(body).toContain('aria-label="Settings sections"');
expect(body).toContain('aria-label="Settings section"');
expect(body).toContain('href="#settings-group-matches-players"');
expect(body).toContain('href="#settings-group-files-versions"');
expect(body).toContain('id="setting-restartConcurrency"');
expect(body).not.toContain('id="setting-matchKeepDays"');
expect(body).toContain('1 operation');
expect(body).toContain('No limit');
expect(body).not.toMatch(/]*value="0"/);
});
it('compares with the saved baseline rather than factory defaults and disables Save and Discard when unchanged', () => {
const body = html({ ...defaultFleetSettings, preparationConcurrency: 7 });
expect(body).toContain('All changes saved');
expect(body).not.toContain('unsaved changes');
expect(body).not.toContain('class="changed-marker"');
expect(body).toMatch(/]*id="setting-preparationConcurrency"[^>]*value="7"/);
expect(body).toMatch(/