diff --git a/cypress/e2e/trafficlight/actions/room.ts b/cypress/e2e/trafficlight/actions/room.ts index e45b58e..7e4712d 100644 --- a/cypress/e2e/trafficlight/actions/room.ts +++ b/cypress/e2e/trafficlight/actions/room.ts @@ -16,20 +16,31 @@ limitations under the License. /// -export function createRoom(name: string, topic: string): string { - cy.get('.mx_RoomListHeader_plusButton').click(); +export async function createRoom(name: string, topic: string): Promise<{roomId: string}> { + cy.get('.mx_RoomListHeader_plusButton').click({ force: true }); cy.get('.mx_ContextualMenu').contains('New room').click(); cy.get('.mx_CreateRoomDialog_name input').type(name); if (topic) { cy.get('.mx_CreateRoomDialog_topic input').type(topic); } - // do this to prevent https://github.com/vector-im/element-web/issues/22590, weirdly - // cy.get('.mx_CreateRoomDialog_name input').click(); - // cy.wait(5000); - cy.get('.mx_Dialog_primary').click(); - //cy.get('.mx_RoomHeader_nametext').should('contain', data['name']); - return "room_created"; + const roomId = await getRoomIdFromName(name); + return { roomId }; +} + +function getRoomIdFromName(name: string): Promise { + let resolve; + const promise: Promise = new Promise(r => resolve = r); + openRoom(name); + cy.get(".mx_RightPanel_roomSummaryButton").click(); + cy.get(".mx_RoomSummaryCard_icon_settings").click(); + cy.get(`[data-testid='settings-tab-ROOM_ADVANCED_TAB']`).click(); + cy.get(".mx_CopyableText").invoke("text").then(roomId => { + cy.get(".mx_Dialog_cancelButton").click(); + cy.get("[data-test-id=base-card-close-button]").click(); + resolve(roomId); + }); + return promise; } export function createDm(userId: string): string { diff --git a/cypress/e2e/trafficlight/actions/timeline.ts b/cypress/e2e/trafficlight/actions/timeline.ts index f5f564c..4d0093b 100644 --- a/cypress/e2e/trafficlight/actions/timeline.ts +++ b/cypress/e2e/trafficlight/actions/timeline.ts @@ -47,11 +47,11 @@ export function verifyLastMessageIsTrusted(): string { return "verified"; } -export function getTimeline(): JSONValue { - const rsp = []; +export function getTimeline(): Record { + const rsp: any = []; Cypress.$('.mx_EventTile').each( function(index, obj) { - tile = {}; + const tile = {}; tile['user'] = Cypress.$(obj).find('.mx_BaseAvatar_image').attr('title'); const e2eicon = Cypress.$(obj).find('.mx_EventTile_e2eIcon').attr('class'); tile['e2e_issues'] = e2eicon; diff --git a/cypress/e2e/trafficlight/trafficlight.spec.ts b/cypress/e2e/trafficlight/trafficlight.spec.ts index f71f9ba..50977eb 100644 --- a/cypress/e2e/trafficlight/trafficlight.spec.ts +++ b/cypress/e2e/trafficlight/trafficlight.spec.ts @@ -106,7 +106,7 @@ function recurse() { function sendResponse(responseStatus) { let data; - if (typeof responseStatus == "string") { + if (typeof responseStatus === "string") { data = { response: responseStatus }; } else { data = responseStatus; @@ -121,23 +121,25 @@ function recurse() { const data: JSONValue = resp.body.data; const action: string = resp.body.action; cy.log('running action', action, JSON.stringify(data)); - let result; try { - result = runAction(action, data); + cy.resolveFromPromise(runAction(action, data)).then(result => { + if (result) { + sendResponse(result); + } + }); } catch (e) { // Don't keep running if we encounter an error! return; } - if (result) { - sendResponse(result); - } if (action !== 'exit') { recurse(); } }); } -function runAction(action: string, data: JSONValue): string | JSONValue | undefined { +type ActionResult = string | JSONValue | undefined; + +function runAction(action: string, data: JSONValue): ActionResult | Promise { switch (action) { // Auth case 'register': diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 73c9370..51ef3d0 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -20,4 +20,9 @@ Cypress.Commands.addAll({ cy.get(".mx_UserMenu_userAvatar").click(); cy.get(".mx_IconizedContextMenu_optionList").contains("All settings").click(); }, + + // A very hacky way to use promises in Cypress + async resolveFromPromise(p: any) { + return await p; + }, }); diff --git a/types.d.ts b/types.d.ts index 1835dfd..3eee9c8 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,16 +1,18 @@ - /// -// Add declare global { namespace Cypress { interface Chainable { /** * Custom command to go to All Settings view in element web. */ - gotoAllSettings(): Chainable; + gotoAllSettings(): Chainable; + /** + * A very hacky way to use promises in Cypress + */ + resolveFromPromise(p: any): Chainable; } } } -export { }; \ No newline at end of file +export {};