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

Commit 1345825

Browse files
author
Kerry
authored
Cypress - stabilise "creating a DM should work" test (#9373)
* 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
1 parent 7fd2fb9 commit 1345825

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

cypress/e2e/crypto/crypto.spec.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
18+
1719
import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
1820
import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
19-
import type { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
2021
import { SynapseInstance } from "../../plugins/synapsedocker";
2122
import Chainable = Cypress.Chainable;
2223

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

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

7575
const bobJoin = function(this: CryptoTestContext) {
76-
cy.botJoinRoomByName(this.bob, "Alice").as("bobsRoom");
76+
cy.window({ log: false }).then(async win => {
77+
const bobRooms = this.bob.getRooms();
78+
if (!bobRooms.length) {
79+
await new Promise<void>(resolve => {
80+
const onMembership = (_event) => {
81+
this.bob.off(win.matrixcs.RoomMemberEvent.Membership, onMembership);
82+
resolve();
83+
};
84+
this.bob.on(win.matrixcs.RoomMemberEvent.Membership, onMembership);
85+
});
86+
}
87+
}).then(() => {
88+
cy.botJoinRoomByName(this.bob, "Alice").as("bobsRoom");
89+
});
90+
7791
cy.contains(".mx_TextualEvent", "Bob joined the room").should("exist");
7892
};
7993

8094
const handleVerificationRequest = (request: VerificationRequest): Chainable<EmojiMapping[]> => {
8195
return cy.wrap(new Promise<EmojiMapping[]>((resolve) => {
8296
const onShowSas = (event: ISasEvent) => {
83-
resolve(event.sas.emoji);
8497
verifier.off("show_sas", onShowSas);
8598
event.confirm();
8699
verifier.done();
100+
resolve(event.sas.emoji);
87101
};
88102

89103
const verifier = request.beginKeyVerification("m.sas.v1");

cypress/support/bot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Cypress.Commands.add("botJoinRoomByName", (cli: MatrixClient, roomName: string):
128128
return cy.botJoinRoom(cli, room.roomId);
129129
}
130130

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

134134
Cypress.Commands.add("botSendMessage", (

0 commit comments

Comments
 (0)