2022-02-17 16:30:36 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
import { jest } from "@jest/globals";
|
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
2023-05-11 08:56:56 +00:00
|
|
|
import { ClientWidgetApi, IWidget, MatrixWidgetType } from "matrix-widget-api";
|
2022-06-03 10:00:16 +00:00
|
|
|
import { Optional } from "matrix-events-sdk";
|
2022-12-30 10:33:10 +00:00
|
|
|
import { act, render, RenderResult } from "@testing-library/react";
|
|
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { SpiedFunction } from "jest-mock";
|
2023-02-23 14:53:44 +00:00
|
|
|
import {
|
|
|
|
ApprovalOpts,
|
|
|
|
WidgetInfo,
|
|
|
|
WidgetLifecycle,
|
|
|
|
} from "@matrix-org/react-sdk-module-api/lib/lifecycles/WidgetLifecycle";
|
2022-02-17 16:30:36 +00:00
|
|
|
|
|
|
|
import RightPanel from "../../../../src/components/structures/RightPanel";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
import ResizeNotifier from "../../../../src/utils/ResizeNotifier";
|
|
|
|
import { stubClient } from "../../../test-utils";
|
|
|
|
import { Action } from "../../../../src/dispatcher/actions";
|
|
|
|
import dis from "../../../../src/dispatcher/dispatcher";
|
|
|
|
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
|
|
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
|
|
|
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
|
|
|
|
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
|
|
|
|
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
|
|
|
import WidgetStore, { IApp } from "../../../../src/stores/WidgetStore";
|
2022-04-25 12:29:54 +00:00
|
|
|
import ActiveWidgetStore from "../../../../src/stores/ActiveWidgetStore";
|
2022-02-17 16:30:36 +00:00
|
|
|
import AppTile from "../../../../src/components/views/elements/AppTile";
|
|
|
|
import { Container, WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
|
|
|
|
import AppsDrawer from "../../../../src/components/views/rooms/AppsDrawer";
|
2022-06-06 10:00:18 +00:00
|
|
|
import { ElementWidgetCapabilities } from "../../../../src/stores/widgets/ElementWidgetCapabilities";
|
|
|
|
import { ElementWidget } from "../../../../src/stores/widgets/StopGapWidget";
|
|
|
|
import { WidgetMessagingStore } from "../../../../src/stores/widgets/WidgetMessagingStore";
|
2023-02-23 14:53:44 +00:00
|
|
|
import { ModuleRunner } from "../../../../src/modules/ModuleRunner";
|
2023-03-16 11:07:29 +00:00
|
|
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
2022-02-17 16:30:36 +00:00
|
|
|
|
|
|
|
describe("AppTile", () => {
|
2022-12-30 10:33:10 +00:00
|
|
|
let cli: MatrixClient;
|
2022-06-06 10:00:18 +00:00
|
|
|
let r1: Room;
|
|
|
|
let r2: Room;
|
2022-02-17 16:30:36 +00:00
|
|
|
const resizeNotifier = new ResizeNotifier();
|
2022-03-15 12:15:26 +00:00
|
|
|
let app1: IApp;
|
|
|
|
let app2: IApp;
|
|
|
|
|
|
|
|
const waitForRps = (roomId: string) =>
|
|
|
|
new Promise<void>((resolve) => {
|
|
|
|
const update = () => {
|
|
|
|
if (RightPanelStore.instance.currentCardForRoom(roomId).phase !== RightPanelPhases.Widget) return;
|
|
|
|
RightPanelStore.instance.off(UPDATE_EVENT, update);
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
RightPanelStore.instance.on(UPDATE_EVENT, update);
|
|
|
|
});
|
2022-02-17 16:30:36 +00:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
stubClient();
|
|
|
|
cli = MatrixClientPeg.get();
|
|
|
|
cli.hasLazyLoadMembersEnabled = () => false;
|
|
|
|
|
|
|
|
// Init misc. startup deps
|
|
|
|
DMRoomMap.makeShared();
|
|
|
|
|
|
|
|
r1 = new Room("r1", cli, "@name:example.com");
|
|
|
|
r2 = new Room("r2", cli, "@name:example.com");
|
|
|
|
|
|
|
|
jest.spyOn(cli, "getRoom").mockImplementation((roomId) => {
|
|
|
|
if (roomId === "r1") return r1;
|
|
|
|
if (roomId === "r2") return r2;
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
jest.spyOn(cli, "getVisibleRooms").mockImplementation(() => {
|
|
|
|
return [r1, r2];
|
|
|
|
});
|
|
|
|
|
2022-03-15 12:15:26 +00:00
|
|
|
// Adjust various widget stores to add mock apps
|
|
|
|
app1 = {
|
2022-02-17 16:30:36 +00:00
|
|
|
id: "1",
|
|
|
|
eventId: "1",
|
|
|
|
roomId: "r1",
|
|
|
|
type: MatrixWidgetType.Custom,
|
|
|
|
url: "https://example.com",
|
2022-03-15 12:15:26 +00:00
|
|
|
name: "Example 1",
|
2022-12-30 10:33:10 +00:00
|
|
|
creatorUserId: cli.getSafeUserId(),
|
2022-08-30 19:13:39 +00:00
|
|
|
avatar_url: undefined,
|
2022-03-15 12:15:26 +00:00
|
|
|
};
|
|
|
|
app2 = {
|
|
|
|
id: "1",
|
|
|
|
eventId: "2",
|
|
|
|
roomId: "r2",
|
|
|
|
type: MatrixWidgetType.Custom,
|
|
|
|
url: "https://example.com",
|
|
|
|
name: "Example 2",
|
2022-12-30 10:33:10 +00:00
|
|
|
creatorUserId: cli.getSafeUserId(),
|
2022-08-30 19:13:39 +00:00
|
|
|
avatar_url: undefined,
|
2022-02-17 16:30:36 +00:00
|
|
|
};
|
2022-12-30 10:33:10 +00:00
|
|
|
jest.spyOn(WidgetStore.instance, "getApps").mockImplementation((roomId: string): Array<IApp> => {
|
2022-03-15 12:15:26 +00:00
|
|
|
if (roomId === "r1") return [app1];
|
|
|
|
if (roomId === "r2") return [app2];
|
2022-12-30 10:33:10 +00:00
|
|
|
return [];
|
2022-03-15 12:15:26 +00:00
|
|
|
});
|
2022-02-17 16:30:36 +00:00
|
|
|
|
|
|
|
// Wake up various stores we rely on
|
|
|
|
WidgetLayoutStore.instance.useUnitTestClient(cli);
|
|
|
|
// @ts-ignore
|
|
|
|
await WidgetLayoutStore.instance.onReady();
|
|
|
|
RightPanelStore.instance.useUnitTestClient(cli);
|
|
|
|
// @ts-ignore
|
|
|
|
await RightPanelStore.instance.onReady();
|
|
|
|
});
|
|
|
|
|
2022-03-22 10:32:35 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockRestore();
|
|
|
|
});
|
|
|
|
|
2022-02-17 16:30:36 +00:00
|
|
|
it("destroys non-persisted right panel widget on room change", async () => {
|
|
|
|
// Set up right panel state
|
|
|
|
const realGetValue = SettingsStore.getValue;
|
|
|
|
const mockSettings = jest.spyOn(SettingsStore, "getValue").mockImplementation((name, roomId) => {
|
|
|
|
if (name !== "RightPanel.phases") return realGetValue(name, roomId);
|
|
|
|
if (roomId === "r1") {
|
|
|
|
return {
|
|
|
|
history: [
|
|
|
|
{
|
|
|
|
phase: RightPanelPhases.Widget,
|
|
|
|
state: {
|
|
|
|
widgetId: "1",
|
2022-12-12 11:24:14 +00:00
|
|
|
},
|
2022-02-17 16:30:36 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
isOpen: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Run initial render with room 1, and also running lifecycle methods
|
2022-12-30 10:33:10 +00:00
|
|
|
const renderResult = render(
|
2022-02-17 16:30:36 +00:00
|
|
|
<MatrixClientContext.Provider value={cli}>
|
2023-03-16 11:07:29 +00:00
|
|
|
<RightPanel
|
|
|
|
room={r1}
|
|
|
|
resizeNotifier={resizeNotifier}
|
|
|
|
permalinkCreator={new RoomPermalinkCreator(r1, r1.roomId)}
|
|
|
|
/>
|
2022-02-17 16:30:36 +00:00
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
|
|
|
// Wait for RPS room 1 updates to fire
|
2022-03-15 12:15:26 +00:00
|
|
|
const rpsUpdated = waitForRps("r1");
|
2022-02-17 16:30:36 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
room_id: "r1",
|
|
|
|
});
|
|
|
|
await rpsUpdated;
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
expect(renderResult.getByText("Example 1")).toBeInTheDocument();
|
2022-04-25 12:29:54 +00:00
|
|
|
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(true);
|
2022-02-17 16:30:36 +00:00
|
|
|
|
|
|
|
// We want to verify that as we change to room 2, we should close the
|
|
|
|
// right panel and destroy the widget.
|
|
|
|
|
2022-02-21 16:57:44 +00:00
|
|
|
// Switch to room 2
|
2022-02-17 16:30:36 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
room_id: "r2",
|
|
|
|
});
|
2022-12-30 10:33:10 +00:00
|
|
|
|
|
|
|
renderResult.rerender(
|
2022-02-17 16:30:36 +00:00
|
|
|
<MatrixClientContext.Provider value={cli}>
|
2023-03-16 11:07:29 +00:00
|
|
|
<RightPanel
|
|
|
|
room={r2}
|
|
|
|
resizeNotifier={resizeNotifier}
|
|
|
|
permalinkCreator={new RoomPermalinkCreator(r2, r2.roomId)}
|
|
|
|
/>
|
2022-02-17 16:30:36 +00:00
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
expect(renderResult.queryByText("Example 1")).not.toBeInTheDocument();
|
2022-04-25 12:29:54 +00:00
|
|
|
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(false);
|
2022-02-17 16:30:36 +00:00
|
|
|
|
|
|
|
mockSettings.mockRestore();
|
|
|
|
});
|
|
|
|
|
2022-03-15 12:15:26 +00:00
|
|
|
it("distinguishes widgets with the same ID in different rooms", async () => {
|
|
|
|
// Set up right panel state
|
|
|
|
const realGetValue = SettingsStore.getValue;
|
2022-03-22 10:32:35 +00:00
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((name, roomId) => {
|
2022-03-15 12:15:26 +00:00
|
|
|
if (name === "RightPanel.phases") {
|
|
|
|
if (roomId === "r1") {
|
|
|
|
return {
|
|
|
|
history: [
|
|
|
|
{
|
|
|
|
phase: RightPanelPhases.Widget,
|
|
|
|
state: {
|
|
|
|
widgetId: "1",
|
2022-12-12 11:24:14 +00:00
|
|
|
},
|
2022-03-15 12:15:26 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
isOpen: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return realGetValue(name, roomId);
|
2022-03-22 10:32:35 +00:00
|
|
|
});
|
2022-03-15 12:15:26 +00:00
|
|
|
|
|
|
|
// Run initial render with room 1, and also running lifecycle methods
|
2022-12-30 10:33:10 +00:00
|
|
|
const renderResult = render(
|
2022-03-15 12:15:26 +00:00
|
|
|
<MatrixClientContext.Provider value={cli}>
|
2023-03-16 11:07:29 +00:00
|
|
|
<RightPanel
|
|
|
|
room={r1}
|
|
|
|
resizeNotifier={resizeNotifier}
|
|
|
|
permalinkCreator={new RoomPermalinkCreator(r1, r1.roomId)}
|
|
|
|
/>
|
2022-03-15 12:15:26 +00:00
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
|
|
|
// Wait for RPS room 1 updates to fire
|
|
|
|
const rpsUpdated1 = waitForRps("r1");
|
|
|
|
dis.dispatch({
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
room_id: "r1",
|
|
|
|
});
|
|
|
|
await rpsUpdated1;
|
|
|
|
|
2022-04-25 12:29:54 +00:00
|
|
|
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(true);
|
|
|
|
expect(ActiveWidgetStore.instance.isLive("1", "r2")).toBe(false);
|
2022-03-15 12:15:26 +00:00
|
|
|
|
2022-03-22 10:32:35 +00:00
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((name, roomId) => {
|
2022-03-15 12:15:26 +00:00
|
|
|
if (name === "RightPanel.phases") {
|
|
|
|
if (roomId === "r2") {
|
|
|
|
return {
|
|
|
|
history: [
|
|
|
|
{
|
|
|
|
phase: RightPanelPhases.Widget,
|
|
|
|
state: {
|
|
|
|
widgetId: "1",
|
2022-12-12 11:24:14 +00:00
|
|
|
},
|
2022-03-15 12:15:26 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
isOpen: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return realGetValue(name, roomId);
|
2022-03-22 10:32:35 +00:00
|
|
|
});
|
2022-03-15 12:15:26 +00:00
|
|
|
// Wait for RPS room 2 updates to fire
|
|
|
|
const rpsUpdated2 = waitForRps("r2");
|
|
|
|
// Switch to room 2
|
|
|
|
dis.dispatch({
|
|
|
|
action: Action.ViewRoom,
|
|
|
|
room_id: "r2",
|
|
|
|
});
|
2022-12-30 10:33:10 +00:00
|
|
|
renderResult.rerender(
|
2022-03-15 12:15:26 +00:00
|
|
|
<MatrixClientContext.Provider value={cli}>
|
2023-03-16 11:07:29 +00:00
|
|
|
<RightPanel
|
|
|
|
room={r2}
|
|
|
|
resizeNotifier={resizeNotifier}
|
|
|
|
permalinkCreator={new RoomPermalinkCreator(r2, r2.roomId)}
|
|
|
|
/>
|
2022-03-15 12:15:26 +00:00
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
|
|
|
await rpsUpdated2;
|
|
|
|
|
2022-04-25 12:29:54 +00:00
|
|
|
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(false);
|
|
|
|
expect(ActiveWidgetStore.instance.isLive("1", "r2")).toBe(true);
|
2022-03-15 12:15:26 +00:00
|
|
|
});
|
|
|
|
|
2022-02-17 16:30:36 +00:00
|
|
|
it("preserves non-persisted widget on container move", async () => {
|
|
|
|
// Set up widget in top container
|
|
|
|
const realGetValue = SettingsStore.getValue;
|
|
|
|
const mockSettings = jest.spyOn(SettingsStore, "getValue").mockImplementation((name, roomId) => {
|
|
|
|
if (name !== "Widgets.layout") return realGetValue(name, roomId);
|
|
|
|
if (roomId === "r1") {
|
|
|
|
return {
|
|
|
|
widgets: {
|
|
|
|
1: {
|
|
|
|
container: Container.Top,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
act(() => {
|
2022-02-17 16:30:36 +00:00
|
|
|
WidgetLayoutStore.instance.recalculateRoom(r1);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Run initial render with room 1, and also running lifecycle methods
|
2022-12-30 10:33:10 +00:00
|
|
|
const renderResult = render(
|
2022-02-17 16:30:36 +00:00
|
|
|
<MatrixClientContext.Provider value={cli}>
|
2022-12-30 10:33:10 +00:00
|
|
|
<AppsDrawer userId={cli.getSafeUserId()} room={r1} resizeNotifier={resizeNotifier} />
|
2022-02-17 16:30:36 +00:00
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
expect(renderResult.getByText("Example 1")).toBeInTheDocument();
|
2022-04-25 12:29:54 +00:00
|
|
|
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(true);
|
2022-02-17 16:30:36 +00:00
|
|
|
|
|
|
|
// We want to verify that as we move the widget to the center container,
|
|
|
|
// the widget frame remains running.
|
|
|
|
|
|
|
|
// Stop mocking settings so that the widget move can take effect
|
|
|
|
mockSettings.mockRestore();
|
2022-12-30 10:33:10 +00:00
|
|
|
act(() => {
|
|
|
|
// Move widget to center
|
2022-03-15 12:15:26 +00:00
|
|
|
WidgetLayoutStore.instance.moveToContainer(r1, app1, Container.Center);
|
2022-02-17 16:30:36 +00:00
|
|
|
});
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
expect(renderResult.getByText("Example 1")).toBeInTheDocument();
|
2022-04-25 12:29:54 +00:00
|
|
|
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(true);
|
2022-02-17 16:30:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
// @ts-ignore
|
|
|
|
await WidgetLayoutStore.instance.onNotReady();
|
|
|
|
// @ts-ignore
|
|
|
|
await RightPanelStore.instance.onNotReady();
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
});
|
2022-06-03 10:00:16 +00:00
|
|
|
|
|
|
|
describe("for a pinned widget", () => {
|
2022-12-30 10:33:10 +00:00
|
|
|
let renderResult: RenderResult;
|
|
|
|
let moveToContainerSpy: SpiedFunction<typeof WidgetLayoutStore.instance.moveToContainer>;
|
2022-06-03 10:00:16 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-12-30 10:33:10 +00:00
|
|
|
renderResult = render(
|
2022-06-03 10:00:16 +00:00
|
|
|
<MatrixClientContext.Provider value={cli}>
|
|
|
|
<AppTile key={app1.id} app={app1} room={r1} />
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
2022-12-12 11:24:14 +00:00
|
|
|
|
2022-06-03 10:00:16 +00:00
|
|
|
moveToContainerSpy = jest.spyOn(WidgetLayoutStore.instance, "moveToContainer");
|
|
|
|
});
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
it("should not display the »Popout widget« button", () => {
|
|
|
|
expect(renderResult.queryByLabelText("Popout widget")).not.toBeInTheDocument();
|
2022-06-06 10:00:18 +00:00
|
|
|
});
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
it("clicking 'minimise' should send the widget to the right", async () => {
|
|
|
|
await userEvent.click(renderResult.getByTitle("Minimise"));
|
2022-06-03 10:00:16 +00:00
|
|
|
expect(moveToContainerSpy).toHaveBeenCalledWith(r1, app1, Container.Right);
|
|
|
|
});
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
it("clicking 'maximise' should send the widget to the center", async () => {
|
|
|
|
await userEvent.click(renderResult.getByTitle("Maximise"));
|
2022-06-03 10:00:16 +00:00
|
|
|
expect(moveToContainerSpy).toHaveBeenCalledWith(r1, app1, Container.Center);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("for a maximised (centered) widget", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(WidgetLayoutStore.instance, "isInContainer").mockImplementation(
|
2023-05-11 08:56:56 +00:00
|
|
|
(room: Optional<Room>, widget: IWidget, container: Container) => {
|
2022-06-03 10:00:16 +00:00
|
|
|
return room === r1 && widget === app1 && container === Container.Center;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
it("clicking 'un-maximise' should send the widget to the top", async () => {
|
|
|
|
await userEvent.click(renderResult.getByTitle("Un-maximise"));
|
2022-06-03 10:00:16 +00:00
|
|
|
expect(moveToContainerSpy).toHaveBeenCalledWith(r1, app1, Container.Top);
|
|
|
|
});
|
|
|
|
});
|
2022-06-06 10:00:18 +00:00
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
describe("with an existing widgetApi with requiresClient = false", () => {
|
2022-06-06 10:00:18 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
const api = {
|
|
|
|
hasCapability: (capability: ElementWidgetCapabilities): boolean => {
|
|
|
|
return !(capability === ElementWidgetCapabilities.RequiresClient);
|
|
|
|
},
|
|
|
|
once: () => {},
|
2022-12-30 10:33:10 +00:00
|
|
|
stop: () => {},
|
2022-06-06 10:00:18 +00:00
|
|
|
} as unknown as ClientWidgetApi;
|
|
|
|
|
|
|
|
const mockWidget = new ElementWidget(app1);
|
|
|
|
WidgetMessagingStore.instance.storeMessaging(mockWidget, r1.roomId, api);
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
renderResult = render(
|
2022-06-06 10:00:18 +00:00
|
|
|
<MatrixClientContext.Provider value={cli}>
|
|
|
|
<AppTile key={app1.id} app={app1} room={r1} />
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-12-30 10:33:10 +00:00
|
|
|
it("should display the »Popout widget« button", () => {
|
|
|
|
expect(renderResult.getByTitle("Popout widget")).toBeInTheDocument();
|
2022-06-06 10:00:18 +00:00
|
|
|
});
|
|
|
|
});
|
2022-06-03 10:00:16 +00:00
|
|
|
});
|
2023-02-23 14:53:44 +00:00
|
|
|
|
|
|
|
it("for a pinned widget permission load", () => {
|
|
|
|
jest.spyOn(ModuleRunner.instance, "invoke").mockImplementation((lifecycleEvent, opts, widgetInfo) => {
|
|
|
|
if (lifecycleEvent === WidgetLifecycle.PreLoadRequest && (widgetInfo as WidgetInfo).id === app1.id) {
|
|
|
|
(opts as ApprovalOpts).approved = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// userId and creatorUserId are different
|
|
|
|
const renderResult = render(
|
|
|
|
<MatrixClientContext.Provider value={cli}>
|
|
|
|
<AppTile key={app1.id} app={app1} room={r1} userId="@user1" creatorUserId="@userAnother" />
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(renderResult.queryByRole("button", { name: "Continue" })).not.toBeInTheDocument();
|
|
|
|
});
|
2022-02-17 16:30:36 +00:00
|
|
|
});
|