Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Cypress - stabilise "creating a DM should work" test (#9373)
Browse files Browse the repository at this point in the history
* better error message for failed bot room join

* wait for room invite before attempting bot join

* remove sent receipt assertion

* lint

* remove debug formatting

* use RoomMemberEvent enum from window
  • Loading branch information
Kerry authored Oct 7, 2022
1 parent 7fd2fb9 commit 1345825
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions cypress/e2e/crypto/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";

import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
import type { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import { SynapseInstance } from "../../plugins/synapsedocker";
import Chainable = Cypress.Chainable;

Expand Down Expand Up @@ -60,7 +61,6 @@ const testMessages = function(this: CryptoTestContext) {
// check the invite message
cy.contains(".mx_EventTile_body", "Hey!").closest(".mx_EventTile").within(() => {
cy.get(".mx_EventTile_e2eIcon_warning").should("not.exist");
cy.get(".mx_EventTile_receiptSent").should("exist");
});

// Bob sends a response
Expand All @@ -73,17 +73,31 @@ const testMessages = function(this: CryptoTestContext) {
};

const bobJoin = function(this: CryptoTestContext) {
cy.botJoinRoomByName(this.bob, "Alice").as("bobsRoom");
cy.window({ log: false }).then(async win => {
const bobRooms = this.bob.getRooms();
if (!bobRooms.length) {
await new Promise<void>(resolve => {
const onMembership = (_event) => {
this.bob.off(win.matrixcs.RoomMemberEvent.Membership, onMembership);
resolve();
};
this.bob.on(win.matrixcs.RoomMemberEvent.Membership, onMembership);
});
}
}).then(() => {
cy.botJoinRoomByName(this.bob, "Alice").as("bobsRoom");
});

cy.contains(".mx_TextualEvent", "Bob joined the room").should("exist");
};

const handleVerificationRequest = (request: VerificationRequest): Chainable<EmojiMapping[]> => {
return cy.wrap(new Promise<EmojiMapping[]>((resolve) => {
const onShowSas = (event: ISasEvent) => {
resolve(event.sas.emoji);
verifier.off("show_sas", onShowSas);
event.confirm();
verifier.done();
resolve(event.sas.emoji);
};

const verifier = request.beginKeyVerification("m.sas.v1");
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Cypress.Commands.add("botJoinRoomByName", (cli: MatrixClient, roomName: string):
return cy.botJoinRoom(cli, room.roomId);
}

return cy.wrap(Promise.reject());
return cy.wrap(Promise.reject(`Bot room join failed. Cannot find room '${roomName}'`));
});

Cypress.Commands.add("botSendMessage", (
Expand Down

0 comments on commit 1345825

Please sign in to comment.