Skip to content

Commit 947451f

Browse files
committed
test(test9): fix field selectors + add blur/delay pattern
ROOT CAUSE: 1. Test used wrong label patterns that don't match actual field titles 2. Missing blur() + delay between fields causes stale element references FIXES: 1. **Correct label patterns**: - "targeted x" → "ML from Bregma" - "targeted y" → "AP to Bregma" - "targeted z" → "DV to Cortical Surface" - "^units$" → placeholder "Distance units defining positioning" 2. **Apply blur() + delay pattern**: After each field (location, device_type, description, targeted_location, x, y, z), call element.blur() and wait 100ms in act() to allow React to complete re-renders before querying next field Test 9 now passes: 9/11 tests passing (82%)
1 parent ba88454 commit 947451f

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

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

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,35 +1034,65 @@ describe('End-to-End Session Creation Workflow', () => {
10341034
);
10351035
expect(electrodeGroupIdInput).toHaveValue(0); // Auto-assigned ID
10361036

1037+
// Fill electrode group fields with blur() + delay to prevent stale references
10371038
// Use placeholder text to find location field (more specific than label)
1038-
const locationInputs = screen.queryAllByPlaceholderText(/type to find a location/i);
1039-
// Get the last one added (most recent electrode group)
1039+
let locationInputs = screen.queryAllByPlaceholderText(/type to find a location/i);
10401040
const electrodeGroupLocationInput = locationInputs[locationInputs.length - 1];
10411041
await user.type(electrodeGroupLocationInput, 'CA1');
1042+
electrodeGroupLocationInput.blur();
1043+
await act(async () => {
1044+
await new Promise(resolve => setTimeout(resolve, 100));
1045+
});
10421046

10431047
// Device type select - get all and use the last one (most recent electrode group)
1044-
const deviceTypeInputs = screen.queryAllByLabelText(/device type/i);
1048+
let deviceTypeInputs = screen.queryAllByLabelText(/device type/i);
10451049
await user.selectOptions(deviceTypeInputs[deviceTypeInputs.length - 1], 'tetrode_12.5');
1050+
deviceTypeInputs[deviceTypeInputs.length - 1].blur();
1051+
await act(async () => {
1052+
await new Promise(resolve => setTimeout(resolve, 100));
1053+
});
10461054

10471055
// Description field - get all and use the last one (most recent electrode group)
1048-
const descriptionInputs = screen.queryAllByLabelText(/^description$/i);
1056+
let descriptionInputs = screen.queryAllByLabelText(/^description$/i);
10491057
const electrodeGroupDescInput = descriptionInputs[descriptionInputs.length - 1];
10501058
await user.type(electrodeGroupDescInput, 'Dorsal CA1 tetrode');
1059+
electrodeGroupDescInput.blur();
1060+
await act(async () => {
1061+
await new Promise(resolve => setTimeout(resolve, 100));
1062+
});
10511063

10521064
// Fill remaining required fields for electrode group
1053-
const targetedLocationInputs = screen.queryAllByLabelText(/targeted location/i);
1065+
let targetedLocationInputs = screen.queryAllByLabelText(/targeted location/i);
10541066
await user.type(targetedLocationInputs[targetedLocationInputs.length - 1], 'CA1');
1067+
targetedLocationInputs[targetedLocationInputs.length - 1].blur();
1068+
await act(async () => {
1069+
await new Promise(resolve => setTimeout(resolve, 100));
1070+
});
10551071

1056-
const targetedXInputs = screen.queryAllByLabelText(/targeted x/i);
1072+
// Use correct label text from App.js
1073+
let targetedXInputs = screen.queryAllByLabelText(/ML from Bregma/i);
10571074
await user.type(targetedXInputs[targetedXInputs.length - 1], '1.5');
1075+
targetedXInputs[targetedXInputs.length - 1].blur();
1076+
await act(async () => {
1077+
await new Promise(resolve => setTimeout(resolve, 100));
1078+
});
10581079

1059-
const targetedYInputs = screen.queryAllByLabelText(/targeted y/i);
1080+
let targetedYInputs = screen.queryAllByLabelText(/AP to Bregma/i);
10601081
await user.type(targetedYInputs[targetedYInputs.length - 1], '2.0');
1082+
targetedYInputs[targetedYInputs.length - 1].blur();
1083+
await act(async () => {
1084+
await new Promise(resolve => setTimeout(resolve, 100));
1085+
});
10611086

1062-
const targetedZInputs = screen.queryAllByLabelText(/targeted z/i);
1087+
let targetedZInputs = screen.queryAllByLabelText(/DV to Cortical Surface/i);
10631088
await user.type(targetedZInputs[targetedZInputs.length - 1], '3.0');
1089+
targetedZInputs[targetedZInputs.length - 1].blur();
1090+
await act(async () => {
1091+
await new Promise(resolve => setTimeout(resolve, 100));
1092+
});
10641093

1065-
const unitsInputs = screen.queryAllByLabelText(/^units$/i);
1094+
// Units field is DataListElement with unique placeholder
1095+
let unitsInputs = screen.queryAllByPlaceholderText(/Distance units defining positioning/i);
10661096
await user.type(unitsInputs[unitsInputs.length - 1], 'mm');
10671097

10681098
// Export using React fiber approach

0 commit comments

Comments
 (0)