Skip to content

Commit 7f27065

Browse files
committed
Return room-id from create-room action
1 parent fdc13ce commit 7f27065

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

cypress/e2e/trafficlight/actions/room.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,30 @@ limitations under the License.
1616

1717
/// <reference types='cypress' />
1818

19-
export function createRoom(name: string, topic: string): string {
20-
cy.get('.mx_RoomListHeader_plusButton').click();
19+
export async function createRoom(name: string, topic: string): Promise<string> {
20+
cy.get('.mx_RoomListHeader_plusButton').click({ force: true });
2121
cy.get('.mx_ContextualMenu').contains('New room').click();
2222
cy.get('.mx_CreateRoomDialog_name input').type(name);
2323
if (topic) {
2424
cy.get('.mx_CreateRoomDialog_topic input').type(topic);
2525
}
26-
// do this to prevent https://github.com/vector-im/element-web/issues/22590, weirdly
27-
// cy.get('.mx_CreateRoomDialog_name input').click();
28-
// cy.wait(5000);
29-
3026
cy.get('.mx_Dialog_primary').click();
31-
//cy.get('.mx_RoomHeader_nametext').should('contain', data['name']);
32-
return "room_created";
27+
return await getRoomIdFromName(name);
28+
}
29+
30+
function getRoomIdFromName(name: string): Promise<string> {
31+
let resolve;
32+
const promise: Promise<string> = new Promise(r => resolve = r);
33+
openRoom(name);
34+
cy.get(".mx_RightPanel_roomSummaryButton").click();
35+
cy.get(".mx_RoomSummaryCard_icon_settings").click();
36+
cy.get(`[data-testid='settings-tab-ROOM_ADVANCED_TAB']`).click();
37+
cy.get(".mx_CopyableText").invoke("text").then(roomId => {
38+
cy.get(".mx_Dialog_cancelButton").click();
39+
cy.get("[data-test-id=base-card-close-button]").click();
40+
resolve(roomId);
41+
});
42+
return promise;
3343
}
3444

3545
export function createDm(userId: string): string {

cypress/e2e/trafficlight/trafficlight.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function recurse() {
106106

107107
function sendResponse(responseStatus) {
108108
let data;
109-
if (typeof responseStatus == "string") {
109+
if (typeof responseStatus === "string") {
110110
data = { response: responseStatus };
111111
} else {
112112
data = responseStatus;
@@ -121,23 +121,25 @@ function recurse() {
121121
const data: JSONValue = resp.body.data;
122122
const action: string = resp.body.action;
123123
cy.log('running action', action, JSON.stringify(data));
124-
let result;
125124
try {
126-
result = runAction(action, data);
125+
cy.resolveFromPromise(runAction(action, data)).then(result => {
126+
if (result) {
127+
sendResponse(result);
128+
}
129+
});
127130
} catch (e) {
128131
// Don't keep running if we encounter an error!
129132
return;
130133
}
131-
if (result) {
132-
sendResponse(result);
133-
}
134134
if (action !== 'exit') {
135135
recurse();
136136
}
137137
});
138138
}
139139

140-
function runAction(action: string, data: JSONValue): string | JSONValue | undefined {
140+
type ActionResult = string | JSONValue | undefined;
141+
142+
function runAction(action: string, data: JSONValue): ActionResult | Promise<ActionResult> {
141143
switch (action) {
142144
// Auth
143145
case 'register':

cypress/support/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ Cypress.Commands.addAll({
2020
cy.get(".mx_UserMenu_userAvatar").click();
2121
cy.get(".mx_IconizedContextMenu_optionList").contains("All settings").click();
2222
},
23+
24+
// A very hacky way to use promises in Cypress
25+
async resolveFromPromise(p: any) {
26+
return await p;
27+
},
2328
});

types.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
21
/// <reference types="cypress" />
32

4-
// Add
53
declare global {
64
namespace Cypress {
75
interface Chainable {
86
/**
97
* Custom command to go to All Settings view in element web.
108
*/
11-
gotoAllSettings(): Chainable<Element>;
9+
gotoAllSettings(): Chainable<Element>;
10+
/**
11+
* A very hacky way to use promises in Cypress
12+
*/
13+
resolveFromPromise(p: any): Chainable<any>;
1214
}
1315
}
1416
}
1517

16-
export { };
18+
export {};

0 commit comments

Comments
 (0)