This commit is contained in:
mikhail.aheichyk 2022-12-20 12:20:40 +03:00
parent 71d06b4d59
commit e0b6e52d9c
3 changed files with 63 additions and 48 deletions

View file

@ -19,7 +19,7 @@ limitations under the License.
import { IWidget } from "matrix-widget-api/src/interfaces/IWidget"; import { IWidget } from "matrix-widget-api/src/interfaces/IWidget";
import type {MatrixClient, MatrixEvent, Room} from "matrix-js-sdk/src/matrix"; import type { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import { SynapseInstance } from "../../plugins/synapsedocker"; import { SynapseInstance } from "../../plugins/synapsedocker";
import { UserCredentials } from "../../support/login"; import { UserCredentials } from "../../support/login";
@ -99,17 +99,17 @@ describe("Widget Events", () => {
let demoWidgetUrl: string; let demoWidgetUrl: string;
beforeEach(() => { beforeEach(() => {
cy.startSynapse("default").then(data => { cy.startSynapse("default").then((data) => {
synapse = data; synapse = data;
cy.initTestUser(synapse, "Mike").then(_user => { cy.initTestUser(synapse, "Mike").then((_user) => {
user = _user; user = _user;
}); });
cy.getBot(synapse, { displayName: "Bot", autoAcceptInvites: true }).then(_bot => { cy.getBot(synapse, { displayName: "Bot", autoAcceptInvites: true }).then((_bot) => {
bot = _bot; bot = _bot;
}); });
}); });
cy.serveHtmlFile(DEMO_WIDGET_HTML).then(url => { cy.serveHtmlFile(DEMO_WIDGET_HTML).then((url) => {
demoWidgetUrl = url; demoWidgetUrl = url;
}); });
}); });
@ -119,52 +119,56 @@ describe("Widget Events", () => {
cy.stopWebServers(); cy.stopWebServers();
}); });
it('should be updated if user is re-invited into the room with updated state event', () => { it("should be updated if user is re-invited into the room with updated state event", () => {
cy.createRoom({ cy.createRoom({
name: ROOM_NAME, name: ROOM_NAME,
invite: [bot.getUserId()], invite: [bot.getUserId()],
}).then(roomId => { }).then((roomId) => {
// setup widget via state event // setup widget via state event
cy.getClient().then(async matrixClient => { cy.getClient()
const content: IWidget = { .then(async (matrixClient) => {
id: DEMO_WIDGET_ID, const content: IWidget = {
creatorUserId: 'somebody', id: DEMO_WIDGET_ID,
type: DEMO_WIDGET_TYPE, creatorUserId: "somebody",
name: DEMO_WIDGET_NAME, type: DEMO_WIDGET_TYPE,
url: demoWidgetUrl, name: DEMO_WIDGET_NAME,
}; url: demoWidgetUrl,
await matrixClient.sendStateEvent(roomId, 'im.vector.modular.widgets', content, DEMO_WIDGET_ID); };
}).as('widgetEventSent'); await matrixClient.sendStateEvent(roomId, "im.vector.modular.widgets", content, DEMO_WIDGET_ID);
})
.as("widgetEventSent");
// set initial layout // set initial layout
cy.getClient().then(async matrixClient => { cy.getClient()
const content = { .then(async (matrixClient) => {
widgets: { const content = {
[DEMO_WIDGET_ID]: { widgets: {
container: 'top', index: 1, width: 100, height: 0, [DEMO_WIDGET_ID]: {
container: "top",
index: 1,
width: 100,
height: 0,
},
}, },
}, };
}; await matrixClient.sendStateEvent(roomId, "io.element.widgets.layout", content, "");
await matrixClient.sendStateEvent(roomId, 'io.element.widgets.layout', content, ""); })
}).as('layoutEventSent'); .as("layoutEventSent");
// open the room // open the room
cy.viewRoomByName(ROOM_NAME); cy.viewRoomByName(ROOM_NAME);
// approve capabilities // approve capabilities
cy.contains('.mx_WidgetCapabilitiesPromptDialog button', 'Approve').click(); cy.contains(".mx_WidgetCapabilitiesPromptDialog button", "Approve").click();
cy.all([ cy.all([cy.get<string>("@widgetEventSent"), cy.get<string>("@layoutEventSent")]).then(async () => {
cy.get<string>("@widgetEventSent"),
cy.get<string>("@layoutEventSent"),
]).then(async () => {
// bot creates a new room with 'net.metadata_invite_shared' state event // bot creates a new room with 'net.metadata_invite_shared' state event
const { room_id: roomNew } = await bot.createRoom({ const { room_id: roomNew } = await bot.createRoom({
name: "New room", name: "New room",
initial_state: [ initial_state: [
{ {
type: 'net.metadata_invite_shared', type: "net.metadata_invite_shared",
state_key: '', state_key: "",
content: { content: {
value: "initial", value: "initial",
}, },
@ -175,28 +179,39 @@ describe("Widget Events", () => {
await bot.invite(roomNew, user.userId); await bot.invite(roomNew, user.userId);
// widget should receive 'net.metadata_invite_shared' event after invite // widget should receive 'net.metadata_invite_shared' event after invite
cy.window().then(async win => { cy.window().then(async (win) => {
await waitForRoom(win, roomId, (room) => { await waitForRoom(win, roomId, (room) => {
const events = room.getLiveTimeline().getEvents(); const events = room.getLiveTimeline().getEvents();
return events.some(e => e.getType() === 'net.widget_echo' return events.some(
&& e.getContent().type === 'net.metadata_invite_shared' (e) =>
&& e.getContent().content.value === 'initial'); e.getType() === "net.widget_echo" &&
e.getContent().type === "net.metadata_invite_shared" &&
e.getContent().content.value === "initial",
);
}); });
}); });
await bot.sendStateEvent(roomNew, 'net.metadata_invite_shared', { await bot.sendStateEvent(
value: "new_value", roomNew,
}, ''); "net.metadata_invite_shared",
{
value: "new_value",
},
"",
);
await bot.invite(roomNew, user.userId, 'something changed in the room'); await bot.invite(roomNew, user.userId, "something changed in the room");
// widget should receive updated 'net.metadata_invite_shared' event after re-invite // widget should receive updated 'net.metadata_invite_shared' event after re-invite
cy.window().then(async win => { cy.window().then(async (win) => {
await waitForRoom(win, roomId, (room) => { await waitForRoom(win, roomId, (room) => {
const events = room.getLiveTimeline().getEvents(); const events = room.getLiveTimeline().getEvents();
return events.some(e => e.getType() === 'net.widget_echo' return events.some(
&& e.getContent().type === 'net.metadata_invite_shared' (e) =>
&& e.getContent().content.value === 'new_value'); e.getType() === "net.widget_echo" &&
e.getContent().type === "net.metadata_invite_shared" &&
e.getContent().content.value === "new_value",
);
}); });
}); });
}); });

View file

@ -76,5 +76,5 @@ ui_auth:
session_timeout: "300s" session_timeout: "300s"
room_prejoin_state: room_prejoin_state:
additional_event_types: additional_event_types:
- net.metadata_invite_shared - net.metadata_invite_shared

View file

@ -524,7 +524,7 @@ export class StopGapWidget extends EventEmitter {
// invitation room will assign it and new state events will be not forwarded to the widget // invitation room will assign it and new state events will be not forwarded to the widget
// because of empty timeline for invitation room and assigned marker. // because of empty timeline for invitation room and assigned marker.
const room = this.client.getRoom(ev.getRoomId()); const room = this.client.getRoom(ev.getRoomId());
if (room && room.getMyMembership() !== 'invite') { if (room && room.getMyMembership() !== "invite") {
this.readUpToMap[ev.getRoomId()] = ev.getId(); this.readUpToMap[ev.getRoomId()] = ev.getId();
} }