Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions test/unit-tests/components/structures/MatrixChat-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import { SetupEncryptionStore } from "../../../../src/stores/SetupEncryptionStor
import { ShareFormat } from "../../../../src/dispatcher/payloads/SharePayload.ts";
import { clearStorage } from "../../../../src/Lifecycle";
import RoomListStore from "../../../../src/stores/room-list/RoomListStore.ts";
import UserSettingsDialog from "../../../../src/components/views/dialogs/UserSettingsDialog.tsx";
import { SdkContextClass } from "../../../../src/contexts/SDKContext.ts";

jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
completeAuthorizationCodeGrant: jest.fn(),
Expand Down Expand Up @@ -268,6 +270,10 @@ describe("<MatrixChat />", () => {
// (must be sync otherwise the next test will start before it happens)
act(() => defaultDispatcher.dispatch({ action: Action.OnLoggedOut }, true));

// that will cause the Login to kick off an update in the background, which we need to allow to finish within
// an `act` to avoid warnings
await flushPromises();

localStorage.clear();
});

Expand Down Expand Up @@ -640,22 +646,29 @@ describe("<MatrixChat />", () => {
});

describe("onAction()", () => {
beforeEach(() => {
jest.spyOn(defaultDispatcher, "dispatch").mockClear();
jest.spyOn(defaultDispatcher, "fire").mockClear();
afterEach(() => {
jest.restoreAllMocks();
});
it("should open user device settings", async () => {

it("ViewUserDeviceSettings should open user device settings", async () => {
await getComponentAndWaitForReady();

defaultDispatcher.dispatch({
action: Action.ViewUserDeviceSettings,
});
const createDialog = jest.spyOn(Modal, "createDialog").mockReturnValue({} as any);

await flushPromises();
await act(async () => {
defaultDispatcher.dispatch({
action: Action.ViewUserDeviceSettings,
});

expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({
action: Action.ViewUserSettings,
initialTabId: UserTab.SessionManager,
await waitFor(() =>
expect(createDialog).toHaveBeenCalledWith(
UserSettingsDialog,
{ initialTabId: UserTab.SessionManager, sdkContext: expect.any(SdkContextClass) },
/*className=*/ undefined,
/*isPriority=*/ false,
/*isStatic=*/ true,
),
);
});
});

Expand All @@ -674,10 +687,6 @@ describe("<MatrixChat />", () => {
jest.spyOn(ReleaseAnnouncementStore.instance, "getReleaseAnnouncement").mockReturnValue(null);
});

afterEach(() => {
jest.restoreAllMocks();
});

describe("forget_room", () => {
it("should dispatch after_forget_room action on successful forget", async () => {
await clearAllModals();
Expand Down
Loading