fix: match filenames against both animal_id_string and animal_name

Multi-word names ("Rat A") now allow any word separator in the
filename — space, underscore, or dash — so "Rat_A_session.csv"
and "Rat-A-data.bin" both match. Single-word names and numeric IDs
are unchanged. Partial overlaps still rejected ("Rat" won't hit
"Rationale"). Tests: 5 new name-based match cases (24 total).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Experiments DB Dev
2026-04-23 13:33:10 -04:00
parent daf36908ef
commit 66e79c1780
2 changed files with 70 additions and 7 deletions
+49
View File
@@ -142,6 +142,55 @@ describe('filename-to-subject matching', () => {
expect(screen.getByText(/unmatched/i)).toBeInTheDocument();
});
// ── animal_name matching ───────────────────────────────────────────────────
it('matches by animal_name when the name appears literally in the filename', async () => {
const animal = { id: 'b1', animal_name: 'Homer', animal_id_string: null };
const row = { animal, status: { id: 's-b1', animal_id: 'b1', date: `${DATE}T00:00:00.000Z` } };
render(<FileDropZone rows={[row]} date={DATE} />);
dropFiles([makeFile(`${DATE}_Homer_session.csv`)]);
await waitFor(() => screen.getByTestId('drop-preview'));
expect(screen.queryByText(/unmatched/i)).not.toBeInTheDocument();
expect(screen.getByText(`${DATE}_Homer_session.csv`)).toBeInTheDocument();
});
it('matches multi-word animal_name with underscores as separator in filename', async () => {
const animal = { id: 'b1', animal_name: 'Rat A', animal_id_string: null };
const row = { animal, status: { id: 's-b1', animal_id: 'b1', date: `${DATE}T00:00:00.000Z` } };
render(<FileDropZone rows={[row]} date={DATE} />);
dropFiles([makeFile(`${DATE}_Rat_A_trials.csv`)]);
await waitFor(() => screen.getByTestId('drop-preview'));
expect(screen.queryByText(/unmatched/i)).not.toBeInTheDocument();
});
it('matches multi-word animal_name with dashes as separator in filename', async () => {
const animal = { id: 'b1', animal_name: 'Rat A', animal_id_string: null };
const row = { animal, status: { id: 's-b1', animal_id: 'b1', date: `${DATE}T00:00:00.000Z` } };
render(<FileDropZone rows={[row]} date={DATE} />);
dropFiles([makeFile(`${DATE}-Rat-A-session.bin`)]);
await waitFor(() => screen.getByTestId('drop-preview'));
expect(screen.queryByText(/unmatched/i)).not.toBeInTheDocument();
});
it('matches by animal_name even when animal_id_string is also set (OR logic)', async () => {
const animal = { id: 'b1', animal_name: 'Rat A', animal_id_string: '2852' };
const row = { animal, status: { id: 's-b1', animal_id: 'b1', date: `${DATE}T00:00:00.000Z` } };
render(<FileDropZone rows={[row]} date={DATE} />);
// File uses name, not ID
dropFiles([makeFile(`${DATE}_Rat_A_ephys.bin`)]);
await waitFor(() => screen.getByTestId('drop-preview'));
expect(screen.queryByText(/unmatched/i)).not.toBeInTheDocument();
});
it('does not match a partial name overlap (Rat should not match Rationale)', async () => {
const animal = { id: 'b1', animal_name: 'Rat', animal_id_string: null };
const row = { animal, status: { id: 's-b1', animal_id: 'b1', date: `${DATE}T00:00:00.000Z` } };
render(<FileDropZone rows={[row]} date={DATE} />);
dropFiles([makeFile('Rationale_study_data.csv')]);
await waitFor(() => screen.getByTestId('drop-preview'));
expect(screen.getByText(/unmatched/i)).toBeInTheDocument();
});
it('shows warning for subjects with no matched files', async () => {
render(<FileDropZone rows={ROWS} date={DATE} />);
// Only drop file for 2852 — 3076 and 3077 get no match