2025-03-10 15:20:51 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
|
Please see LICENSE in the repository root for full details.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-03-13 11:20:32 +01:00
|
|
|
import { it, vi } from "vitest";
|
2025-03-10 15:20:51 +01:00
|
|
|
import { render, screen } from "@testing-library/react";
|
|
|
|
|
import { type ReactElement, useCallback } from "react";
|
|
|
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
|
import { BrowserRouter } from "react-router-dom";
|
|
|
|
|
|
2025-03-21 15:07:15 -04:00
|
|
|
import { GroupCallErrorBoundary } from "./room/GroupCallErrorBoundary";
|
|
|
|
|
import { useErrorBoundary } from "./useErrorBoundary";
|
|
|
|
|
import { ConnectionLostError } from "./utils/errors";
|
2025-03-10 15:20:51 +01:00
|
|
|
|
|
|
|
|
it("should show async error", async () => {
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
|
|
|
|
|
const TestComponent = (): ReactElement => {
|
2025-03-21 15:07:15 -04:00
|
|
|
const { showErrorBoundary } = useErrorBoundary();
|
2025-03-10 15:20:51 +01:00
|
|
|
|
|
|
|
|
const onClick = useCallback((): void => {
|
2025-03-21 15:07:15 -04:00
|
|
|
showErrorBoundary(new ConnectionLostError());
|
|
|
|
|
}, [showErrorBoundary]);
|
2025-03-10 15:20:51 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<h1>HELLO</h1>
|
|
|
|
|
<button onClick={onClick}>Click me</button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render(
|
|
|
|
|
<BrowserRouter>
|
2025-03-17 11:26:16 +01:00
|
|
|
<GroupCallErrorBoundary widget={null} recoveryActionHandler={vi.fn()}>
|
|
|
|
|
<TestComponent />
|
|
|
|
|
</GroupCallErrorBoundary>
|
2025-03-10 15:20:51 +01:00
|
|
|
</BrowserRouter>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Click me" }));
|
|
|
|
|
|
|
|
|
|
await screen.findByText("Connection lost");
|
|
|
|
|
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Reconnect" }));
|
|
|
|
|
|
|
|
|
|
await screen.findByText("HELLO");
|
|
|
|
|
});
|