mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-10 23:25:52 +00:00
Drop ErrorView's widget prop in favour of the host bridge
ErrorView needed a widget only to decide whether to offer a close button or a link home. That prop was threaded down through ErrorPage, RichError and GroupCallErrorBoundary from seven call sites, to answer the single question of whether the host can dismiss Element Call — which the host bridge now answers directly through the presence of close(). Read the bridge from context in ErrorView and remove the prop, along with the plumbing that carried it. No functional change: the rendered output is unchanged, as the existing snapshot confirms. Move GroupCallView onto the host bridge GroupCallView asked the widget API to keep it on screen, to close it, and to tell it when a preloaded call should join. Route all three through the host bridge and drop the widget prop.
This commit is contained in:
+22
-21
@@ -6,6 +6,8 @@ Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { act, renderHook } from "@testing-library/react";
|
||||
import { createElement, type FC, type PropsWithChildren } from "react";
|
||||
import { Subject } from "rxjs";
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
@@ -15,24 +17,28 @@ import {
|
||||
test,
|
||||
vi,
|
||||
} from "vitest";
|
||||
import EventEmitter from "events";
|
||||
import { WidgetApiToWidgetAction } from "matrix-widget-api";
|
||||
|
||||
import { useTheme } from "./useTheme";
|
||||
import { useUrlParams } from "./UrlParams";
|
||||
import { widget } from "./widget";
|
||||
import {
|
||||
type HostBridge,
|
||||
HostBridgeProvider,
|
||||
type HostRequest,
|
||||
nullHostBridge,
|
||||
} from "./HostBridge";
|
||||
|
||||
vi.mock("./UrlParams", () => ({ useUrlParams: vi.fn() }));
|
||||
vi.mock("./widget", () => ({
|
||||
widget: {
|
||||
api: { transport: { reply: vi.fn() } },
|
||||
lazyActions: new EventEmitter(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe("useTheme", () => {
|
||||
let originalClassList: DOMTokenList;
|
||||
let themeChange$: Subject<HostRequest<{ name?: string }>>;
|
||||
let wrapper: FC<PropsWithChildren>;
|
||||
|
||||
beforeEach(() => {
|
||||
themeChange$ = new Subject();
|
||||
const hostBridge: HostBridge = { ...nullHostBridge, themeChange$ };
|
||||
wrapper = ({ children }) =>
|
||||
createElement(HostBridgeProvider, { value: hostBridge }, children);
|
||||
// Save the original classList to setup spies
|
||||
originalClassList = document.body.classList;
|
||||
|
||||
@@ -55,7 +61,7 @@ describe("useTheme", () => {
|
||||
test(`should apply ${add[0]} theme when ${setTheme} theme is specified`, () => {
|
||||
(useUrlParams as Mock).mockReturnValue({ theme: setTheme });
|
||||
|
||||
renderHook(() => useTheme());
|
||||
renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(originalClassList.remove).toHaveBeenCalledWith(
|
||||
"cpd-theme-light",
|
||||
@@ -71,7 +77,7 @@ describe("useTheme", () => {
|
||||
// Simulate a previous theme
|
||||
originalClassList.item = vi.fn().mockReturnValue("cpd-theme-dark");
|
||||
|
||||
renderHook(() => useTheme());
|
||||
renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(document.body.classList.add).not.toHaveBeenCalledWith(
|
||||
"cpd-theme-dark",
|
||||
@@ -82,18 +88,13 @@ describe("useTheme", () => {
|
||||
expect(originalClassList.add).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("theme changes in response to widget actions", async () => {
|
||||
renderHook(() => useTheme());
|
||||
test("theme changes in response to host requests", () => {
|
||||
renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(originalClassList.add).toHaveBeenCalledWith("cpd-theme-dark");
|
||||
await act(() =>
|
||||
widget!.lazyActions.emit(
|
||||
WidgetApiToWidgetAction.ThemeChange,
|
||||
new CustomEvent(WidgetApiToWidgetAction.ThemeChange, {
|
||||
detail: { data: { name: "light" } },
|
||||
}),
|
||||
),
|
||||
);
|
||||
const reply = vi.fn();
|
||||
act(() => themeChange$.next({ data: { name: "light" }, reply }));
|
||||
expect(reply).toHaveBeenCalledOnce();
|
||||
expect(originalClassList.remove).toHaveBeenCalledWith(
|
||||
"cpd-theme-light",
|
||||
"cpd-theme-dark",
|
||||
|
||||
Reference in New Issue
Block a user