fix(e2e): implement clickSwitch utility for reliable toggle interactions and enhance tests with new helper functions

This commit is contained in:
GitHub Actions
2026-02-02 07:23:46 +00:00
parent 5b4df96581
commit 8e31db2a5a
15 changed files with 1900 additions and 1477 deletions
+37
View File
@@ -55,6 +55,43 @@ export async function clickAndWaitForResponse(
return response;
}
/**
* Click a Switch/Toggle component and wait for an API response atomically.
* Uses the clickSwitch helper to handle the hidden input structure.
* @param page - Playwright Page instance
* @param switchLocator - Locator for the switch element
* @param urlPattern - URL string or RegExp to match
* @param options - Configuration options
* @returns The matched response
*/
export async function clickSwitchAndWaitForResponse(
page: Page,
switchLocator: Locator,
urlPattern: string | RegExp,
options: { status?: number; timeout?: number; scrollPadding?: number } = {}
): Promise<Response> {
const { status = 200, timeout = 30000, scrollPadding = 100 } = options;
// Import dynamically to avoid circular dependency
const { clickSwitch } = await import('./ui-helpers');
const [response] = await Promise.all([
page.waitForResponse(
(resp) => {
const urlMatch =
typeof urlPattern === 'string'
? resp.url().includes(urlPattern)
: urlPattern.test(resp.url());
return urlMatch && resp.status() === status;
},
{ timeout }
),
clickSwitch(switchLocator, { scrollPadding, timeout }),
]);
return response;
}
/**
* Options for waitForToast
*/