This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mikhail Aheichyk <[email protected]>
- Loading branch information
Mikhail Aheichyk
committed
Oct 26, 2023
1 parent
d0b44a5
commit f106cdf
Showing
7 changed files
with
482 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
Copyright 2022-2023 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. | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
|
||
import { HomeserverInstance } from "../../plugins/utils/homeserver"; | ||
import { waitForRoom } from "../utils"; | ||
|
||
describe("Create Knock Room", () => { | ||
let homeserver: HomeserverInstance; | ||
|
||
beforeEach(() => { | ||
cy.enableLabsFeature("feature_ask_to_join"); | ||
|
||
cy.startHomeserver("default").then((data) => { | ||
homeserver = data; | ||
|
||
cy.initTestUser(homeserver, "Alice"); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.stopHomeserver(homeserver); | ||
}); | ||
|
||
it("should create a knock room", () => { | ||
cy.openCreateRoomDialog().within(() => { | ||
cy.findByRole("textbox", { name: "Name" }).type("Cybersecurity"); | ||
cy.findByRole("button", { name: "Room visibility" }).click(); | ||
cy.findByRole("option", { name: "Ask to join" }).click(); | ||
|
||
cy.findByRole("button", { name: "Create room" }).click(); | ||
}); | ||
|
||
cy.get(".mx_LegacyRoomHeader").within(() => { | ||
cy.findByText("Cybersecurity"); | ||
}); | ||
|
||
cy.hash().then((urlHash) => { | ||
const roomId = urlHash.replace("#/room/", ""); | ||
|
||
// Room should have a knock join rule | ||
cy.window().then(async (win) => { | ||
await waitForRoom(win, win.mxMatrixClientPeg.get(), roomId, (room) => { | ||
const events = room.getLiveTimeline().getEvents(); | ||
return events.some( | ||
(e) => e.getType() === "m.room.join_rules" && e.getContent().join_rule === 'knock', | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it("should create a room and change a join rule to knock", () => { | ||
cy.openCreateRoomDialog().within(() => { | ||
cy.findByRole("textbox", { name: "Name" }).type("Cybersecurity"); | ||
|
||
cy.findByRole("button", { name: "Create room" }).click(); | ||
}); | ||
|
||
cy.get(".mx_LegacyRoomHeader").within(() => { | ||
cy.findByText("Cybersecurity"); | ||
}); | ||
|
||
cy.hash().then((urlHash) => { | ||
const roomId = urlHash.replace("#/room/", ""); | ||
|
||
cy.openRoomSettings("Security & Privacy"); | ||
|
||
cy.findByRole("group", { name: "Access" }).within(() => { | ||
cy.findByRole("radio", { name: "Private (invite only)" }).should("be.checked"); | ||
cy.findByRole("radio", { name: "Ask to join" }).check({ force: true }); | ||
}); | ||
|
||
// Room should have a knock join rule | ||
cy.window().then(async (win) => { | ||
await waitForRoom(win, win.mxMatrixClientPeg.get(), roomId, (room) => { | ||
const events = room.getLiveTimeline().getEvents(); | ||
return events.some( | ||
(e) => e.getType() === "m.room.join_rules" && e.getContent().join_rule === 'knock', | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
Copyright 2023 Mikhail Aheichyk | ||
Copyright 2023 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 { MatrixClient } from "matrix-js-sdk/src/matrix"; | ||
|
||
import { HomeserverInstance } from "../../plugins/utils/homeserver"; | ||
import { UserCredentials } from "../../support/login"; | ||
import { waitForRoom } from "../utils"; | ||
|
||
describe("Knock Into Room", () => { | ||
let homeserver: HomeserverInstance; | ||
let user: UserCredentials; | ||
let bot: MatrixClient; | ||
|
||
let roomId; | ||
|
||
beforeEach(() => { | ||
cy.enableLabsFeature("feature_ask_to_join"); | ||
|
||
cy.startHomeserver("default").then((data) => { | ||
homeserver = data; | ||
|
||
cy.initTestUser(homeserver, "Alice").then((_user) => { | ||
user = _user; | ||
}); | ||
|
||
cy.getBot(homeserver, { displayName: "Bob" }).then(async (_bot) => { | ||
bot = _bot; | ||
|
||
const { room_id: newRoomId } = await bot.createRoom({ | ||
name: "Cybersecurity", | ||
initial_state: [ | ||
{ | ||
type: "m.room.join_rules", | ||
content: { | ||
join_rule: "knock", | ||
}, | ||
state_key: "", | ||
}, | ||
], | ||
}); | ||
|
||
roomId = newRoomId; | ||
}); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.stopHomeserver(homeserver); | ||
}); | ||
|
||
it("should knock into the room then knock is approved and user joins the room", () => { | ||
cy.viewRoomById(roomId); | ||
|
||
cy.get(".mx_RoomPreviewBar").within(() => { | ||
cy.findByRole("button", { name: "Join the discussion" }).click(); | ||
|
||
cy.findByRole("heading", { name: "Ask to join?" }); | ||
cy.findByRole("textbox"); | ||
cy.findByRole("button", { name: "Request access" }).click(); | ||
|
||
cy.findByRole("heading", { name: "Request to join sent" }); | ||
}); | ||
|
||
// Knocked room should appear in Rooms | ||
cy.findByRole("group", { name: "Rooms" }).findByRole("treeitem", { name: "Cybersecurity" }); | ||
|
||
cy.window().then(async (win) => { | ||
// bot waits for knock request from Alice | ||
await waitForRoom(win, bot, roomId, (room) => { | ||
const events = room.getLiveTimeline().getEvents(); | ||
return events.some( | ||
(e) => | ||
e.getType() === "m.room.member" && | ||
e.getContent()?.membership === "knock" && | ||
e.getContent()?.displayname === "Alice", | ||
); | ||
}); | ||
|
||
// bot invites Alice | ||
await bot.invite(roomId, user.userId); | ||
}); | ||
|
||
cy.findByRole("group", { name: "Invites" }).findByRole("treeitem", { name: "Cybersecurity" }); | ||
|
||
// Alice have to accept invitation in order to join the room. | ||
// It will be not needed when homeserver implements auto accept knock requests. | ||
cy.get(".mx_RoomView").findByRole("button", { name: "Accept" }).click(); | ||
|
||
cy.findByRole("group", { name: "Rooms" }).findByRole("treeitem", { name: "Cybersecurity" }); | ||
|
||
cy.findByText("Alice joined the room").should("exist"); | ||
}); | ||
|
||
it("should knock into the room and knock is cancelled by user himself", () => { | ||
cy.viewRoomById(roomId); | ||
|
||
cy.get(".mx_RoomPreviewBar").within(() => { | ||
cy.findByRole("button", { name: "Join the discussion" }).click(); | ||
|
||
cy.findByRole("heading", { name: "Ask to join?" }); | ||
cy.findByRole("textbox"); | ||
cy.findByRole("button", { name: "Request access" }).click(); | ||
|
||
cy.findByRole("heading", { name: "Request to join sent" }); | ||
}); | ||
|
||
// Knocked room should appear in Rooms | ||
cy.findByRole("group", { name: "Rooms" }).findByRole("treeitem", { name: "Cybersecurity" }); | ||
|
||
cy.get(".mx_RoomPreviewBar").within(() => { | ||
cy.findByRole("button", { name: "Cancel request" }).click(); | ||
|
||
cy.findByRole("heading", { name: "Ask to join Cybersecurity?" }); | ||
cy.findByRole("button", { name: "Request access" }); | ||
}); | ||
|
||
cy.findByRole("group", { name: "Historical" }).findByRole("treeitem", { name: "Cybersecurity" }); | ||
}); | ||
|
||
it("should knock into the room then knock is cancelled by another user and room is forgotten", () => { | ||
cy.viewRoomById(roomId); | ||
|
||
cy.get(".mx_RoomPreviewBar").within(() => { | ||
cy.findByRole("button", { name: "Join the discussion" }).click(); | ||
|
||
cy.findByRole("heading", { name: "Ask to join?" }); | ||
cy.findByRole("textbox"); | ||
cy.findByRole("button", { name: "Request access" }).click(); | ||
|
||
cy.findByRole("heading", { name: "Request to join sent" }); | ||
}); | ||
|
||
// Knocked room should appear in Rooms | ||
cy.findByRole("group", { name: "Rooms" }).findByRole("treeitem", { name: "Cybersecurity" }); | ||
|
||
cy.window().then(async (win) => { | ||
// bot waits for knock request from Alice | ||
await waitForRoom(win, bot, roomId, (room) => { | ||
const events = room.getLiveTimeline().getEvents(); | ||
return events.some( | ||
(e) => | ||
e.getType() === "m.room.member" && | ||
e.getContent()?.membership === "knock" && | ||
e.getContent()?.displayname === "Alice", | ||
); | ||
}); | ||
|
||
// bot kicks Alice | ||
await bot.kick(roomId, user.userId); | ||
}); | ||
|
||
// Room should stay in Rooms and have red badge when knock is denied | ||
cy.findByRole("group", { name: "Rooms" }).findByRole("treeitem", { name: "Cybersecurity" }).should("not.exist"); | ||
cy.findByRole("group", { name: "Rooms" }).findByRole("treeitem", { name: "Cybersecurity 1 unread mention." }); | ||
|
||
cy.get(".mx_RoomPreviewBar").within(() => { | ||
cy.findByRole("heading", { name: "You have been denied access" }); | ||
cy.findByRole("button", { name: "Forget this room" }).click(); | ||
}); | ||
|
||
// Room should disappear from the list completely when forgotten | ||
cy.findByRole("treeitem", { name: /Cybersecurity/ }).should("not.exist"); | ||
}); | ||
}); |
Oops, something went wrong.