@@ -201,4 +201,49 @@ describe("PostForm", () => {
201201 // Verify textarea is focused first
202202 expect ( document . activeElement ) . toBe ( textarea ) ;
203203 } ) ;
204+
205+ it ( "refocuses textarea after successful form submission" , async ( ) => {
206+ const mockCreatePost = vi . mocked ( createPost ) ;
207+ mockCreatePost . mockResolvedValueOnce ( mockPost ) ;
208+
209+ renderPostForm ( ) ;
210+
211+ const textarea = screen . getByRole ( 'textbox' , { name : / p o s t c o n t e n t / i } ) ;
212+ const submitButton = screen . getByRole ( 'button' , { name : / s e n d / i } ) ;
213+
214+ // Type some text and submit
215+ await userEvent . type ( textarea , "Test post content" ) ;
216+ await userEvent . click ( submitButton ) ;
217+
218+ // Verify textarea is refocused after submission
219+ expect ( document . activeElement ) . toBe ( textarea ) ;
220+ } ) ;
221+
222+ it ( "submits form and refocuses textarea on Cmd/Ctrl+Enter" , async ( ) => {
223+ const mockCreatePost = vi . mocked ( createPost ) ;
224+ mockCreatePost . mockResolvedValueOnce ( mockPost ) ;
225+
226+ renderPostForm ( ) ;
227+
228+ const textarea = screen . getByRole ( 'textbox' , { name : / p o s t c o n t e n t / i } ) ;
229+ await userEvent . type ( textarea , "Test post content" ) ;
230+
231+ // Simulate Cmd+Enter (macOS) or Ctrl+Enter (Windows/Linux)
232+ fireEvent . keyDown ( textarea , {
233+ key : "Enter" ,
234+ code : "Enter" ,
235+ metaKey : true , // Cmd key on macOS
236+ } ) ;
237+
238+ // Verify form was submitted
239+ await waitFor ( ( ) => {
240+ expect ( mockCreatePost ) . toHaveBeenCalledWith ( {
241+ head : "Test post content" ,
242+ body : "" ,
243+ } ) ;
244+ } ) ;
245+
246+ // Verify textarea is refocused
247+ expect ( document . activeElement ) . toBe ( textarea ) ;
248+ } ) ;
204249} ) ;
0 commit comments