2022-10-05 23:58:27 +03:00
|
|
|
/*
|
|
|
|
Copyright 2022 Oliver Sand
|
|
|
|
Copyright 2022 Nordeck IT + Consulting GmbH.
|
|
|
|
|
|
|
|
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 { IWidget } from "matrix-widget-api";
|
|
|
|
|
2023-01-11 02:29:56 +03:00
|
|
|
import { HomeserverInstance } from "../../plugins/utils/homeserver";
|
2022-10-05 23:58:27 +03:00
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
const ROOM_NAME = "Test Room";
|
2022-10-05 23:58:27 +03:00
|
|
|
const WIDGET_ID = "fake-widget";
|
|
|
|
const WIDGET_HTML = `
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<title>Fake Widget</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Hello World
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`;
|
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
describe("Widget Layout", () => {
|
2022-10-05 23:58:27 +03:00
|
|
|
let widgetUrl: string;
|
2023-01-11 02:29:56 +03:00
|
|
|
let homeserver: HomeserverInstance;
|
2022-10-05 23:58:27 +03:00
|
|
|
let roomId: string;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-01-11 02:29:56 +03:00
|
|
|
cy.startHomeserver("default").then((data) => {
|
|
|
|
homeserver = data;
|
2022-10-05 23:58:27 +03:00
|
|
|
|
2023-01-11 02:29:56 +03:00
|
|
|
cy.initTestUser(homeserver, "Sally");
|
2022-10-05 23:58:27 +03:00
|
|
|
});
|
2022-12-12 14:24:14 +03:00
|
|
|
cy.serveHtmlFile(WIDGET_HTML).then((url) => {
|
2022-10-05 23:58:27 +03:00
|
|
|
widgetUrl = url;
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.createRoom({
|
|
|
|
name: ROOM_NAME,
|
|
|
|
}).then((id) => {
|
|
|
|
roomId = id;
|
|
|
|
|
|
|
|
// setup widget via state event
|
2022-12-12 14:24:14 +03:00
|
|
|
cy.getClient()
|
|
|
|
.then(async (matrixClient) => {
|
|
|
|
const content: IWidget = {
|
|
|
|
id: WIDGET_ID,
|
|
|
|
creatorUserId: "somebody",
|
|
|
|
type: "widget",
|
|
|
|
name: "widget",
|
|
|
|
url: widgetUrl,
|
|
|
|
};
|
|
|
|
await matrixClient.sendStateEvent(roomId, "im.vector.modular.widgets", content, WIDGET_ID);
|
|
|
|
})
|
|
|
|
.as("widgetEventSent");
|
2022-10-05 23:58:27 +03:00
|
|
|
|
|
|
|
// set initial layout
|
2022-12-12 14:24:14 +03:00
|
|
|
cy.getClient()
|
|
|
|
.then(async (matrixClient) => {
|
|
|
|
const content = {
|
|
|
|
widgets: {
|
|
|
|
[WIDGET_ID]: {
|
|
|
|
container: "top",
|
|
|
|
index: 1,
|
|
|
|
width: 100,
|
|
|
|
height: 0,
|
|
|
|
},
|
2022-10-05 23:58:27 +03:00
|
|
|
},
|
2022-12-12 14:24:14 +03:00
|
|
|
};
|
|
|
|
await matrixClient.sendStateEvent(roomId, "io.element.widgets.layout", content, "");
|
|
|
|
})
|
|
|
|
.as("layoutEventSent");
|
2022-10-05 23:58:27 +03:00
|
|
|
});
|
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
cy.all([cy.get<string>("@widgetEventSent"), cy.get<string>("@layoutEventSent")]).then(() => {
|
2022-10-05 23:58:27 +03:00
|
|
|
// open the room
|
|
|
|
cy.viewRoomByName(ROOM_NAME);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2023-01-11 02:29:56 +03:00
|
|
|
cy.stopHomeserver(homeserver);
|
2022-10-05 23:58:27 +03:00
|
|
|
cy.stopWebServers();
|
|
|
|
});
|
|
|
|
|
2023-05-22 10:48:40 +03:00
|
|
|
it("should be set properly", () => {
|
|
|
|
cy.get(".mx_AppsDrawer").percySnapshotElement("Widgets drawer on the timeline (AppsDrawer)");
|
|
|
|
});
|
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
it("manually resize the height of the top container layout", () => {
|
|
|
|
cy.get('iframe[title="widget"]').invoke("height").should("be.lessThan", 250);
|
2022-10-05 23:58:27 +03:00
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
cy.get(".mx_AppsContainer_resizerHandle")
|
|
|
|
.trigger("mousedown")
|
|
|
|
.trigger("mousemove", { clientX: 0, clientY: 550, force: true })
|
|
|
|
.trigger("mouseup", { clientX: 0, clientY: 550, force: true });
|
2022-10-05 23:58:27 +03:00
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
cy.get('iframe[title="widget"]').invoke("height").should("be.greaterThan", 400);
|
2022-10-05 23:58:27 +03:00
|
|
|
});
|
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
it("programatically resize the height of the top container layout", () => {
|
|
|
|
cy.get('iframe[title="widget"]').invoke("height").should("be.lessThan", 250);
|
2022-10-05 23:58:27 +03:00
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
cy.getClient().then(async (matrixClient) => {
|
2022-10-05 23:58:27 +03:00
|
|
|
const content = {
|
|
|
|
widgets: {
|
|
|
|
[WIDGET_ID]: {
|
2022-12-12 14:24:14 +03:00
|
|
|
container: "top",
|
|
|
|
index: 1,
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
2022-10-05 23:58:27 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-12-12 14:24:14 +03:00
|
|
|
await matrixClient.sendStateEvent(roomId, "io.element.widgets.layout", content, "");
|
2022-10-05 23:58:27 +03:00
|
|
|
});
|
|
|
|
|
2022-12-12 14:24:14 +03:00
|
|
|
cy.get('iframe[title="widget"]').invoke("height").should("be.greaterThan", 400);
|
2022-10-05 23:58:27 +03:00
|
|
|
});
|
|
|
|
});
|