Merge branch 'develop' of https://github.com/vector-im/element-web into dbkr/stateafter
# Conflicts: # test/unit-tests/components/structures/RoomView-test.tsx # test/unit-tests/components/structures/TimelinePanel-test.tsx
This commit is contained in:
@@ -23,6 +23,8 @@ import {
|
||||
concat,
|
||||
asyncEvery,
|
||||
asyncSome,
|
||||
asyncSomeParallel,
|
||||
asyncFilter,
|
||||
} from "../../../src/utils/arrays";
|
||||
|
||||
type TestParams = { input: number[]; output: number[] };
|
||||
@@ -460,4 +462,34 @@ describe("arrays", () => {
|
||||
expect(predicate).toHaveBeenCalledWith(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("asyncSomeParallel", () => {
|
||||
it("when called with an empty array, it should return false", async () => {
|
||||
expect(await asyncSomeParallel([], jest.fn().mockResolvedValue(true))).toBe(false);
|
||||
});
|
||||
|
||||
it("when all the predicates return false", async () => {
|
||||
expect(await asyncSomeParallel([1, 2, 3], jest.fn().mockResolvedValue(false))).toBe(false);
|
||||
});
|
||||
|
||||
it("when all the predicates return true", async () => {
|
||||
expect(await asyncSomeParallel([1, 2, 3], jest.fn().mockResolvedValue(true))).toBe(true);
|
||||
});
|
||||
|
||||
it("when one of the predicate return true", async () => {
|
||||
const predicate = jest.fn().mockImplementation((value) => Promise.resolve(value === 2));
|
||||
expect(await asyncSomeParallel([1, 2, 3], predicate)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("asyncFilter", () => {
|
||||
it("when called with an empty array, it should return an empty array", async () => {
|
||||
expect(await asyncFilter([], jest.fn().mockResolvedValue(true))).toEqual([]);
|
||||
});
|
||||
|
||||
it("should filter the content", async () => {
|
||||
const predicate = jest.fn().mockImplementation((value) => Promise.resolve(value === 2));
|
||||
expect(await asyncFilter([1, 2, 3], predicate)).toEqual([2]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
22
test/unit-tests/utils/login-test.ts
Normal file
22
test/unit-tests/utils/login-test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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 MatrixChat from "../../../src/components/structures/MatrixChat.tsx";
|
||||
import { isLoggedIn } from "../../../src/utils/login.ts";
|
||||
import Views from "../../../src/Views.ts";
|
||||
|
||||
describe("isLoggedIn", () => {
|
||||
it("should return true if MatrixChat state view is LOGGED_IN", () => {
|
||||
window.matrixChat = {
|
||||
state: {
|
||||
view: Views.LOGGED_IN,
|
||||
},
|
||||
} as unknown as MatrixChat;
|
||||
|
||||
expect(isLoggedIn()).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -21,7 +21,7 @@ describe("requestMediaPermissions", () => {
|
||||
const itShouldLogTheErrorAndShowTheNoMediaPermissionsModal = () => {
|
||||
it("should log the error and show the »No media permissions« modal", async () => {
|
||||
expect(logger.log).toHaveBeenCalledWith("Failed to list userMedia devices", error);
|
||||
await screen.findByText("No media permissions");
|
||||
await expect(screen.findByText("No media permissions")).resolves.toBeInTheDocument();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ describe("notifications", () => {
|
||||
// set true, no existing event
|
||||
it("sets unread flag if event doesn't exist", async () => {
|
||||
await setMarkedUnreadState(room, client, true);
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "com.famedly.marked_unread", {
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "m.marked_unread", {
|
||||
unread: true,
|
||||
});
|
||||
});
|
||||
@@ -287,7 +287,7 @@ describe("notifications", () => {
|
||||
.fn()
|
||||
.mockReturnValue({ getContent: jest.fn().mockReturnValue({ unread: false }) });
|
||||
await setMarkedUnreadState(room, client, true);
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "com.famedly.marked_unread", {
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "m.marked_unread", {
|
||||
unread: true,
|
||||
});
|
||||
});
|
||||
@@ -316,7 +316,7 @@ describe("notifications", () => {
|
||||
.fn()
|
||||
.mockReturnValue({ getContent: jest.fn().mockReturnValue({ unread: true }) });
|
||||
await setMarkedUnreadState(room, client, false);
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "com.famedly.marked_unread", {
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "m.marked_unread", {
|
||||
unread: false,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user