@@ -10,18 +10,21 @@ vi.mock("@/stores/historyItemsStore", () => ({
1010 useHistoryItemsStore : ( ) => ( { getHistoryItems : ( ) => [ ] } ) ,
1111} ) ) ;
1212
13- function mountInput ( props : Record < string , unknown > = { } ) {
13+ function mountInput (
14+ props : Record < string , unknown > = { } ,
15+ stubs : Record < string , boolean > = {
16+ FontAwesomeIcon : true ,
17+ LoadingSpan : true ,
18+ MentionDropdown : true ,
19+ } ,
20+ ) {
1421 return mount ( ChatInput as any , {
1522 propsData : {
1623 value : "" ,
1724 busy : false ,
1825 ...props ,
1926 } ,
20- stubs : {
21- FontAwesomeIcon : true ,
22- LoadingSpan : true ,
23- MentionDropdown : true ,
24- } ,
27+ stubs,
2528 } ) ;
2629}
2730
@@ -114,6 +117,36 @@ describe("ChatInput", () => {
114117 await wrapper . find ( "textarea" ) . trigger ( "keydown.enter" , { shiftKey : true } ) ;
115118 expect ( wrapper . emitted ( "submit" ) ) . toBeFalsy ( ) ;
116119 } ) ;
120+
121+ it ( "emits submit on Enter when the mention dropdown has no matches" , async ( ) => {
122+ const value = "@dataset:nope" ;
123+ const wrapper = mountInput ( { value } , { FontAwesomeIcon : true , LoadingSpan : true } ) ;
124+ const textarea = wrapper . find ( "textarea" ) ;
125+ const el = textarea . element as HTMLTextAreaElement ;
126+ el . selectionStart = value . length ;
127+ el . selectionEnd = value . length ;
128+
129+ await textarea . trigger ( "input" ) ;
130+ await textarea . trigger ( "keydown.enter" ) ;
131+
132+ expect ( wrapper . emitted ( "submit" ) ) . toBeTruthy ( ) ;
133+ } ) ;
134+
135+ it ( "closes an empty mention dropdown on Escape" , async ( ) => {
136+ const value = "@dataset:nope" ;
137+ const wrapper = mountInput ( { value } , { FontAwesomeIcon : true , LoadingSpan : true } ) ;
138+ const textarea = wrapper . find ( "textarea" ) ;
139+ const el = textarea . element as HTMLTextAreaElement ;
140+ el . selectionStart = value . length ;
141+ el . selectionEnd = value . length ;
142+
143+ await textarea . trigger ( "input" ) ;
144+ expect ( wrapper . find ( ".mention-dropdown" ) . attributes ( "style" ) ?? "" ) . not . toContain ( "display: none" ) ;
145+
146+ await textarea . trigger ( "keydown" , { key : "Escape" } ) ;
147+
148+ expect ( wrapper . find ( ".mention-dropdown" ) . attributes ( "style" ) ?? "" ) . toContain ( "display: none" ) ;
149+ } ) ;
117150 } ) ;
118151
119152 describe ( "busy state UI" , ( ) => {
0 commit comments