项目文件夹

文件
wehub-resource-sync a9cd7750f4
CI / unit-test (push) Has been cancelled
CI / detect-changes (push) Has been cancelled
CI / build (push) Has been cancelled
Publish docs via GitHub Pages / Deploy docs (push) Has been cancelled
CI / test-harness (push) Has been cancelled
CI / generate-e2e-matrix (push) Has been cancelled
CI / e2e (push) Has been cancelled
CI / build-ui (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
UI v2 Integration CI / E2E (Integration) (push) Has been cancelled
UI v2 CI / Lint, Format & Test (push) Has been cancelled
UI v2 CI / E2E (Mocked) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:37:56 +08:00

55 行
1.9 KiB
TypeScript

import path from "path";
import type { Page } from "@playwright/test";
const fixturesDir = path.join(__dirname, "../fixtures");
/** Resolve a fixture file path relative to e2e/fixtures/. */
export const f = (name: string) => path.join(fixturesDir, name);
/**
* Register route mocks for the APIs that are required on every page:
* workflow/task metadata used by nav dropdowns and search forms.
*/
export async function mockCommonApis(page: Page) {
await page.route("**/api/metadata/workflow/names-and-versions", (route) =>
route.fulfill({ path: f("metadataWorkflowNamesAndVersions.json") })
);
await page.route("**/api/metadata/workflow/names", (route) =>
route.fulfill({ path: f("metadataWorkflowNames.json") })
);
await page.route("**/api/metadata/workflow/*/versions", (route) =>
route.fulfill({ path: f("metadataWorkflowVersions.json") })
);
await page.route("**/api/metadata/taskdefs", (route) =>
route.fulfill({ path: f("metadataTasks.json") })
);
}
/** Mock the workflow execution search endpoint. */
export async function mockWorkflowSearch(page: Page) {
await page.route("**/api/workflow/search**", (route) =>
route.fulfill({ path: f("workflowSearch.json") })
);
}
/** Mock the task execution search endpoint. */
export async function mockTaskSearch(page: Page) {
await page.route("**/api/tasks/search**", (route) =>
route.fulfill({ path: f("taskSearch.json") })
);
}
/**
* Mock scheduler endpoints.
* The /schedules endpoint must be mocked on any page that uses ScheduleNameInput —
* without it, serve -s returns index.html and data.map() throws, crashing the component.
*/
export async function mockSchedulerApis(page: Page) {
await page.route("**/api/scheduler/schedules**", (route) =>
route.fulfill({ path: f("schedulerDefs.json") })
);
await page.route("**/api/scheduler/search/executions**", (route) =>
route.fulfill({ path: f("schedulerExecutions.json") })
);
}