Make tests more resilient for React 18 upgrade (#12861)
* Make tests more resilient for React 18 upgrade Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
4e4c5c7768
commit
8285283cc3
35 changed files with 313 additions and 290 deletions
|
@ -129,11 +129,11 @@ describe("AccessSecretStorageDialog", () => {
|
|||
expect(screen.getByPlaceholderText("Security Phrase")).toHaveValue(securityKey);
|
||||
await submitDialog();
|
||||
|
||||
expect(
|
||||
screen.getByText(
|
||||
await expect(
|
||||
screen.findByText(
|
||||
"👎 Unable to access secret storage. Please verify that you entered the correct Security Phrase.",
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
).resolves.toBeInTheDocument();
|
||||
|
||||
expect(screen.getByPlaceholderText("Security Phrase")).toHaveFocus();
|
||||
});
|
||||
|
|
|
@ -429,7 +429,7 @@ describe("InviteDialog", () => {
|
|||
|
||||
describe("when clicking »Start DM anyway«", () => {
|
||||
beforeEach(async () => {
|
||||
await userEvent.click(screen.getByRole("button", { name: "Start DM anyway", exact: true }));
|
||||
await userEvent.click(screen.getByRole("button", { name: "Start DM anyway" }));
|
||||
});
|
||||
|
||||
it("should start the DM", () => {
|
||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from "react";
|
||||
import { render, RenderResult } from "@testing-library/react";
|
||||
import { render, RenderResult, waitForElementToBeRemoved } from "@testing-library/react";
|
||||
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
@ -39,6 +39,7 @@ describe("<MessageEditHistory />", () => {
|
|||
|
||||
async function renderComponent(): Promise<RenderResult> {
|
||||
const result = render(<MessageEditHistoryDialog mxEvent={event} onFinished={jest.fn()} />);
|
||||
await waitForElementToBeRemoved(() => result.queryByRole("progressbar"));
|
||||
await flushPromises();
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from "react";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import {
|
||||
EventTimeline,
|
||||
EventType,
|
||||
|
@ -129,7 +129,7 @@ describe("<RoomSettingsDialog />", () => {
|
|||
expect(screen.getByTestId("settings-tab-ROOM_PEOPLE_TAB")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("re-renders on room join rule changes", () => {
|
||||
it("re-renders on room join rule changes", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
||||
(setting) => setting === "feature_ask_to_join",
|
||||
);
|
||||
|
@ -142,7 +142,9 @@ describe("<RoomSettingsDialog />", () => {
|
|||
room.getLiveTimeline().getState(EventTimeline.FORWARDS)!,
|
||||
null,
|
||||
);
|
||||
expect(screen.queryByTestId("settings-tab-ROOM_PEOPLE_TAB")).not.toBeInTheDocument();
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByTestId("settings-tab-ROOM_PEOPLE_TAB")).not.toBeInTheDocument(),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -57,14 +57,9 @@ jest.mock("../../../../src/settings/SettingsStore", () => ({
|
|||
settingIsOveriddenAtConfigLevel: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock("../../../../src/SdkConfig", () => ({
|
||||
get: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("<UserSettingsDialog />", () => {
|
||||
const userId = "@alice:server.org";
|
||||
const mockSettingsStore = mocked(SettingsStore);
|
||||
const mockSdkConfig = mocked(SdkConfig);
|
||||
let mockClient!: MockedObject<MatrixClient>;
|
||||
|
||||
let sdkContext: SdkContextClass;
|
||||
|
@ -89,7 +84,8 @@ describe("<UserSettingsDialog />", () => {
|
|||
mockSettingsStore.getValue.mockReturnValue(false);
|
||||
mockSettingsStore.getValueAt.mockReturnValue(false);
|
||||
mockSettingsStore.getFeatureSettingNames.mockReturnValue([]);
|
||||
mockSdkConfig.get.mockReturnValue({ brand: "Test" });
|
||||
SdkConfig.reset();
|
||||
SdkConfig.put({ brand: "Test" });
|
||||
});
|
||||
|
||||
const getActiveTabLabel = (container: Element) =>
|
||||
|
@ -115,6 +111,9 @@ describe("<UserSettingsDialog />", () => {
|
|||
});
|
||||
|
||||
it("renders tabs correctly", () => {
|
||||
SdkConfig.add({
|
||||
show_labs_settings: true,
|
||||
});
|
||||
const { container } = render(getComponent());
|
||||
expect(container.querySelectorAll(".mx_TabbedView_tabLabel")).toMatchSnapshot();
|
||||
});
|
||||
|
@ -181,7 +180,7 @@ describe("<UserSettingsDialog />", () => {
|
|||
expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Settings: Voice & Video");
|
||||
});
|
||||
|
||||
it("renders with secutity tab selected", () => {
|
||||
it("renders with security tab selected", () => {
|
||||
const { container } = render(getComponent({ initialTabId: UserTab.Security }));
|
||||
|
||||
expect(getActiveTabLabel(container)).toEqual("Security & Privacy");
|
||||
|
@ -189,18 +188,8 @@ describe("<UserSettingsDialog />", () => {
|
|||
});
|
||||
|
||||
it("renders with labs tab selected", () => {
|
||||
// @ts-ignore I give up trying to get the types right here
|
||||
// why do we have functions that return different things depending on what they're passed?
|
||||
mockSdkConfig.get.mockImplementation((x) => {
|
||||
const mockConfig = { show_labs_settings: true, brand: "Test" };
|
||||
switch (x) {
|
||||
case "show_labs_settings":
|
||||
case "brand":
|
||||
// @ts-ignore
|
||||
return mockConfig[x];
|
||||
default:
|
||||
return mockConfig;
|
||||
}
|
||||
SdkConfig.add({
|
||||
show_labs_settings: true,
|
||||
});
|
||||
const { container } = render(getComponent({ initialTabId: UserTab.Labs }));
|
||||
|
||||
|
@ -223,8 +212,9 @@ describe("<UserSettingsDialog />", () => {
|
|||
});
|
||||
|
||||
it("renders labs tab when show_labs_settings is enabled in config", () => {
|
||||
// @ts-ignore simplified test stub
|
||||
mockSdkConfig.get.mockImplementation((configName) => configName === "show_labs_settings");
|
||||
SdkConfig.add({
|
||||
show_labs_settings: true,
|
||||
});
|
||||
const { getByTestId } = render(getComponent());
|
||||
expect(getByTestId(`settings-tab-${UserTab.Labs}`)).toBeTruthy();
|
||||
});
|
||||
|
@ -238,7 +228,7 @@ describe("<UserSettingsDialog />", () => {
|
|||
expect(getByTestId(`settings-tab-${UserTab.Labs}`)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("watches settings", () => {
|
||||
it("watches settings", async () => {
|
||||
const watchSettingCallbacks: Record<string, CallbackFn> = {};
|
||||
|
||||
mockSettingsStore.watchSetting.mockImplementation((settingName, roomId, callback) => {
|
||||
|
@ -247,7 +237,7 @@ describe("<UserSettingsDialog />", () => {
|
|||
});
|
||||
mockSettingsStore.getValue.mockReturnValue(false);
|
||||
|
||||
const { queryByTestId, unmount } = render(getComponent());
|
||||
const { queryByTestId, findByTestId, unmount } = render(getComponent());
|
||||
expect(queryByTestId(`settings-tab-${UserTab.Mjolnir}`)).toBeFalsy();
|
||||
|
||||
expect(mockSettingsStore.watchSetting).toHaveBeenCalledWith("feature_mjolnir", null, expect.anything());
|
||||
|
@ -257,7 +247,7 @@ describe("<UserSettingsDialog />", () => {
|
|||
watchSettingCallbacks["feature_mjolnir"]("feature_mjolnir", "", SettingLevel.ACCOUNT, true, true);
|
||||
|
||||
// tab is rendered now
|
||||
expect(queryByTestId(`settings-tab-${UserTab.Mjolnir}`)).toBeTruthy();
|
||||
await expect(findByTestId(`settings-tab-${UserTab.Mjolnir}`)).resolves.toBeTruthy();
|
||||
|
||||
unmount();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue