From 07670a75ced314bed7242c73bb478e14be9587ca Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 1 Aug 2024 16:15:53 +0100 Subject: [PATCH] Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../structures/auth/Registration.tsx | 23 +- test/components/structures/UserMenu-test.tsx | 6 +- .../structures/auth/ForgotPassword-test.tsx | 2 +- .../views/dialogs/UserSettingsDialog-test.tsx | 6 +- .../views/messages/MPollEndBody-test.tsx | 5 +- .../polls/pollHistory/PollHistory-test.tsx | 3 +- .../RoomSummaryCard-test.tsx.snap | 1622 ++++++++--------- .../views/rooms/RoomPreviewBar-test.tsx | 16 +- .../settings/SetIntegrationManager-test.tsx | 4 +- .../AppearanceUserSettingsTab-test.tsx.snap | 32 +- test/languageHandler-test.tsx | 6 +- test/setupTests.ts | 6 + test/test-utils/client.ts | 1 + 13 files changed, 871 insertions(+), 861 deletions(-) diff --git a/src/components/structures/auth/Registration.tsx b/src/components/structures/auth/Registration.tsx index 5ac49537c5..ede5767745 100644 --- a/src/components/structures/auth/Registration.tsx +++ b/src/components/structures/auth/Registration.tsx @@ -248,15 +248,20 @@ export default class Registration extends React.Component { logger.error("Failed to get login flows to check for SSO support", e); } - this.setState(({ flows }) => ({ - matrixClient: cli, - ssoFlow, - oidcNativeFlow, - // if we are using oidc native we won't continue with flow discovery on HS - // so set an empty array to indicate flows are no longer loading - flows: oidcNativeFlow ? [] : flows, - busy: false, - })); + await new Promise((resolve) => { + this.setState( + ({ flows }) => ({ + matrixClient: cli, + ssoFlow, + oidcNativeFlow, + // if we are using oidc native we won't continue with flow discovery on HS + // so set an empty array to indicate flows are no longer loading + flows: oidcNativeFlow ? [] : flows, + busy: false, + }), + resolve, + ); + }); // don't need to check with homeserver for login flows // since we are going to use OIDC native flow diff --git a/test/components/structures/UserMenu-test.tsx b/test/components/structures/UserMenu-test.tsx index 24b75a87d1..6fea2453b0 100644 --- a/test/components/structures/UserMenu-test.tsx +++ b/test/components/structures/UserMenu-test.tsx @@ -128,7 +128,7 @@ describe("", () => { const spy = jest.spyOn(defaultDispatcher, "dispatch"); screen.getByRole("button", { name: /User menu/i }).click(); - screen.getByRole("menuitem", { name: /Sign out/i }).click(); + await waitFor(() => screen.getByRole("menuitem", { name: /Sign out/i }).click()); await waitFor(() => { expect(spy).toHaveBeenCalledWith({ action: "logout" }); }); @@ -152,7 +152,7 @@ describe("", () => { const spy = jest.spyOn(defaultDispatcher, "dispatch"); screen.getByRole("button", { name: /User menu/i }).click(); - screen.getByRole("menuitem", { name: /Sign out/i }).click(); + await waitFor(() => screen.getByRole("menuitem", { name: /Sign out/i }).click()); await waitFor(() => { expect(spy).toHaveBeenCalledWith({ action: "logout" }); }); @@ -178,7 +178,7 @@ describe("", () => { const spy = jest.spyOn(Modal, "createDialog"); screen.getByRole("button", { name: /User menu/i }).click(); - screen.getByRole("menuitem", { name: /Sign out/i }).click(); + await waitFor(() => screen.getByRole("menuitem", { name: /Sign out/i }).click()); await waitFor(() => { expect(spy).toHaveBeenCalledWith(LogoutDialog); diff --git a/test/components/structures/auth/ForgotPassword-test.tsx b/test/components/structures/auth/ForgotPassword-test.tsx index b43e6bea6a..de3558f349 100644 --- a/test/components/structures/auth/ForgotPassword-test.tsx +++ b/test/components/structures/auth/ForgotPassword-test.tsx @@ -16,7 +16,7 @@ limitations under the License. import React from "react"; import { mocked } from "jest-mock"; -import { act, render, RenderResult, screen } from "@testing-library/react"; +import { act, render, RenderResult, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { MatrixClient, createClient } from "matrix-js-sdk/src/matrix"; diff --git a/test/components/views/dialogs/UserSettingsDialog-test.tsx b/test/components/views/dialogs/UserSettingsDialog-test.tsx index f404b7f208..322b7cc944 100644 --- a/test/components/views/dialogs/UserSettingsDialog-test.tsx +++ b/test/components/views/dialogs/UserSettingsDialog-test.tsx @@ -15,7 +15,7 @@ limitations under the License. */ import React, { ReactElement } from "react"; -import { render, screen } from "@testing-library/react"; +import { render, screen, waitFor } from "@testing-library/react"; import { mocked, MockedObject } from "jest-mock"; import { MatrixClient } from "matrix-js-sdk/src/matrix"; @@ -238,7 +238,7 @@ describe("", () => { expect(getByTestId(`settings-tab-${UserTab.Labs}`)).toBeTruthy(); }); - it("watches settings", () => { + it("watches settings", async () => { const watchSettingCallbacks: Record = {}; mockSettingsStore.watchSetting.mockImplementation((settingName, roomId, callback) => { @@ -257,7 +257,7 @@ describe("", () => { watchSettingCallbacks["feature_mjolnir"]("feature_mjolnir", "", SettingLevel.ACCOUNT, true, true); // tab is rendered now - expect(queryByTestId(`settings-tab-${UserTab.Mjolnir}`)).toBeTruthy(); + await waitFor(() => expect(queryByTestId(`settings-tab-${UserTab.Mjolnir}`)).toBeTruthy()); unmount(); diff --git a/test/components/views/messages/MPollEndBody-test.tsx b/test/components/views/messages/MPollEndBody-test.tsx index f972e40bfd..2410e2e108 100644 --- a/test/components/views/messages/MPollEndBody-test.tsx +++ b/test/components/views/messages/MPollEndBody-test.tsx @@ -15,7 +15,7 @@ limitations under the License. */ import React from "react"; -import { render } from "@testing-library/react"; +import { render, waitForElementToBeRemoved } from "@testing-library/react"; import { EventTimeline, MatrixEvent, Room, M_TEXT } from "matrix-js-sdk/src/matrix"; import { logger } from "matrix-js-sdk/src/logger"; @@ -129,13 +129,14 @@ describe("", () => { describe("when poll start event does not exist in current timeline", () => { it("fetches the related poll start event and displays a poll tile", async () => { await setupRoomWithEventsTimeline(pollEndEvent); - const { container, getByTestId } = getComponent(); + const { container, getByTestId, queryByRole } = getComponent(); // while fetching event, only icon is shown expect(container).toMatchSnapshot(); // flush the fetch event promise await flushPromises(); + await waitForElementToBeRemoved(() => queryByRole("progressbar")); expect(mockClient.fetchRoomEvent).toHaveBeenCalledWith(roomId, pollStartEvent.getId()); diff --git a/test/components/views/polls/pollHistory/PollHistory-test.tsx b/test/components/views/polls/pollHistory/PollHistory-test.tsx index 2a5fc80168..632f58580f 100644 --- a/test/components/views/polls/pollHistory/PollHistory-test.tsx +++ b/test/components/views/polls/pollHistory/PollHistory-test.tsx @@ -24,6 +24,7 @@ import { getMockClientWithEventEmitter, makePollEndEvent, makePollStartEvent, + mockClientMethodsRooms, mockClientMethodsUser, mockIntlDateTimeFormat, setupRoomWithPollEvents, @@ -41,7 +42,7 @@ describe("", () => { const roomId = "!room:domain.org"; const mockClient = getMockClientWithEventEmitter({ ...mockClientMethodsUser(userId), - getRoom: jest.fn(), + ...mockClientMethodsRooms([]), relations: jest.fn(), decryptEventIfNeeded: jest.fn(), getOrCreateFilter: jest.fn(), diff --git a/test/components/views/right_panel/__snapshots__/RoomSummaryCard-test.tsx.snap b/test/components/views/right_panel/__snapshots__/RoomSummaryCard-test.tsx.snap index 1986c2c036..31502f1bb2 100644 --- a/test/components/views/right_panel/__snapshots__/RoomSummaryCard-test.tsx.snap +++ b/test/components/views/right_panel/__snapshots__/RoomSummaryCard-test.tsx.snap @@ -108,817 +108,6 @@ exports[` has button to edit topic 1`] = ` data-orientation="horizontal" role="separator" /> -
-
- - -
- -
-
-
- - - - -
-
-`; - -exports[` renders the room summary 1`] = ` -
-
-
-
-
- - ! - -

- !room:domain.org -

-
-
- -
- Not encrypted - -
-
- -
-
-