@@ -30,6 +30,7 @@ import { describe, it, expect, vi } from 'vitest';
3030import { render , screen , fireEvent , waitFor } from '@testing-library/react' ;
3131import type { ActionParamDef } from '@object-ui/core' ;
3232import { validateActionParams } from '@objectstack/spec/ui' ;
33+ import { SchemaRendererProvider } from '@object-ui/react' ;
3334import { ActionParamDialog , filterVisibleParams , serializeParamValues } from './ActionParamDialog' ;
3435import { expectedParamShape , classifyValueShape } from '../utils/paramValueShape' ;
3536
@@ -815,3 +816,68 @@ describe('serializeParamValues', () => {
815816 } ) ;
816817 } ) ;
817818} ) ;
819+
820+ describe ( 'ActionParamDialog — a param `widget` draws the named widget (#30260)' , ( ) => {
821+ // The Create User shape once its `permissionSet` param declares the picker
822+ // (`ActionParamSchema.widget`, ADR-0131 D4): a `text` param whose value is a
823+ // permission-set NAME. The registry pickers read their catalog through the
824+ // data source of `SchemaRendererContext`, so the dialog is mounted inside the
825+ // provider, as the console mounts it.
826+ function openWithCatalog ( params : ActionParamDef [ ] ) {
827+ const resolve = vi . fn ( ) ;
828+ const ds = {
829+ listMetadataItems : vi . fn ( async ( _type : string ) => [
830+ { name : 'sales_user' , label : 'Sales User' } ,
831+ { name : 'support_agent' , label : 'Support Agent' } ,
832+ ] ) ,
833+ } ;
834+ const view = render (
835+ < SchemaRendererProvider dataSource = { ds as any } >
836+ < ActionParamDialog state = { { open : true , params, resolve } } onOpenChange = { ( ) => { } } />
837+ </ SchemaRendererProvider > ,
838+ ) ;
839+ return { resolve, ds, ...view } ;
840+ }
841+
842+ it ( 'draws the permission-set picker: labels listed, the machine name submitted' , async ( ) => {
843+ const param = def ( { name : 'permissionSet' , label : 'Permission set' , type : 'text' , widget : 'permission-ref' } ) ;
844+ const { resolve, ds } = openWithCatalog ( [ param ] ) ;
845+
846+ const trigger = await screen . findByRole ( 'combobox' ) ;
847+ await waitFor ( ( ) => expect ( ds . listMetadataItems ) . toHaveBeenCalledWith ( 'permission' ) ) ;
848+ fireEvent . click ( trigger ) ;
849+ fireEvent . click ( await screen . findByText ( 'Support Agent (support_agent)' ) ) ;
850+ await waitFor ( ( ) => expect ( trigger ) . toHaveTextContent ( 'Support Agent (support_agent)' ) ) ;
851+
852+ confirm ( ) ;
853+ await waitFor ( ( ) => expect ( resolve ) . toHaveBeenCalledWith ( { permissionSet : 'support_agent' } ) ) ;
854+ // The emitted value matches the declared shape contract for the widget.
855+ expect ( expectedParamShape ( param ) ) . toBe ( 'string' ) ;
856+ expect ( classifyValueShape ( resolve . mock . calls [ 0 ] [ 0 ] . permissionSet ) ) . toBe ( 'string' ) ;
857+ } ) ;
858+
859+ it ( 'CONTROL: the same param without a widget is a text box, and lists nothing' , async ( ) => {
860+ const { resolve, ds } = openWithCatalog ( [
861+ def ( { name : 'permissionSet' , label : 'Permission set' , type : 'text' } ) ,
862+ ] ) ;
863+ const input = await screen . findByLabelText ( 'Permission set' ) ;
864+ expect ( input . tagName ) . toBe ( 'INPUT' ) ;
865+ expect ( screen . queryByRole ( 'combobox' ) ) . toBeNull ( ) ;
866+ expect ( ds . listMetadataItems ) . not . toHaveBeenCalled ( ) ;
867+ fireEvent . change ( input , { target : { value : 'typed_name' } } ) ;
868+ confirm ( ) ;
869+ await waitFor ( ( ) => expect ( resolve ) . toHaveBeenCalledWith ( { permissionSet : 'typed_name' } ) ) ;
870+ } ) ;
871+
872+ it ( 'an unregistered widget name falls back to the `type` control' , async ( ) => {
873+ const { resolve, ds } = openWithCatalog ( [
874+ def ( { name : 'reason' , label : 'Reason' , type : 'textarea' , widget : 'no_such_widget' } ) ,
875+ ] ) ;
876+ const box = await screen . findByLabelText ( 'Reason' ) ;
877+ expect ( box . tagName ) . toBe ( 'TEXTAREA' ) ;
878+ expect ( ds . listMetadataItems ) . not . toHaveBeenCalled ( ) ;
879+ fireEvent . change ( box , { target : { value : 'because' } } ) ;
880+ confirm ( ) ;
881+ await waitFor ( ( ) => expect ( resolve ) . toHaveBeenCalledWith ( { reason : 'because' } ) ) ;
882+ } ) ;
883+ } ) ;
0 commit comments