import { describe, expect, it } from 'vitest'; import { FormComponentType, getDisplayOnlyFieldNames } from './form.js'; import type { FormTemplate } from './form.js'; describe('getDisplayOnlyFieldNames', () => { it('returns ALERT field names', () => { const template: FormTemplate = { sections: [ { name: 'auth', items: [ { name: 'HTTPBasicAlert', label: '', startVersion: '1', componentType: FormComponentType.ALERT, messageTemplate: 'some info' } ] } ] }; expect(getDisplayOnlyFieldNames(template)).toEqual(new Set(['HTTPBasicAlert'])); }); it('returns BUTTON field names', () => { const template: FormTemplate = { sections: [ { name: 'authButtons', items: [ { rowItems: [ { name: 'oauth-connect-button', label: 'Connect', startVersion: '1', componentType: FormComponentType.BUTTON, buttonType: 'connectOAuth' }, { name: 'oauth-revoke-shared-tokens-button', label: 'Revoke', startVersion: '1', componentType: FormComponentType.BUTTON, buttonType: 'revokeOAuthTokens' } ] } ] } ] }; expect(getDisplayOnlyFieldNames(template)).toEqual(new Set(['oauth-connect-button', 'oauth-revoke-shared-tokens-button'])); }); it('returns disabled + immutable INPUT_TEXT field names', () => { const template: FormTemplate = { sections: [ { name: 'auth', items: [ { name: 'oauth-callback-alert', label: 'Callback URL', startVersion: '1', componentType: FormComponentType.INPUT_TEXT, disabled: true, immutable: true, initialValue: 'https://example.com/oauth/callback' } ] } ] }; expect(getDisplayOnlyFieldNames(template)).toEqual(new Set(['oauth-callback-alert'])); }); it('does not include regular INPUT_TEXT fields', () => { const template: FormTemplate = { sections: [ { name: 'main', items: [ { name: 'path', label: 'URL', startVersion: '1', componentType: FormComponentType.INPUT_TEXT } ] } ] }; expect(getDisplayOnlyFieldNames(template).size).toBe(0); }); it('does not include disabled-only fields without immutable', () => { const template: FormTemplate = { sections: [ { name: 'main', items: [ { name: 'path', label: 'URL', startVersion: '1', componentType: FormComponentType.INPUT_TEXT, disabled: true } ] } ] }; expect(getDisplayOnlyFieldNames(template).size).toBe(0); }); it('handles mixed sections with normal and display-only fields', () => { const template: FormTemplate = { sections: [ { name: 'main', items: [ { name: 'path', label: 'URL', startVersion: '1', componentType: FormComponentType.INPUT_TEXT }, { name: 'OAuth2PasswordAlert', label: '', startVersion: '1', componentType: FormComponentType.ALERT } ] }, { name: 'authButtons', items: [ { rowItems: [ { name: 'oauth-connect-button', label: 'Connect', startVersion: '1', componentType: FormComponentType.BUTTON, buttonType: 'connectOAuth' } ] } ] } ] }; const result = getDisplayOnlyFieldNames(template); expect(result).toEqual(new Set(['OAuth2PasswordAlert', 'oauth-connect-button'])); expect(result.has('path')).toBe(false); }); });