@@ -8,18 +8,18 @@ import configureMockStore from "redux-mock-store";
88import NewEntry , {
99 NewEntryId ,
1010} from "components/DataEntry/DataEntryTable/NewEntry" ;
11- import { focusInput } from "components/DataEntry/utilities" ;
1211import { newWritingSystem } from "types/writingSystem" ;
1312
1413jest . mock ( "components/DataEntry/utilities.ts" , ( ) => ( {
1514 ...jest . requireActual ( "components/DataEntry/utilities.ts" ) ,
16- focusInput : jest . fn ( ) ,
15+ focusInput : ( ) => mockFocusInput ( ) ,
1716} ) ) ;
1817jest . mock ( "components/Pronunciations/PronunciationsFrontend" , ( ) => jest . fn ( ) ) ;
1918
2019const mockAddNewAudio = jest . fn ( ) ;
2120const mockAddNewEntry = jest . fn ( ) ;
2221const mockDelNewAudio = jest . fn ( ) ;
22+ const mockFocusInput = jest . fn ( ) ;
2323const mockSetNewGloss = jest . fn ( ) ;
2424const mockSetNewNote = jest . fn ( ) ;
2525const mockSetNewVern = jest . fn ( ) ;
@@ -81,7 +81,7 @@ const fireEnterOnActiveElement = async (): Promise<void> => {
8181} ;
8282
8383beforeEach ( ( ) => {
84- jest . resetAllMocks ( ) ;
84+ jest . clearAllMocks ( ) ;
8585} ) ;
8686
8787afterEach ( ( ) => {
@@ -177,34 +177,29 @@ describe("NewEntry", () => {
177177 } ) ;
178178
179179 it ( "returns focus to gloss after closing note dialog" , async ( ) => {
180- ( focusInput as jest . Mock ) . mockClear ( ) ;
181- await renderNewEntry ( "" , "" , "" ) ;
180+ await renderNewEntry ( ) ;
181+ mockFocusInput . mockClear ( ) ;
182182
183183 // Click the note button to open the dialog
184- const noteButton = screen . getByTestId ( NewEntryId . ButtonNote ) ;
185- await userEvent . click ( noteButton ) ;
186-
187- // Click cancel to close the dialog
188- const cancelButton = screen . getByTestId ( "note-edit-cancel" ) ;
189- await userEvent . click ( cancelButton ) ;
184+ await userEvent . click ( screen . getByTestId ( NewEntryId . ButtonNote ) ) ;
185+ expect ( mockFocusInput ) . not . toHaveBeenCalled ( ) ;
190186
191- // Verify that focusInput was called (which should focus the gloss field)
192- expect ( focusInput ) . toHaveBeenCalled ( ) ;
187+ // Cancel and verify that focusInput was called
188+ await userEvent . click ( screen . getByText ( new RegExp ( "cancel" ) ) ) ;
189+ expect ( mockFocusInput ) . toHaveBeenCalled ( ) ;
193190 } ) ;
194191
195192 it ( "returns focus to gloss after confirming note" , async ( ) => {
196- ( focusInput as jest . Mock ) . mockClear ( ) ;
197- await renderNewEntry ( "" , "" , "" ) ;
198-
199- // Click the note button to open the dialog
200- const noteButton = screen . getByTestId ( NewEntryId . ButtonNote ) ;
201- await userEvent . click ( noteButton ) ;
193+ await renderNewEntry ( ) ;
194+ mockFocusInput . mockClear ( ) ;
202195
203- // Click confirm to close the dialog
204- const confirmButton = screen . getByTestId ( "note-edit-confirm" ) ;
205- await userEvent . click ( confirmButton ) ;
196+ // Click the note button to open the dialog and type a note
197+ await userEvent . click ( screen . getByTestId ( NewEntryId . ButtonNote ) ) ;
198+ await userEvent . type ( document . activeElement ! , "note text" ) ;
199+ expect ( mockFocusInput ) . not . toHaveBeenCalled ( ) ;
206200
207- // Verify that focusInput was called (which should focus the gloss field)
208- expect ( focusInput ) . toHaveBeenCalled ( ) ;
201+ // Confirm and verify that focusInput was called
202+ await userEvent . click ( screen . getByText ( new RegExp ( "confirm" ) ) ) ;
203+ expect ( mockFocusInput ) . toHaveBeenCalled ( ) ;
209204 } ) ;
210205} ) ;
0 commit comments