mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +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:
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { type WidgetApi } from "matrix-widget-api";
|
||||
import EventEmitter from "events";
|
||||
|
||||
import { createWidgetHostBridge, nullHostBridge } from "./HostBridge";
|
||||
import { type WidgetHelpers } from "./widget";
|
||||
|
||||
function mockWidget(api: Partial<WidgetApi>): WidgetHelpers {
|
||||
return {
|
||||
api: api as WidgetApi,
|
||||
lazyActions: new EventEmitter(),
|
||||
client: Promise.resolve(),
|
||||
} as unknown as WidgetHelpers;
|
||||
}
|
||||
|
||||
describe("createWidgetHostBridge", () => {
|
||||
describe("downloadMedia", () => {
|
||||
const mxcUri = "mxc://example.org/alice-avatar";
|
||||
|
||||
test("passes a Blob through unchanged", async () => {
|
||||
const file = new Blob([]);
|
||||
const bridge = createWidgetHostBridge(
|
||||
mockWidget({ downloadFile: vi.fn().mockResolvedValue({ file }) }),
|
||||
);
|
||||
|
||||
await expect(bridge.downloadMedia!(mxcUri)).resolves.toBe(file);
|
||||
});
|
||||
|
||||
test("decodes a base64 string into a Blob", async () => {
|
||||
const bridge = createWidgetHostBridge(
|
||||
mockWidget({
|
||||
// "hello" in base64
|
||||
downloadFile: vi.fn().mockResolvedValue({ file: "aGVsbG8=" }),
|
||||
}),
|
||||
);
|
||||
|
||||
const blob = await bridge.downloadMedia!(mxcUri);
|
||||
|
||||
expect(blob).toBeInstanceOf(Blob);
|
||||
// The five decoded bytes, rather than the eight characters of base64 —
|
||||
// which is what we'd get if the string were stored verbatim.
|
||||
expect(blob.size).toBe(5);
|
||||
});
|
||||
|
||||
test("rejects a file format it does not understand", async () => {
|
||||
const bridge = createWidgetHostBridge(
|
||||
mockWidget({ downloadFile: vi.fn().mockResolvedValue({ file: 42 }) }),
|
||||
);
|
||||
|
||||
await expect(bridge.downloadMedia!(mxcUri)).rejects.toThrow(
|
||||
"Downloaded file format is not supported",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("supportsReactions", () => {
|
||||
const capabilities = [
|
||||
"org.matrix.msc2762.send.event:m.reaction",
|
||||
"org.matrix.msc2762.send.event:m.room.redaction",
|
||||
"org.matrix.msc2762.receive.event:m.reaction",
|
||||
"org.matrix.msc2762.receive.event:m.room.redaction",
|
||||
];
|
||||
|
||||
test("is true when the host grants every reaction capability", () => {
|
||||
const bridge = createWidgetHostBridge(
|
||||
mockWidget({ hasCapability: () => true }),
|
||||
);
|
||||
|
||||
expect(bridge.supportsReactions).toBe(true);
|
||||
});
|
||||
|
||||
test.each(capabilities)("is false without %s", (missing) => {
|
||||
const bridge = createWidgetHostBridge(
|
||||
mockWidget({ hasCapability: (c) => c !== missing }),
|
||||
);
|
||||
|
||||
expect(bridge.supportsReactions).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("nullHostBridge", () => {
|
||||
test("offers no way to close, so the interface falls back to navigation", () => {
|
||||
expect(nullHostBridge.close).toBeUndefined();
|
||||
});
|
||||
|
||||
test("offers no media download, so Element Call uses its own client", () => {
|
||||
expect(nullHostBridge.downloadMedia).toBeUndefined();
|
||||
});
|
||||
|
||||
test("supports reactions, since nothing is mediating its homeserver access", () => {
|
||||
expect(nullHostBridge.supportsReactions).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user