/** @vitest-environment jsdom */ import { cleanup, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { afterEach, describe, expect, it } from 'vitest'; import type { AdminExtensionSettingField } from '@/api/admin/extensions/queries'; import SettingsSections, { groupSettingsBySection } from './SettingsSections'; afterEach(cleanup); const field = (input: string, tab: string | null): AdminExtensionSettingField => ({ input, label: input, help: null, tab, field: 'text', options: [], value: null, constraints: { max_length: null, max_items: null, max_kilobytes: null, accept: [] }, visibility: 'admin', }); const names = (schema: AdminExtensionSettingField[]) => groupSettingsBySection(schema).map((section) => [section.name, section.fields.map((field) => field.input)]); const renderField = (setting: AdminExtensionSettingField) =>
{setting.input}
; describe('groupSettingsBySection', () => { it('keeps a schema without tabs as one section', () => { expect(names([field('a', null), field('b', null)])).toEqual([['General', ['a', 'b']]]); }); it('orders sections by their first field and puts untabbed fields under General first', () => { expect( names([ field('bucket', 'Storage'), field('enabled', null), field('webhook', 'Notifications'), field('access_key', 'Storage'), ]) ).toEqual([ ['General', ['enabled']], ['Storage', ['bucket', 'access_key']], ['Notifications', ['webhook']], ]); }); it('omits General when every field names a tab', () => { expect(names([field('bucket', 'Storage'), field('webhook', 'Notifications')]).map(([name]) => name)).toEqual([ 'Storage', 'Notifications', ]); }); }); describe('SettingsSections', () => { it('renders fields in the scroll area without a section picker when no field names a tab', () => { render(