@@ -6421,3 +6421,84 @@ describe('test-utils wrapper', () => {
64216421 } ) . toThrow ( 'Option with value "nonexistent" not found in menu' ) ;
64226422 } ) ;
64236423} ) ;
6424+
6425+ describe ( 'i18n token aria label format callbacks' , ( ) => {
6426+ test ( 'tokenInsertedAriaLabel is called with token label after menu selection' , ( ) => {
6427+ const tokenInsertedAriaLabel = jest . fn ( ( token : { label ?: string ; value : string } ) => `${ token . label } added` ) ;
6428+ const ref = React . createRef < PromptInputProps . Ref > ( ) ;
6429+ const { wrapper } = renderStatefulTokenMode ( {
6430+ props : { tokens : [ ] , i18nStrings : { ...defaultI18nStrings , tokenInsertedAriaLabel } } ,
6431+ ref,
6432+ } ) ;
6433+ act ( ( ) => {
6434+ ref . current ! . focus ( ) ;
6435+ } ) ;
6436+ act ( ( ) => {
6437+ ref . current ! . insertText ( '@' , 0 , 1 ) ;
6438+ } ) ;
6439+ wrapper . selectMenuOptionByValue ( 'user-1' ) ;
6440+ expect ( tokenInsertedAriaLabel ) . toHaveBeenCalledWith ( expect . objectContaining ( { label : 'Alice' , value : 'user-1' } ) ) ;
6441+ } ) ;
6442+
6443+ test ( 'tokenPinnedAriaLabel is called when pinned reference is inserted' , ( ) => {
6444+ const tokenPinnedAriaLabel = jest . fn ( ( token : { label ?: string ; value : string } ) => `${ token . label } pinned` ) ;
6445+ const ref = React . createRef < PromptInputProps . Ref > ( ) ;
6446+ const menusWithUseAtStart : PromptInputProps . MenuDefinition [ ] = [
6447+ { id : 'commands' , trigger : '/' , options : commandOptions , filteringType : 'auto' , useAtStart : true } ,
6448+ ] ;
6449+ const { wrapper } = renderStatefulTokenMode ( {
6450+ props : { tokens : [ ] , menus : menusWithUseAtStart , i18nStrings : { ...defaultI18nStrings , tokenPinnedAriaLabel } } ,
6451+ ref,
6452+ } ) ;
6453+ act ( ( ) => {
6454+ ref . current ! . focus ( ) ;
6455+ } ) ;
6456+ act ( ( ) => {
6457+ ref . current ! . insertText ( '/' , 0 , 1 ) ;
6458+ } ) ;
6459+ expect ( wrapper . isMenuOpen ( ) ) . toBe ( true ) ;
6460+ wrapper . selectMenuOptionByValue ( 'dev' ) ;
6461+ expect ( tokenPinnedAriaLabel ) . toHaveBeenCalledWith (
6462+ expect . objectContaining ( { label : 'Developer Mode' , value : 'dev' } )
6463+ ) ;
6464+ } ) ;
6465+ } ) ;
6466+
6467+ describe ( 'onTriggerDetected callback' , ( ) => {
6468+ test ( 'onTriggerDetected is called when a trigger character is typed' , ( ) => {
6469+ const onTriggerDetected = jest . fn ( ) ;
6470+ const ref = React . createRef < PromptInputProps . Ref > ( ) ;
6471+ renderStatefulTokenMode ( {
6472+ props : { tokens : [ ] , onTriggerDetected } ,
6473+ ref,
6474+ } ) ;
6475+ act ( ( ) => {
6476+ ref . current ! . focus ( ) ;
6477+ } ) ;
6478+ act ( ( ) => {
6479+ ref . current ! . insertText ( '@' ) ;
6480+ } ) ;
6481+ expect ( onTriggerDetected ) . toHaveBeenCalledWith (
6482+ expect . objectContaining ( {
6483+ detail : expect . objectContaining ( { menuId : 'mentions' , triggerChar : '@' } ) ,
6484+ } )
6485+ ) ;
6486+ } ) ;
6487+
6488+ test ( 'onTriggerDetected can cancel trigger creation via preventDefault' , ( ) => {
6489+ const onTriggerDetected = jest . fn ( event => event . preventDefault ( ) ) ;
6490+ const ref = React . createRef < PromptInputProps . Ref > ( ) ;
6491+ const { wrapper } = renderStatefulTokenMode ( {
6492+ props : { tokens : [ ] , onTriggerDetected } ,
6493+ ref,
6494+ } ) ;
6495+ act ( ( ) => {
6496+ ref . current ! . focus ( ) ;
6497+ } ) ;
6498+ act ( ( ) => {
6499+ ref . current ! . insertText ( '@' ) ;
6500+ } ) ;
6501+ expect ( onTriggerDetected ) . toHaveBeenCalled ( ) ;
6502+ expect ( wrapper . isMenuOpen ( ) ) . toBe ( false ) ;
6503+ } ) ;
6504+ } ) ;
0 commit comments