Skip to content

Commit 2edde66

Browse files
committed
test(test7): fix stale element references + ListElement selector
Apply same fixes from test 2 to test 7: 1. Manual blur() + act() delay after each field to prevent stale references 2. Use getByPlaceholderText() for task_epochs ListElement 3. Add multiple items to ListElement by typing + Enter for each Test 7 now passes: 7/11 tests passing (was 6/11) Remaining work on test 8: SelectInputPairElement has complex structure (select dropdown + number input). Need to investigate correct way to fill this component type. Current approach tries to type text into number input which doesn't work.
1 parent 2a26b08 commit 2edde66

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

src/__tests__/integration/complete-session-creation.test.jsx

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/task name/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(/task description/i);
874+
let taskDescInputs = screen.getAllByLabelText(/task description/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(/task environment/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(/task epochs/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(/Type Task Epochs/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(/Add behavioral_events/i);
918-
let eventDescInputs = screen.queryAllByLabelText(/event description/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(/Item #/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(/event description/i);
925-
expect(eventDescInputs.length).toBe(initialEventCount + 1);
952+
behavioralEventItems = screen.queryAllByText(/Item #/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(/event description/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(/DIO info/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(/^event name$/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\. light1/i);
968+
await user.type(eventNameInput, 'Din1');
933969

934970
// Export using React fiber approach
935971
await triggerExport();

0 commit comments

Comments
 (0)