@@ -161,7 +161,7 @@ describe('SuggestionMention', () => {
161161 ) ;
162162 } ) ;
163163
164- it ( 'preserves trailing punctuation dot when selected mention does not include dotted prefix' , async ( ) => {
164+ it ( 'preserves trailing punctuation dot and inserts trailing space when selected mention does not include dotted prefix' , async ( ) => {
165165 mockPersonalDetails = { } ;
166166 mockPersonalDetails [ 2 ] = {
167167 accountID : 2 ,
@@ -178,11 +178,11 @@ describe('SuggestionMention', () => {
178178
179179 act ( ( ) => onSelect ( 0 ) ) ;
180180
181- expect ( updateComment ) . toHaveBeenCalledWith ( '@adam@example.com.' , true ) ;
182- expect ( setSelection ) . toHaveBeenCalledWith ( { start : 18 , end : 18 } ) ;
181+ expect ( updateComment ) . toHaveBeenCalledWith ( '@adam@example.com. ' , true ) ;
182+ expect ( setSelection ) . toHaveBeenCalledWith ( { start : 19 , end : 19 } ) ;
183183 } ) ;
184184
185- it ( 'does not append an extra trailing dot when selected mention already matches dotted prefix' , async ( ) => {
185+ it ( 'does not append an extra trailing dot and inserts trailing space when selected mention already matches dotted prefix' , async ( ) => {
186186 mockPersonalDetails = { } ;
187187 mockPersonalDetails [ 2 ] = {
188188 accountID : 2 ,
@@ -199,7 +199,49 @@ describe('SuggestionMention', () => {
199199
200200 act ( ( ) => onSelect ( 0 ) ) ;
201201
202- expect ( updateComment ) . toHaveBeenCalledWith ( '@a.smith@example.com' , true ) ;
202+ expect ( updateComment ) . toHaveBeenCalledWith ( '@a.smith@example.com ' , true ) ;
203203 expect ( setSelection ) . toHaveBeenCalledWith ( { start : 21 , end : 21 } ) ;
204204 } ) ;
205+
206+ it ( 'does not insert trailing space when mention is followed by a comma (punctuation)' , async ( ) => {
207+ mockPersonalDetails = { } ;
208+ mockPersonalDetails [ 2 ] = {
209+ accountID : 2 ,
210+ login : 'adam@example.com' ,
211+ firstName : 'Adam' ,
212+ lastName : 'Tester' ,
213+ } ;
214+
215+ const updateComment = jest . fn ( ) ;
216+ const { setSelection} = renderSuggestionMention ( '@a, thanks' , updateComment , { start : 2 , end : 2 } ) ;
217+
218+ await waitFor ( ( ) => expect ( mockMentionSuggestionsSpy ) . toHaveBeenCalled ( ) ) ;
219+ const { onSelect} = getLastMentionSuggestionsProps ( ) ;
220+
221+ act ( ( ) => onSelect ( 0 ) ) ;
222+
223+ expect ( updateComment ) . toHaveBeenCalledWith ( '@adam@example.com, thanks' , true ) ;
224+ expect ( setSelection ) . toHaveBeenCalledWith ( { start : 17 , end : 17 } ) ;
225+ } ) ;
226+
227+ it ( 'inserts trailing space when mention is followed by a regular word' , async ( ) => {
228+ mockPersonalDetails = { } ;
229+ mockPersonalDetails [ 2 ] = {
230+ accountID : 2 ,
231+ login : 'adam@example.com' ,
232+ firstName : 'Adam' ,
233+ lastName : 'Tester' ,
234+ } ;
235+
236+ const updateComment = jest . fn ( ) ;
237+ const { setSelection} = renderSuggestionMention ( '@a thanks' , updateComment , { start : 2 , end : 2 } ) ;
238+
239+ await waitFor ( ( ) => expect ( mockMentionSuggestionsSpy ) . toHaveBeenCalled ( ) ) ;
240+ const { onSelect} = getLastMentionSuggestionsProps ( ) ;
241+
242+ act ( ( ) => onSelect ( 0 ) ) ;
243+
244+ expect ( updateComment ) . toHaveBeenCalledWith ( '@adam@example.com thanks' , true ) ;
245+ expect ( setSelection ) . toHaveBeenCalledWith ( { start : 18 , end : 18 } ) ;
246+ } ) ;
205247} ) ;
0 commit comments