2021-12-10 15:17:26 +03: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { MatrixEvent } from "matrix-js-sdk";
|
2022-01-17 20:06:30 +03:00
|
|
|
import { POLL_ANSWER, M_TEXT, M_POLL_KIND_DISCLOSED, M_POLL_START } from "matrix-events-sdk";
|
2021-12-10 15:17:26 +03:00
|
|
|
|
|
|
|
import { PollStartEventPreview } from "../../../../src/stores/room-list/previews/PollStartEventPreview";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
|
|
|
|
MatrixClientPeg.matrixClient = {
|
|
|
|
getUserId: () => "@me:example.com",
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("PollStartEventPreview", () => {
|
|
|
|
it("shows the question for a poll I created", async () => {
|
|
|
|
const pollStartEvent = newPollStartEvent("My Question", "@me:example.com");
|
|
|
|
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 () => {
|
|
|
|
const pollStartEvent = newPollStartEvent("Your Question", "@yo:example.com");
|
|
|
|
const preview = new PollStartEventPreview();
|
|
|
|
expect(preview.getTextFor(pollStartEvent)).toBe("@yo:example.com: Your Question");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function newPollStartEvent(
|
|
|
|
question: string,
|
|
|
|
sender: string,
|
2022-01-17 20:06:30 +03:00
|
|
|
answers?: POLL_ANSWER[],
|
2021-12-10 15:17:26 +03:00
|
|
|
): MatrixEvent {
|
|
|
|
if (!answers) {
|
|
|
|
answers = [
|
2022-01-17 20:06:30 +03:00
|
|
|
{ "id": "socks", [M_TEXT.name]: "Socks" },
|
|
|
|
{ "id": "shoes", [M_TEXT.name]: "Shoes" },
|
2021-12-10 15:17:26 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return new MatrixEvent(
|
|
|
|
{
|
|
|
|
"event_id": "$mypoll",
|
|
|
|
"room_id": "#myroom:example.com",
|
|
|
|
"sender": sender,
|
2022-01-17 20:06:30 +03:00
|
|
|
"type": M_POLL_START.name,
|
2021-12-10 15:17:26 +03:00
|
|
|
"content": {
|
2022-01-17 20:06:30 +03:00
|
|
|
[M_POLL_START.name]: {
|
2021-12-10 15:17:26 +03:00
|
|
|
"question": {
|
2022-01-17 20:06:30 +03:00
|
|
|
[M_TEXT.name]: question,
|
2021-12-10 15:17:26 +03:00
|
|
|
},
|
2022-01-17 20:06:30 +03:00
|
|
|
"kind": M_POLL_KIND_DISCLOSED.name,
|
2021-12-10 15:17:26 +03:00
|
|
|
"answers": answers,
|
|
|
|
},
|
2022-01-17 20:06:30 +03:00
|
|
|
[M_TEXT.name]: `${question}: answers`,
|
2021-12-10 15:17:26 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|