Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add, update and remove tests/screenshots/snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
MidhunSureshR committed Jul 8, 2024
1 parent 384723a commit a8ead86
Show file tree
Hide file tree
Showing 20 changed files with 259 additions and 196 deletions.
4 changes: 2 additions & 2 deletions playwright/e2e/crypto/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const verify = async (page: Page, bob: Bot) => {
const bobsVerificationRequestPromise = waitForVerificationRequest(bob);

const roomInfo = await openRoomInfo(page);
await roomInfo.getByRole("menuitem", { name: "People" }).click();
await page.locator(".mx_RightPanelTabs").getByText("People").click();
await roomInfo.getByText("Bob").click();
await roomInfo.getByRole("button", { name: "Verify" }).click();
await roomInfo.getByRole("button", { name: "Start Verification" }).click();
Expand Down Expand Up @@ -279,7 +279,7 @@ test.describe("Cryptography", function () {

// Assert that verified icon is rendered
await page.getByRole("button", { name: "Room members" }).click();
await page.getByRole("button", { name: "Room information" }).click();
await page.locator(".mx_RightPanelTabs").getByText("Info").click();
await expect(page.locator('.mx_RoomSummaryCard_badges [data-kind="success"]')).toContainText("Encrypted");

// Take a snapshot of RoomSummaryCard with a verified E2EE icon
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/crypto/dehydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test.describe("Dehydration", () => {

await viewRoomSummaryByName(page, app, ROOM_NAME);

await page.getByRole("menuitem", { name: "People" }).click();
await page.locator(".mx_RightPanelTabs").getByText("People").click();
await expect(page.locator(".mx_MemberList")).toBeVisible();

await getMemberTileByName(page, NAME).click();
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/lazy-loading/lazy-loading.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test.describe("Lazy Loading", () => {

async function openMemberlist(page: Page): Promise<void> {
await page.locator(".mx_LegacyRoomHeader").getByRole("button", { name: "Room info" }).click();
await page.locator(".mx_RoomSummaryCard").getByRole("menuitem", { name: "People" }).click(); // \d represents the number of the room members
await page.locator(".mx_RightPanelTabs").getByText("People").click();
}

function getMemberInMemberlist(page: Page, name: string): Locator {
Expand Down
7 changes: 3 additions & 4 deletions playwright/e2e/read-receipts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,19 +399,18 @@ class Helpers {
}

/**
* Close the threads panel. (Actually, close any right panel, but for these
* tests we only open the threads panel.)
* Close the threads panel.
*/
async closeThreadsPanel() {
await this.page.locator(".mx_RightPanel").getByLabel("Close").click();
await this.page.locator(".mx_LegacyRoomHeader").getByLabel("Threads").click();
await expect(this.page.locator(".mx_RightPanel")).not.toBeVisible();
}

/**
* Return to the list of threads, given we are viewing a single thread.
*/
async backToThreadsList() {
await this.page.locator(".mx_RightPanel").getByLabel("Threads").click();
await this.page.locator(".mx_LegacyRoomHeader").getByLabel("Threads").click();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/right-panel/right-panel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ test.describe("RightPanel", () => {
test("should handle viewing room member", async ({ page, app }) => {
await viewRoomSummaryByName(page, app, ROOM_NAME);

await page.getByRole("menuitem", { name: "People" }).click();
await page.locator(".mx_RightPanelTabs").getByText("People").click();
await expect(page.locator(".mx_MemberList")).toBeVisible();

await getMemberTileByName(page, NAME).click();
Expand All @@ -123,7 +123,7 @@ test.describe("RightPanel", () => {
await page.getByRole("button", { name: "Room members" }).click();
await expect(page.locator(".mx_MemberList")).toBeVisible();

await page.getByRole("button", { name: "Room information" }).click();
await page.locator(".mx_RightPanelTabs").getByText("Info").click();
await checkRoomSummaryCard(page, ROOM_NAME);
});
});
Expand Down
8 changes: 3 additions & 5 deletions playwright/e2e/spaces/threads-activity-centre/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,10 @@ export class Helpers {
}

/**
* Assert that the thread panel is focused (actually the 'close' button, specifically)
* Assert that the thread tab is focused
*/
assertThreadPanelFocused() {
return expect(
this.page.locator(".mx_ThreadPanel").locator(".mx_BaseCard_header").getByLabel("Close"),
).toBeFocused();
assertThreadTabFocused() {
return expect(this.page.locator("#thread-panel-tab")).toBeFocused();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,12 @@ test.describe("Threads Activity Centre", () => {
await util.assertNoTacIndicator();
});

test("should focus the thread panel close button when clicking an item in the TAC", async ({
room1,
room2,
util,
msg,
}) => {
test("should focus the thread tab when clicking an item in the TAC", async ({ room1, room2, util, msg }) => {
await util.receiveMessages(room1, ["Msg1", msg.threadedOff("Msg1", "Resp1")]);

await util.openTac();
await util.clickRoomInTac(room1.name);

await util.assertThreadPanelFocused();
await util.assertThreadTabFocused();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 0 additions & 39 deletions test/components/structures/ThreadPanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import ResizeNotifier from "../../../src/utils/ResizeNotifier";
import { createTestClient, getRoomContext, mkRoom, mockPlatformPeg, stubClient } from "../../test-utils";
import { mkThread } from "../../test-utils/threads";
import { IRoomState } from "../../../src/components/structures/RoomView";
import defaultDispatcher from "../../../src/dispatcher/dispatcher";
import { Action } from "../../../src/dispatcher/actions";

jest.mock("../../../src/utils/Feedback");

Expand Down Expand Up @@ -148,43 +146,6 @@ describe("ThreadPanel", () => {
fireEvent.click(getByRole(container, "button", { name: "Mark all as read" }));
await waitFor(() => expect(mockClient.sendReadReceipt).not.toHaveBeenCalled());
});

it("focuses the close button on FocusThreadsPanel dispatch", () => {
const ROOM_ID = "!roomId:example.org";

stubClient();
mockPlatformPeg();
const mockClient = mocked(MatrixClientPeg.safeGet());

const room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
pendingEventOrdering: PendingEventOrdering.Detached,
});

render(
<MatrixClientContext.Provider value={mockClient}>
<RoomContext.Provider
value={getRoomContext(room, {
canSendMessages: true,
})}
>
<ThreadPanel
roomId={ROOM_ID}
onClose={jest.fn()}
resizeNotifier={new ResizeNotifier()}
permalinkCreator={new RoomPermalinkCreator(room)}
/>
</RoomContext.Provider>
</MatrixClientContext.Provider>,
);

// Unfocus it first so we know it's not just focused by coincidence
screen.getByTestId("base-card-close-button").blur();
expect(screen.getByTestId("base-card-close-button")).not.toHaveFocus();

defaultDispatcher.dispatch({ action: Action.FocusThreadsPanel }, true);

expect(screen.getByTestId("base-card-close-button")).toHaveFocus();
});
});

describe("Filtering", () => {
Expand Down
72 changes: 72 additions & 0 deletions test/components/views/right_panel/RightPanelTabs-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2024 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from "react";
import { render, fireEvent } from "@testing-library/react";

import dis from "../../../../src/dispatcher/dispatcher";
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
import { RightPanelTabs } from "../../../../src/components/views/right_panel/RightPanelTabs";
import { Action } from "../../../../src/dispatcher/actions";

describe("<RightPanelTabs />", () => {
it("Component renders the correct tabs", () => {
const { container, getByRole } = render(<RightPanelTabs phase={RightPanelPhases.RoomSummary} />);
expect(container).toMatchSnapshot();

// We expect Info, People and Threads as tabs
expect(getByRole("tab", { name: "Info" })).toBeDefined();
expect(getByRole("tab", { name: "People" })).toBeDefined();
expect(getByRole("tab", { name: "Threads" })).toBeDefined();
});

it("Correct tab is active", () => {
const { container } = render(<RightPanelTabs phase={RightPanelPhases.RoomMemberList} />);
expect(container).toMatchSnapshot();
// Assert that the active tab is Info
expect(container.querySelectorAll("[aria-selected='true'").length).toEqual(1);
expect(container.querySelector("[aria-selected='true'")).toHaveAccessibleName("People");
});

it("Renders nothing for some phases, eg: FilePanel", () => {
const { container } = render(<RightPanelTabs phase={RightPanelPhases.FilePanel} />);
expect(container).toBeEmptyDOMElement();
});

it("onClick behaviors work as expected", () => {
const spy = jest.spyOn(RightPanelStore.instance, "pushCard");
const { getByRole } = render(<RightPanelTabs phase={RightPanelPhases.RoomSummary} />);

// Info -> People
fireEvent.click(getByRole("tab", { name: "People" }));
expect(spy).toHaveBeenLastCalledWith({ phase: RightPanelPhases.RoomMemberList }, true);

// People -> Threads
fireEvent.click(getByRole("tab", { name: "Threads" }));
expect(spy).toHaveBeenLastCalledWith({ phase: RightPanelPhases.ThreadPanel }, true);

// Threads -> Info
fireEvent.click(getByRole("tab", { name: "Info" }));
expect(spy).toHaveBeenLastCalledWith({ phase: RightPanelPhases.RoomSummary }, true);
});

it("Threads tab is focused on action", () => {
const { getByRole } = render(<RightPanelTabs phase={RightPanelPhases.ThreadPanel} />);
dis.dispatch({ action: Action.FocusThreadsPanel }, true);
expect(getByRole("tab", { name: "Threads" })).toHaveFocus();
});
});
15 changes: 0 additions & 15 deletions test/components/views/right_panel/RoomSummaryCard-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } f
import { PollHistoryDialog } from "../../../../src/components/views/dialogs/PollHistoryDialog";
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
import { _t } from "../../../../src/languageHandler";
import SettingsStore from "../../../../src/settings/SettingsStore";
import { tagRoom } from "../../../../src/utils/room/tagRoom";
import { DefaultTagID } from "../../../../src/stores/room-list/models";
import { Action } from "../../../../src/dispatcher/actions";
Expand Down Expand Up @@ -195,7 +194,6 @@ describe("<RoomSummaryCard />", () => {
<RoomSummaryCard
room={room}
permalinkCreator={new RoomPermalinkCreator(room)}
onClose={jest.fn()}
onSearchChange={onSearchChange}
focusRoomSearch={true}
/>
Expand All @@ -212,7 +210,6 @@ describe("<RoomSummaryCard />", () => {
<RoomSummaryCard
room={room}
permalinkCreator={new RoomPermalinkCreator(room)}
onClose={jest.fn()}
onSearchChange={onSearchChange}
/>
</RoomContext.Provider>
Expand Down Expand Up @@ -270,18 +267,6 @@ describe("<RoomSummaryCard />", () => {
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({ action: "open_room_settings" });
});

it("renders room members options when new room UI is not enabled", () => {
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
const { getByText } = getComponent();

fireEvent.click(getByText(_t("common|people")));

expect(RightPanelStore.instance.pushCard).toHaveBeenCalledWith(
{ phase: RightPanelPhases.RoomMemberList },
true,
);
});

describe("pinning", () => {
it("renders pins options when pinning feature is enabled", () => {
mocked(settingsHooks.useFeatureEnabled).mockImplementation((feature) => feature === "feature_pinning");
Expand Down
Loading

0 comments on commit a8ead86

Please sign in to comment.