2021-12-10 12:17:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 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.
|
|
|
|
*/
|
|
|
|
|
2022-04-21 16:14:10 +00:00
|
|
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
2021-12-10 12:17:26 +00:00
|
|
|
|
|
|
|
import { PollStartEventPreview } from "../../../../src/stores/room-list/previews/PollStartEventPreview";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
2022-04-21 16:14:10 +00:00
|
|
|
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);
|
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");
|
|
|
|
});
|
|
|
|
});
|