Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e tests : add leaveRoom #170

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ To run the tests, complete the env vars, start a web instance then run the tests
Files in 'support' folder are automatically imported by Cypress

TODO :
- make all this run in CI ! Will need running a tchap-web server at http://localhost:8080
- make all this run in CI ! Will need running a tchap-web server at http://localhost:8080. Cypress does not recommend that the server be started by cypress itself (https://docs.cypress.io/guides/references/best-practices#Web-Servers)
- clean up the server after each test : delete created rooms, log out, ...
- import/symlink/whatever the files we are using from matrix-react-sdk, instead of copying them to tchap-web repo.
18 changes: 16 additions & 2 deletions cypress/e2e/create-room/create-room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,22 @@ describe("Create Room", () => {
});

afterEach(() => {
// todo logout, otherwise the login test is not reliable aby more.
// todo delete room, otherwise the test user will end up with a million identical rooms after a while.
// We find the roomId to clean up from the current URL.
// Note : This is simple and works, so good enough for now. But if we want to store the roomId at the end of the test instead, we could use “as”
// for passing the value around : https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Sharing-Context
// Do NOT use a describe-level variable (like "let roomIdToCleanup") like we do in unit tests, cypress does not work like that.
cy.url().then(urlString => {
console.log('roomId url string', urlString);
console.log('roomId url string split', urlString.split('/#/room/'));
console.log('roomIdToCleanup', urlString.split('/#/room/')[1]);
const roomId = urlString.split('/#/room/')[1];
if (roomId) {
cy.leaveRoom(roomId);
// todo also forgetRoom to save resources.
} else {
console.error('Did not find roomId in url. Not cleaning up.');
}
});
});

it("should allow us to create a private room with name", () => {
Expand Down
10 changes: 10 additions & 0 deletions cypress/support/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ declare global {
* @param roomIdOrAlias the id or alias of the room to join
*/
joinRoom(roomIdOrAlias: string): Chainable<Room>;
/**
* :TCHAP: added this function
* Leave a room.
* @param roomId the id of the room to invite to
*/
leaveRoom(roomId: string): Chainable<{}>;
}
}
}
Expand Down Expand Up @@ -226,3 +232,7 @@ Cypress.Commands.add("bootstrapCrossSigning", () => {
Cypress.Commands.add("joinRoom", (roomIdOrAlias: string): Chainable<Room> => {
return cy.getClient().then(cli => cli.joinRoom(roomIdOrAlias));
});

Cypress.Commands.add("leaveRoom", (roomId: string): Chainable<{}> => {
return cy.getClient().then(cli => cli.leave(roomId));
});