mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
Builder features that use tRPC need request-level coverage beyond publishing. This PR shares the publish request interceptor and uses it to test uncovered UI flows across the HTTP boundary. It only changes test support and tests; product behavior and API contracts stay unchanged. ## Todos - [x] Move the tRPC interceptor into shared Builder test support and update its publish tests. - [x] Replace the JSX paste test’s tRPC client mock with an intercepted request. - [x] Test workspace member invitations for success and server rejection. - [x] Test accepting and declining notifications. - [x] Test backup loading and both successful and failed restores. - [x] Make the shared interceptor reject invalid batch requests, enforce each request's method, and reject unregistered routes. - [x] Review Builder docs; the existing dashboard guide already describes invitations, and these test-only changes need no doc update. - [x] Run focused browser tests, Builder typecheck, lint, and formatting checks. - [x] Wait for CI on the latest commit. ## Verification - Publish browser tests: 19 files, 199 tests passed. - Shared tRPC, notifications, and backups: 3 files, 12 tests passed. - JSX paste request tests: 1 file, 6 tests passed. - Workspace member request tests: 1 file, 2 tests passed. - New regression tests failed against the previous implementation and passed with the fix. - Builder typecheck, changed-file lint, formatting, diff checks, and CI passed. Ref #6719
22 lines
741 B
TypeScript
22 lines
741 B
TypeScript
import type { ReactNode } from "react";
|
|
import { act } from "react-dom/test-utils";
|
|
import { createRoot } from "react-dom/client";
|
|
|
|
export const createBrowserTestRenderer = () => {
|
|
const global = globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean };
|
|
const previousActEnvironment = global.IS_REACT_ACT_ENVIRONMENT;
|
|
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
const container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
const root = createRoot(container);
|
|
|
|
return {
|
|
render: async (element: ReactNode) => act(async () => root.render(element)),
|
|
unmount: () => {
|
|
act(() => root.unmount());
|
|
container.remove();
|
|
global.IS_REACT_ACT_ENVIRONMENT = previousActEnvironment;
|
|
},
|
|
};
|
|
};
|