2021-12-10 12:17:26 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2021-12-10 12:17:26 +00:00
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2021-12-10 12:17:26 +00:00
|
|
|
*/
|
|
|
|
|
2022-04-21 16:14:10 +00:00
|
|
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
2021-12-10 12:17:26 +00:00
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
import { PollStartEventPreview } from "../../../../../src/stores/room-list/previews/PollStartEventPreview";
|
|
|
|
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
|
|
|
import { makePollStartEvent } from "../../../../test-utils";
|
2021-12-10 12:17:26 +00:00
|
|
|
|
2022-03-11 16:03:33 +00:00
|
|
|
jest.spyOn(MatrixClientPeg, "get").mockReturnValue({
|
2021-12-10 12:17:26 +00:00
|
|
|
getUserId: () => "@me:example.com",
|
2023-05-05 07:45:14 +00:00
|
|
|
getSafeUserId: () => "@me:example.com",
|
2022-03-11 16:03:33 +00:00
|
|
|
} as unknown as MatrixClient);
|
2023-06-15 14:11:49 +00:00
|
|
|
jest.spyOn(MatrixClientPeg, "safeGet").mockReturnValue({
|
|
|
|
getUserId: () => "@me:example.com",
|
|
|
|
getSafeUserId: () => "@me:example.com",
|
|
|
|
} as unknown as MatrixClient);
|
2021-12-10 12:17:26 +00:00
|
|
|
|
|
|
|
describe("PollStartEventPreview", () => {
|
|
|
|
it("shows the question for a poll I created", async () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const pollStartEvent = makePollStartEvent("My Question", "@me:example.com");
|
2021-12-10 12:17:26 +00:00
|
|
|
const preview = new PollStartEventPreview();
|
|
|
|
expect(preview.getTextFor(pollStartEvent)).toBe("My Question");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows the sender and question for a poll created by someone else", async () => {
|
2022-04-21 16:14:10 +00:00
|
|
|
const pollStartEvent = makePollStartEvent("Your Question", "@yo:example.com");
|
2021-12-10 12:17:26 +00:00
|
|
|
const preview = new PollStartEventPreview();
|
|
|
|
expect(preview.getTextFor(pollStartEvent)).toBe("@yo:example.com: Your Question");
|
|
|
|
});
|
|
|
|
});
|