From 4ed6e39067955f2430f8506086127cb9486f1f9a Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Mon, 3 Apr 2023 13:06:58 +0900 Subject: [PATCH] Use Cypress Testing Library - editing.spec.ts (#10480) Signed-off-by: Suguru Hirahara --- cypress/e2e/editing/editing.spec.ts | 30 +++++++++-------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/cypress/e2e/editing/editing.spec.ts b/cypress/e2e/editing/editing.spec.ts index 76d4c8da1b..8210536efc 100644 --- a/cypress/e2e/editing/editing.spec.ts +++ b/cypress/e2e/editing/editing.spec.ts @@ -46,12 +46,7 @@ describe("Editing", () => { // Edit "Message" const editLastMessage = (edit: string) => { - cy.get(".mx_EventTile_last").realHover(); - cy.get(".mx_EventTile_last .mx_MessageActionBar_optionsButton", { timeout: 1000 }) - .should("exist") - .realHover() - .get('.mx_EventTile_last [aria-label="Edit"]') - .click({ force: false }); + cy.get(".mx_EventTile_last").realHover().findButton("Edit").click(); cy.get(".mx_BasicMessageComposer_input").type(`{selectAll}{del}${edit}{enter}`); }; @@ -67,11 +62,7 @@ describe("Editing", () => { const clickButtonViewSource = () => { // Assert that "View Source" button is rendered and click it - cy.get(".mx_EventTile .mx_EventTile_line") - .realHover() - .contains(".mx_AccessibleButton", "View Source") - .should("exist") - .click(); + cy.get(".mx_EventTile .mx_EventTile_line").realHover().findButton("View Source").click(); }; beforeEach(() => { @@ -93,7 +84,7 @@ describe("Editing", () => { it("should render and interact with the message edit history dialog", () => { // Click the "Remove" button on the message edit history dialog const clickButtonRemove = () => { - cy.get(".mx_EventTile_line").realHover().contains(".mx_AccessibleButton", "Remove").click({ force: false }); + cy.get(".mx_EventTile_line").realHover().findButton("Remove").click(); }; cy.visit("/#/room/" + roomId); @@ -250,10 +241,7 @@ describe("Editing", () => { // Assert that the edited message is rendered cy.get(".mx_MessageEditHistoryDialog li:nth-child(2)").within(() => { // Assert that "Remove" button for the original message is rendered - cy.get(".mx_EventTile .mx_EventTile_line") - .realHover() - .contains(".mx_AccessibleButton", "Remove") - .should("exist"); + cy.get(".mx_EventTile .mx_EventTile_line").realHover().findButton("Remove"); clickButtonViewSource(); }); @@ -283,11 +271,11 @@ describe("Editing", () => { sendEvent(roomId); // Edit message - cy.contains(".mx_RoomView_body .mx_EventTile .mx_EventTile_line", "Message").within(() => { - cy.get('[aria-label="Edit"]').click({ force: true }); // Cypress has no ability to hover - cy.checkA11y(); - cy.get(".mx_BasicMessageComposer_input").type("Foo{backspace}{backspace}{backspace}{enter}"); - cy.checkA11y(); + cy.contains(".mx_RoomView_body .mx_EventTile", "Message").within(() => { + cy.get(".mx_EventTile_line").realHover().findButton("Edit").click().checkA11y(); + cy.get(".mx_EventTile_line .mx_BasicMessageComposer_input") + .type("Foo{backspace}{backspace}{backspace}{enter}") + .checkA11y(); }); cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Message");