Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
t3chguy committed Dec 2, 2024
1 parent 351774d commit 2099aaa
Showing 3 changed files with 139 additions and 6 deletions.
16 changes: 16 additions & 0 deletions test/unit-tests/components/structures/RoomView-test.tsx
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@ import { ViewRoomErrorPayload } from "../../../../src/dispatcher/payloads/ViewRo
import { SearchScope } from "../../../../src/Searching";
import { MEGOLM_ENCRYPTION_ALGORITHM } from "../../../../src/utils/crypto";
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
import { ViewUserPayload } from "../../../../src/dispatcher/payloads/ViewUserPayload.ts";

describe("RoomView", () => {
let cli: MockedObject<MatrixClient>;
@@ -202,6 +203,21 @@ describe("RoomView", () => {
return ref.current!;
};

it("should show member list right panel phase on Action.ViewUser without `payload.member`", async () => {
const spy = jest.spyOn(stores.rightPanelStore, "showOrHidePhase");
await renderRoomView(false);

defaultDispatcher.dispatch<ViewUserPayload>(
{
action: Action.ViewUser,
member: undefined,
},
true,
);

expect(spy).toHaveBeenCalledWith(RightPanelPhases.MemberList);
});

it("when there is no room predecessor, getHiddenHighlightCount should return 0", async () => {
const instance = await getRoomViewInstance();
expect(instance.getHiddenHighlightCount()).toBe(0);
117 changes: 117 additions & 0 deletions test/unit-tests/components/structures/SpaceRoomView-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
Copyright 2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/

import React from "react";
import { mocked, MockedObject } from "jest-mock";
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import { render, cleanup, screen, fireEvent } from "jest-matrix-react";

import { stubClient, mockPlatformPeg, unmockPlatformPeg, withClientContextRenderOptions } from "../../../test-utils";
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
import SpaceRoomView from "../../../../src/components/structures/SpaceRoomView.tsx";
import ResizeNotifier from "../../../../src/utils/ResizeNotifier.ts";
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks.ts";
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore.ts";
import DMRoomMap from "../../../../src/utils/DMRoomMap.ts";

describe("SpaceRoomView", () => {
let cli: MockedObject<MatrixClient>;
let space: Room;

beforeEach(() => {
mockPlatformPeg({ reload: () => {} });
cli = mocked(stubClient());

space = new Room(`!space:example.org`, cli, cli.getSafeUserId());
space.currentState.setStateEvents([
new MatrixEvent({
type: "m.room.create",
room_id: space.roomId,
sender: cli.getSafeUserId(),
state_key: "",
content: {
creator: cli.getSafeUserId(),
type: "m.space",
},
}),
new MatrixEvent({
type: "m.room.member",
room_id: space.roomId,
sender: cli.getSafeUserId(),
state_key: cli.getSafeUserId(),
content: {
membership: "join",
},
}),
new MatrixEvent({
type: "m.room.member",
room_id: space.roomId,
sender: "@userA:server",
state_key: "@userA:server",
content: {
membership: "join",
},
}),
new MatrixEvent({
type: "m.room.member",
room_id: space.roomId,
sender: "@userB:server",
state_key: "@userB:server",
content: {
membership: "join",
},
}),
new MatrixEvent({
type: "m.room.member",
room_id: space.roomId,
sender: "@userC:server",
state_key: "@userC:server",
content: {
membership: "join",
},
}),
]);
space.updateMyMembership("join");

DMRoomMap.makeShared(cli);
});

afterEach(() => {
unmockPlatformPeg();
jest.clearAllMocks();
cleanup();
});

const renderSpaceRoomView = async (): Promise<ReturnType<typeof render>> => {
const resizeNotifier = new ResizeNotifier();
const permalinkCreator = new RoomPermalinkCreator(space);

const spaceRoomView = render(
<SpaceRoomView
space={space}
resizeNotifier={resizeNotifier}
permalinkCreator={permalinkCreator}
onJoinButtonClicked={jest.fn()}
onRejectButtonClicked={jest.fn()}
/>,
withClientContextRenderOptions(cli),
);
return spaceRoomView;
};

describe("SpaceLanding", () => {
it("should show member list right panel phase on members click on landing", async () => {
const spy = jest.spyOn(RightPanelStore.instance, "setCard");
const { container } = await renderSpaceRoomView();

await expect(screen.findByText("Welcome to")).resolves.toBeVisible();
fireEvent.click(container.querySelector(".mx_FacePile")!);

expect(spy).toHaveBeenCalledWith({ phase: RightPanelPhases.MemberList });
});
});
});
Original file line number Diff line number Diff line change
@@ -1302,7 +1302,7 @@ exports[`RoomView should not display the timeline when the room encryption is lo
aria-label="Open room settings"
aria-live="off"
class="_avatar_mcap2_17 mx_BaseAvatar _avatar-imageless_mcap2_61"
data-color="1"
data-color="2"
data-testid="avatar-img"
data-type="round"
role="button"
@@ -1329,7 +1329,7 @@ exports[`RoomView should not display the timeline when the room encryption is lo
<span
class="mx_RoomHeader_truncated mx_lineClamp"
>
!5:example.org
!6:example.org
</span>
</div>
</div>
@@ -1513,7 +1513,7 @@ exports[`RoomView should not display the timeline when the room encryption is lo
aria-label="Open room settings"
aria-live="off"
class="_avatar_mcap2_17 mx_BaseAvatar _avatar-imageless_mcap2_61"
data-color="1"
data-color="2"
data-testid="avatar-img"
data-type="round"
role="button"
@@ -1540,7 +1540,7 @@ exports[`RoomView should not display the timeline when the room encryption is lo
<span
class="mx_RoomHeader_truncated mx_lineClamp"
>
!5:example.org
!6:example.org
</span>
</div>
</div>
@@ -1897,7 +1897,7 @@ exports[`RoomView video rooms should render joined video room view 1`] = `
aria-label="Open room settings"
aria-live="off"
class="_avatar_mcap2_17 mx_BaseAvatar _avatar-imageless_mcap2_61"
data-color="5"
data-color="6"
data-testid="avatar-img"
data-type="round"
role="button"
@@ -1924,7 +1924,7 @@ exports[`RoomView video rooms should render joined video room view 1`] = `
<span
class="mx_RoomHeader_truncated mx_lineClamp"
>
!12:example.org
!13:example.org
</span>
</div>
</div>

0 comments on commit 2099aaa

Please sign in to comment.