@@ -147,4 +147,58 @@ describe("PostForm", () => {
147147 expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( new Error ( "API Error" ) ) ;
148148 consoleErrorSpy . mockRestore ( ) ;
149149 } ) ;
150+
151+ it ( "renders form elements with correct accessibility attributes" , ( ) => {
152+ renderPostForm ( ) ;
153+
154+ // Check if textarea is present and has correct tabIndex
155+ const textarea = screen . getByRole ( 'textbox' , { name : / p o s t c o n t e n t / i } ) ;
156+ expect ( textarea ) . toBeInTheDocument ( ) ;
157+ expect ( textarea ) . toHaveAttribute ( 'tabindex' , '1' ) ;
158+
159+ // Check if submit button is present and has correct tabIndex
160+ const submitButton = screen . getByRole ( 'button' , { name : / s e n d / i } ) ;
161+ expect ( submitButton ) . toBeInTheDocument ( ) ;
162+ expect ( submitButton ) . toHaveAttribute ( 'tabindex' , '2' ) ;
163+ } ) ;
164+
165+ it ( "maintains correct tab order" , async ( ) => {
166+ renderPostForm ( ) ;
167+
168+ // Get all focusable elements
169+ const textarea = screen . getByRole ( 'textbox' , { name : / p o s t c o n t e n t / i } ) ;
170+ const submitButton = screen . getByRole ( 'button' , { name : / s e n d / i } ) ;
171+
172+ // Focus the textarea
173+ textarea . focus ( ) ;
174+ expect ( document . activeElement ) . toBe ( textarea ) ;
175+
176+ // Press Tab to move to submit button
177+ await userEvent . tab ( ) ;
178+ expect ( document . activeElement ) . toBe ( submitButton ) ;
179+ } ) ;
180+
181+ it ( "applies focus styles when elements are focused" , ( ) => {
182+ renderPostForm ( ) ;
183+
184+ const textarea = screen . getByRole ( 'textbox' , { name : / p o s t c o n t e n t / i } ) ;
185+ const submitButton = screen . getByRole ( 'button' , { name : / s e n d / i } ) ;
186+
187+ // Check if focus styles are applied
188+ expect ( textarea ) . toHaveClass ( 'focus:ring-2' , 'focus:ring-blue-500' ) ;
189+ expect ( submitButton ) . toHaveClass ( 'focus:ring-2' , 'focus:ring-offset-2' , 'focus:ring-indigo-500' ) ;
190+ } ) ;
191+
192+ it ( "focuses textarea first when pressing Tab on the page" , async ( ) => {
193+ renderPostForm ( ) ;
194+
195+ // Get the textarea
196+ const textarea = screen . getByRole ( 'textbox' , { name : / p o s t c o n t e n t / i } ) ;
197+
198+ // Press Tab on the page
199+ await userEvent . tab ( ) ;
200+
201+ // Verify textarea is focused first
202+ expect ( document . activeElement ) . toBe ( textarea ) ;
203+ } ) ;
150204} ) ;
0 commit comments