test(folders): use escaped regex for file name matching in drag-and-drop tests

Update folder tests to use an exported escapeRegExp helper when constructing
regex patterns for file name matching. This prevents false positives or errors
when file names contain special regex characters, improving test reliability.
This commit is contained in:
Richard R 2026-06-04 18:21:40 -06:00
parent 2e74e79e2c
commit 9da21a8004
2 changed files with 3 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import {
dragAndDrop,
expectDocumentListed,
expectNoDocumentLink,
escapeRegExp,
} from './helpers';
test.describe('Document folders and hint persistence', () => {
@ -16,7 +17,7 @@ test.describe('Document folders and hint persistence', () => {
// Utility to get the draggable tile for a given filename (by link).
const rowFor = (page: Page, fileName: string) => {
const link = page.getByRole('link', { name: new RegExp(fileName, 'i') }).first();
const link = page.getByRole('link', { name: new RegExp(escapeRegExp(fileName), 'i') }).first();
// The drag source is the tile container ancestor, marked with data-doc-tile.
return link.locator('xpath=ancestor::*[@data-doc-tile][1]');
};

View file

@ -4,7 +4,7 @@ import { createHash } from 'crypto';
const DIR = './tests/files/';
// Small util to safely use filenames inside regex patterns
function escapeRegExp(input: string) {
export function escapeRegExp(input: string) {
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}