@@ -863,17 +863,34 @@ describe('End-to-End Session Creation Workflow', () => {
863863 expect ( taskNameInputs . length ) . toBe ( initialTaskCount + 1 ) ;
864864 } ) ;
865865
866+ // Fill task fields with blur() + delay pattern to avoid stale element references
866867 taskNameInputs = screen . getAllByLabelText ( / t a s k n a m e / i) ;
867868 await user . type ( taskNameInputs [ 0 ] , 'sleep' ) ;
869+ taskNameInputs [ 0 ] . blur ( ) ;
870+ await act ( async ( ) => {
871+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
872+ } ) ;
868873
869- const taskDescInputs = screen . getAllByLabelText ( / t a s k d e s c r i p t i o n / i) ;
874+ let taskDescInputs = screen . getAllByLabelText ( / t a s k d e s c r i p t i o n / i) ;
870875 await user . type ( taskDescInputs [ 0 ] , 'Rest session' ) ;
876+ taskDescInputs [ 0 ] . blur ( ) ;
877+ await act ( async ( ) => {
878+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
879+ } ) ;
871880
872881 const taskEnvInputs = screen . getAllByLabelText ( / t a s k e n v i r o n m e n t / i) ;
873882 await user . type ( taskEnvInputs [ 0 ] , 'home cage' ) ;
883+ taskEnvInputs [ 0 ] . blur ( ) ;
884+ await act ( async ( ) => {
885+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
886+ } ) ;
874887
875- const taskEpochInputs = screen . getAllByLabelText ( / t a s k e p o c h s / i) ;
876- await user . type ( taskEpochInputs [ 0 ] , '1, 3' ) ;
888+ // task_epochs is a ListElement - use placeholder instead of label
889+ const taskEpochInput = screen . getByPlaceholderText ( / T y p e T a s k E p o c h s / i) ;
890+ await user . type ( taskEpochInput , '1' ) ;
891+ await user . keyboard ( '{Enter}' ) ;
892+ await user . type ( taskEpochInput , '3' ) ;
893+ await user . keyboard ( '{Enter}' ) ;
877894
878895 // Export using React fiber approach
879896 await triggerExport ( ) ;
@@ -915,21 +932,40 @@ describe('End-to-End Session Creation Workflow', () => {
915932
916933 // Add behavioral events
917934 const addBehavioralEventButton = screen . getByTitle ( / A d d b e h a v i o r a l _ e v e n t s / i) ;
918- let eventDescInputs = screen . queryAllByLabelText ( / e v e n t d e s c r i p t i o n / i) ;
919- const initialEventCount = eventDescInputs . length ;
935+
936+ // DEBUG: Check what happens when we click Add
937+ console . log ( `DEBUG test8: BEFORE click - checking for "Add behavioral_events" button` ) ;
938+ console . log ( `DEBUG test8: Button found: ${ addBehavioralEventButton ? 'YES' : 'NO' } ` ) ;
939+
940+ // Check initial behavioral events count using a different selector
941+ // behavioral_events has SelectInputPairElement with name="description"
942+ let behavioralEventItems = screen . queryAllByText ( / I t e m # / i) ;
943+ console . log ( `DEBUG test8: Initial "Item #" count: ${ behavioralEventItems . length } ` ) ;
944+
945+ const initialEventCount = behavioralEventItems . length ;
920946
921947 await user . click ( addBehavioralEventButton ) ;
922948
949+ console . log ( `DEBUG test8: Clicked Add button, waiting for item to appear...` ) ;
950+
923951 await waitFor ( ( ) => {
924- eventDescInputs = screen . queryAllByLabelText ( / e v e n t d e s c r i p t i o n / i) ;
925- expect ( eventDescInputs . length ) . toBe ( initialEventCount + 1 ) ;
952+ behavioralEventItems = screen . queryAllByText ( / I t e m # / i) ;
953+ console . log ( `DEBUG test8: After click, "Item #" count: ${ behavioralEventItems . length } ` ) ;
954+ expect ( behavioralEventItems . length ) . toBe ( initialEventCount + 1 ) ;
926955 } ) ;
927956
928- eventDescInputs = screen . getAllByLabelText ( / e v e n t d e s c r i p t i o n / i) ;
929- await user . type ( eventDescInputs [ 0 ] , 'Poke event' ) ;
957+ // Fill behavioral event fields
958+ // behavioral_events-description is a SelectInputPairElement with unique placeholder
959+ const eventDescInput = screen . getByPlaceholderText ( / D I O i n f o / i) ;
960+ await user . type ( eventDescInput , 'Poke event' ) ;
961+ eventDescInput . blur ( ) ;
962+ await act ( async ( ) => {
963+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
964+ } ) ;
930965
931- const eventNameInputs = screen . getAllByLabelText ( / ^ e v e n t n a m e $ / i) ;
932- await user . type ( eventNameInputs [ 0 ] , 'Din1' ) ;
966+ // behavioral_events-name is a DataListElement with unique placeholder
967+ const eventNameInput = screen . getByPlaceholderText ( / E \. g \. l i g h t 1 / i) ;
968+ await user . type ( eventNameInput , 'Din1' ) ;
933969
934970 // Export using React fiber approach
935971 await triggerExport ( ) ;
0 commit comments