Skip to content

Commit

Permalink
Fix broken jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MidhunSureshR committed Dec 16, 2024
1 parent 83265ff commit e78f6ba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
4 changes: 2 additions & 2 deletions test/unit-tests/components/structures/RightPanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe("RightPanel", () => {
await waitFor(() => expect(screen.queryByTestId("spinner")).not.toBeInTheDocument());

// room one will be in the MemberList phase - confirm this is rendered
expect(container.getElementsByClassName("mx_MemberList")).toHaveLength(1);
expect(container.getElementsByClassName("mx_MemberListView")).toHaveLength(1);

// wait for RPS room 2 updates to fire, then rerender
const _rpsUpdated = waitForRpsUpdate();
Expand All @@ -146,7 +146,7 @@ describe("RightPanel", () => {
// the correct right panel state for whichever room we are showing, so we
// confirm we do not have the MemberList class on the page and that we have
// the expected room title
expect(container.getElementsByClassName("mx_MemberList")).toHaveLength(0);
expect(container.getElementsByClassName("mx_MemberListView")).toHaveLength(0);
expect(screen.getByRole("heading", { name: "r2" })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ exports[`RoomView video rooms should render joined video room view 1`] = `
</div>
<div
class="mx_RightPanel_ResizeWrapper"
style="position: relative; user-select: auto; width: 420px; height: 100%; max-width: 50%; min-width: 264px; box-sizing: border-box; flex-shrink: 0;"
style="position: relative; user-select: auto; width: 420px; height: 100%; max-width: 50%; min-width: 320px; box-sizing: border-box; flex-shrink: 0;"
>
<aside
class="mx_RightPanel"
Expand Down
76 changes: 37 additions & 39 deletions test/unit-tests/components/views/rooms/MemberListView-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe("MemberListView and MemberlistHeaderView", () => {
}
}

function renderMemberList(enablePresence: boolean, usersPerLevel: number = 2): void {
async function renderMemberList(enablePresence: boolean, usersPerLevel: number = 2): Promise<void> {
TestUtils.stubClient();
client = MatrixClientPeg.safeGet();
client.hasLazyLoadMembersEnabled = () => false;
Expand Down Expand Up @@ -231,6 +231,9 @@ describe("MemberListView and MemberlistHeaderView", () => {
</SDKContext.Provider>
</MatrixClientContext.Provider>,
);
await waitFor(async () => {
expect(root.container.querySelectorAll(".mx_MemberTileView")).toHaveLength(usersPerLevel * 3);
});
}

async function reRenderMemberList(): Promise<void> {
Expand All @@ -246,13 +249,8 @@ describe("MemberListView and MemberlistHeaderView", () => {
}

describe("MemberListView", () => {
beforeEach(function () {
renderMemberList(true);
});

it("Renders correctly", async () => {
// Should have rendered 6 members
expect(root.container.querySelectorAll(".mx_MemberTileView")).toHaveLength(6);
beforeEach(async function () {
await renderMemberList(true);
});

it("Memberlist is re-rendered on unreachable presence event", async () => {
Expand All @@ -275,8 +273,8 @@ describe("MemberListView and MemberlistHeaderView", () => {
});

describe.each([true, false])("does order members correctly (presence %s)", (enablePresence) => {
beforeEach(function () {
renderMemberList(enablePresence);
beforeEach(async function () {
await renderMemberList(enablePresence);
});

describe("does order members correctly", () => {
Expand Down Expand Up @@ -368,8 +366,8 @@ describe("MemberListView and MemberlistHeaderView", () => {
});

describe("MemberListHeaderView", () => {
beforeEach(function () {
renderMemberList(true);
beforeEach(async function () {
await renderMemberList(true);
});

it("Shows the correct member count", async () => {
Expand Down Expand Up @@ -404,35 +402,35 @@ describe("MemberListView and MemberlistHeaderView", () => {

it("Does not render invite button when user is not a member", async () => {});

it("does not render invite button UI customisation hides invites", async () => {
it("Renders disabled invite button when current user is a member but does not have rights to invite", async () => {
jest.spyOn(memberListRoom, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(memberListRoom, "canInvite").mockReturnValue(false);
mocked(shouldShowComponent).mockReturnValue(true);
await reRenderMemberList();
expect(screen.getByRole("button", { name: "Invite" })).toHaveAttribute("aria-disabled", "true");
});
it("does not render invite button UI customisation hides invites", async () => {});

it("Renders enabled invite button when current user is a member and has rights to invite", async () => {
jest.spyOn(memberListRoom, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(memberListRoom, "canInvite").mockReturnValue(true);
mocked(shouldShowComponent).mockReturnValue(true);
await reRenderMemberList();
expect(screen.getByRole("button", { name: "Invite" })).not.toHaveAttribute("aria-disabled", "true");
});
it("Renders disabled invite button when current user is a member but does not have rights to invite", async () => {
jest.spyOn(memberListRoom, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(memberListRoom, "canInvite").mockReturnValue(false);
mocked(shouldShowComponent).mockReturnValue(true);
await reRenderMemberList();
expect(screen.getByRole("button", { name: "Invite" })).toHaveAttribute("aria-disabled", "true");
});

it("Renders enabled invite button when current user is a member and has rights to invite", async () => {
jest.spyOn(memberListRoom, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(memberListRoom, "canInvite").mockReturnValue(true);
mocked(shouldShowComponent).mockReturnValue(true);
await reRenderMemberList();
expect(screen.getByRole("button", { name: "Invite" })).not.toHaveAttribute("aria-disabled", "true");
});

it("Opens room inviter on button click", async () => {
jest.spyOn(defaultDispatcher, "dispatch");
jest.spyOn(memberListRoom, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(memberListRoom, "canInvite").mockReturnValue(true);
mocked(shouldShowComponent).mockReturnValue(true);
await reRenderMemberList();

it("Opens room inviter on button click", async () => {
jest.spyOn(defaultDispatcher, "dispatch");
jest.spyOn(memberListRoom, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(memberListRoom, "canInvite").mockReturnValue(true);
mocked(shouldShowComponent).mockReturnValue(true);
await reRenderMemberList();

fireEvent.click(screen.getByRole("button", { name: "Invite" }));
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({
action: "view_invite",
roomId: memberListRoom.roomId,
});
fireEvent.click(screen.getByRole("button", { name: "Invite" }));
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({
action: "view_invite",
roomId: memberListRoom.roomId,
});
});
});
Expand Down

0 comments on commit e78f6ba

Please sign in to comment.