From 9aa09d4b15694328ceca175d98600293ad760883 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 23 Sep 2024 09:29:24 +0100 Subject: [PATCH] Maybe fix flakey AddRemoveThreepid test (#81) I have no idea why this is flaking. There are warnings about things not being wrapped in act() which may be relevant... this makes the warnings happy, although apparently should not be necessary. https://github.com/testing-library/user-event/discussions/906 and https://github.com/testing-library/user-event/issues/497 are depressing reading (making the versions the same didn't help). I think my conclusion might be to do this until we're able to upgrade to the latest testing-library, then re-evaluate. It still may or may not fix the flake. --- .../settings/AddRemoveThreepids-test.tsx | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/components/views/settings/AddRemoveThreepids-test.tsx b/test/components/views/settings/AddRemoveThreepids-test.tsx index ec56d9f03b..9cdfe4ec18 100644 --- a/test/components/views/settings/AddRemoveThreepids-test.tsx +++ b/test/components/views/settings/AddRemoveThreepids-test.tsx @@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ -import { render, screen } from "@testing-library/react"; +import { render, screen, waitFor } from "@testing-library/react"; import { MatrixClient, ThreepidMedium } from "matrix-js-sdk/src/matrix"; import React from "react"; import userEvent from "@testing-library/user-event"; @@ -218,7 +218,17 @@ describe("AddRemoveThreepids", () => { await userEvent.type(input, PHONE1_LOCALNUM); const addButton = screen.getByRole("button", { name: "Add" }); - await userEvent.click(addButton); + userEvent.click(addButton); + + const continueButton = await screen.findByRole("button", { name: "Continue" }); + + await expect(continueButton).toHaveAttribute("aria-disabled", "true"); + + await expect( + await screen.findByText( + `A text message has been sent to +${PHONE1.address}. Please enter the verification code it contains.`, + ), + ).toBeInTheDocument(); expect(client.requestAdd3pidMsisdnToken).toHaveBeenCalledWith( "GB", @@ -226,15 +236,14 @@ describe("AddRemoveThreepids", () => { client.generateClientSecret(), 1, ); - const continueButton = screen.getByRole("button", { name: "Continue" }); - - expect(continueButton).toHaveAttribute("aria-disabled", "true"); const verificationInput = screen.getByRole("textbox", { name: "Verification code" }); await userEvent.type(verificationInput, "123456"); expect(continueButton).not.toHaveAttribute("aria-disabled", "true"); - await userEvent.click(continueButton); + userEvent.click(continueButton); + + await waitFor(() => expect(continueButton).toHaveAttribute("aria-disabled", "true")); expect(client.addThreePidOnly).toHaveBeenCalledWith({ client_secret: client.generateClientSecret(),