Make tests more resilient for React 18 upgrade (#12861)
* Make tests more resilient for React 18 upgrade Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { render } from "@testing-library/react";
|
||||
import { render, waitFor } from "@testing-library/react";
|
||||
import {
|
||||
MatrixEvent,
|
||||
MsgType,
|
||||
@@ -79,21 +79,23 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
|
||||
});
|
||||
|
||||
it("thread notification does change the thread button", () => {
|
||||
it("thread notification does change the thread button", async () => {
|
||||
const { container } = getComponent(room);
|
||||
expect(getThreadButton(container)!.className.includes("mx_LegacyRoomHeader_button--unread")).toBeFalsy();
|
||||
|
||||
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Total, 1);
|
||||
expect(getThreadButton(container)!.className.includes("mx_LegacyRoomHeader_button--unread")).toBeTruthy();
|
||||
expect(isIndicatorOfType(container, "notification")).toBe(true);
|
||||
await waitFor(() => {
|
||||
expect(getThreadButton(container)!.className.includes("mx_LegacyRoomHeader_button--unread")).toBeTruthy();
|
||||
expect(isIndicatorOfType(container, "notification")).toBe(true);
|
||||
});
|
||||
|
||||
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Highlight, 1);
|
||||
expect(isIndicatorOfType(container, "highlight")).toBe(true);
|
||||
await waitFor(() => expect(isIndicatorOfType(container, "highlight")).toBe(true));
|
||||
|
||||
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Total, 0);
|
||||
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Highlight, 0);
|
||||
|
||||
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
|
||||
await waitFor(() => expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull());
|
||||
});
|
||||
|
||||
it("thread activity does change the thread button", async () => {
|
||||
@@ -122,7 +124,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
expect(isIndicatorOfType(container, "activity")).toBe(true);
|
||||
await waitFor(() => expect(isIndicatorOfType(container, "activity")).toBe(true));
|
||||
|
||||
// Sending the last event should clear the notification.
|
||||
let event = mkEvent({
|
||||
@@ -140,7 +142,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
},
|
||||
});
|
||||
room.addLiveEvents([event]);
|
||||
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
|
||||
await waitFor(() => expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull());
|
||||
|
||||
// Mark it as unread again.
|
||||
event = mkEvent({
|
||||
@@ -158,7 +160,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
},
|
||||
});
|
||||
room.addLiveEvents([event]);
|
||||
expect(isIndicatorOfType(container, "activity")).toBe(true);
|
||||
await waitFor(() => expect(isIndicatorOfType(container, "activity")).toBe(true));
|
||||
|
||||
// Sending a read receipt on an earlier event shouldn't do anything.
|
||||
receipt = new MatrixEvent({
|
||||
@@ -173,7 +175,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
expect(isIndicatorOfType(container, "activity")).toBe(true);
|
||||
await waitFor(() => expect(isIndicatorOfType(container, "activity")).toBe(true));
|
||||
|
||||
// Sending a receipt on the latest event should clear the notification.
|
||||
receipt = new MatrixEvent({
|
||||
@@ -188,6 +190,6 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
|
||||
await waitFor(() => expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -87,20 +87,17 @@ describe("<PinnedMessagesCard />", () => {
|
||||
};
|
||||
|
||||
const mountPins = async (room: Room): Promise<RenderResult> => {
|
||||
let pins!: RenderResult;
|
||||
await act(async () => {
|
||||
pins = render(
|
||||
<MatrixClientContext.Provider value={cli}>
|
||||
<PinnedMessagesCard
|
||||
room={room}
|
||||
onClose={jest.fn()}
|
||||
permalinkCreator={new RoomPermalinkCreator(room, room.roomId)}
|
||||
/>
|
||||
</MatrixClientContext.Provider>,
|
||||
);
|
||||
// Wait a tick for state updates
|
||||
await sleep(0);
|
||||
});
|
||||
const pins = render(
|
||||
<MatrixClientContext.Provider value={cli}>
|
||||
<PinnedMessagesCard
|
||||
room={room}
|
||||
onClose={jest.fn()}
|
||||
permalinkCreator={new RoomPermalinkCreator(room, room.roomId)}
|
||||
/>
|
||||
</MatrixClientContext.Provider>,
|
||||
);
|
||||
// Wait a tick for state updates
|
||||
await act(() => sleep(0));
|
||||
|
||||
return pins;
|
||||
};
|
||||
@@ -313,7 +310,6 @@ describe("<PinnedMessagesCard />", () => {
|
||||
it("should show spinner whilst loading", async () => {
|
||||
const room = mkRoom([], [pin1]);
|
||||
mountPins(room);
|
||||
const spinner = await screen.findByTestId("spinner");
|
||||
await waitForElementToBeRemoved(spinner);
|
||||
await waitForElementToBeRemoved(() => screen.queryAllByRole("progressbar"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -287,10 +287,10 @@ describe("<UserInfo />", () => {
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("renders close button correctly when encryption panel with a pending verification request", () => {
|
||||
it("renders close button correctly when encryption panel with a pending verification request", async () => {
|
||||
renderComponent({ phase: RightPanelPhases.EncryptionPanel, verificationRequest });
|
||||
screen.getByTestId("base-card-close-button").focus();
|
||||
expect(screen.getByRole("tooltip")).toHaveTextContent("Cancel");
|
||||
await expect(screen.findByRole("tooltip", { name: "Cancel" })).resolves.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user