Fix broken jest tests
This commit is contained in:
@@ -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();
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
@@ -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> {
|
||||
@@ -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 () => {
|
||||
@@ -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", () => {
|
||||
@@ -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 () => {
|
||||
@@ -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("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("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");
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Invite" }));
|
||||
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({
|
||||
action: "view_invite",
|
||||
roomId: memberListRoom.roomId,
|
||||
});
|
||||
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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user