mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-04 01:19:41 +00:00
Absorb the matrix-react-sdk repository (#28192)
Co-authored-by: github-merge-queue <118344674+github-merge-queue@users.noreply.github.com> Co-authored-by: github-merge-queue <github-merge-queue@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Florian Duros <florian.duros@ormaz.fr> Co-authored-by: Kim Brose <kim.brose@nordeck.net> Co-authored-by: Florian Duros <florianduros@element.io> Co-authored-by: R Midhun Suresh <hi@midhun.dev> Co-authored-by: dbkr <986903+dbkr@users.noreply.github.com> Co-authored-by: ElementRobot <releases@riot.im> Co-authored-by: dbkr <dbkr@users.noreply.github.com> Co-authored-by: David Baker <dbkr@users.noreply.github.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Co-authored-by: David Langley <davidl@element.io> Co-authored-by: Michael Weimann <michaelw@matrix.org> Co-authored-by: Timshel <Timshel@users.noreply.github.com> Co-authored-by: Sahil Silare <32628578+sahil9001@users.noreply.github.com> Co-authored-by: Will Hunt <will@half-shot.uk> Co-authored-by: Hubert Chathi <hubert@uhoreg.ca> Co-authored-by: Andrew Ferrazzutti <andrewf@element.io> Co-authored-by: Robin <robin@robin.town> Co-authored-by: Tulir Asokan <tulir@maunium.net>
This commit is contained in:
committed by
GitHub
parent
2b99496025
commit
c05c429803
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
import { test, expect } from "../../element-web-test";
|
||||
import type { Bot } from "../../pages/bot";
|
||||
import type { Client } from "../../pages/client";
|
||||
import { ElementAppPage } from "../../pages/ElementAppPage";
|
||||
|
||||
test.describe("Poll history", () => {
|
||||
type CreatePollOptions = {
|
||||
title: string;
|
||||
options: {
|
||||
"id": string;
|
||||
"org.matrix.msc1767.text": string;
|
||||
}[];
|
||||
};
|
||||
const createPoll = async (createOptions: CreatePollOptions, roomId: string, client: Client) => {
|
||||
return client.sendEvent(roomId, null, "org.matrix.msc3381.poll.start", {
|
||||
"org.matrix.msc3381.poll.start": {
|
||||
question: {
|
||||
"org.matrix.msc1767.text": createOptions.title,
|
||||
"body": createOptions.title,
|
||||
"msgtype": "m.text",
|
||||
},
|
||||
kind: "org.matrix.msc3381.poll.disclosed",
|
||||
max_selections: 1,
|
||||
answers: createOptions.options,
|
||||
},
|
||||
"org.matrix.msc1767.text": "poll fallback text",
|
||||
});
|
||||
};
|
||||
|
||||
const botVoteForOption = async (bot: Bot, roomId: string, pollId: string, optionId: string): Promise<void> => {
|
||||
// We can't use the js-sdk types for this stuff directly, so manually construct the event.
|
||||
await bot.sendEvent(roomId, null, "org.matrix.msc3381.poll.response", {
|
||||
"m.relates_to": {
|
||||
rel_type: "m.reference",
|
||||
event_id: pollId,
|
||||
},
|
||||
"org.matrix.msc3381.poll.response": {
|
||||
answers: [optionId],
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const endPoll = async (bot: Bot, roomId: string, pollId: string): Promise<void> => {
|
||||
// We can't use the js-sdk types for this stuff directly, so manually construct the event.
|
||||
await bot.sendEvent(roomId, null, "org.matrix.msc3381.poll.end", {
|
||||
"m.relates_to": {
|
||||
rel_type: "m.reference",
|
||||
event_id: pollId,
|
||||
},
|
||||
"org.matrix.msc1767.text": "The poll has ended",
|
||||
});
|
||||
};
|
||||
|
||||
async function openPollHistory(app: ElementAppPage): Promise<void> {
|
||||
const { page } = app;
|
||||
await app.toggleRoomInfoPanel();
|
||||
await page.locator(".mx_RoomSummaryCard").getByRole("menuitem", { name: "Polls" }).click();
|
||||
}
|
||||
|
||||
test.use({
|
||||
displayName: "Tom",
|
||||
botCreateOpts: { displayName: "BotBob" },
|
||||
});
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.addInitScript(() => {
|
||||
// Collapse left panel for these tests
|
||||
window.localStorage.setItem("mx_lhs_size", "0");
|
||||
});
|
||||
});
|
||||
|
||||
test("Should display active and past polls", async ({ page, app, user, bot }) => {
|
||||
const pollParams1 = {
|
||||
title: "Does the polls feature work?",
|
||||
options: ["Yes", "No", "Maybe"].map((option) => ({
|
||||
"id": option,
|
||||
"org.matrix.msc1767.text": option,
|
||||
})),
|
||||
};
|
||||
|
||||
const pollParams2 = {
|
||||
title: "Which way",
|
||||
options: ["Left", "Right"].map((option) => ({
|
||||
"id": option,
|
||||
"org.matrix.msc1767.text": option,
|
||||
})),
|
||||
};
|
||||
|
||||
const roomId = await app.client.createRoom({});
|
||||
|
||||
await app.client.inviteUser(roomId, bot.credentials.userId);
|
||||
await page.goto("/#/room/" + roomId);
|
||||
// wait until Bob joined
|
||||
await expect(page.getByText("BotBob joined the room")).toBeAttached();
|
||||
|
||||
// active poll
|
||||
const { event_id: pollId1 } = await createPoll(pollParams1, roomId, bot);
|
||||
await botVoteForOption(bot, roomId, pollId1, pollParams1.options[1].id);
|
||||
|
||||
// ended poll
|
||||
const { event_id: pollId2 } = await createPoll(pollParams2, roomId, bot);
|
||||
await botVoteForOption(bot, roomId, pollId2, pollParams1.options[1].id);
|
||||
await endPoll(bot, roomId, pollId2);
|
||||
|
||||
await openPollHistory(app);
|
||||
|
||||
// these polls are also in the timeline
|
||||
// focus on the poll history dialog
|
||||
const dialog = page.locator(".mx_Dialog");
|
||||
|
||||
// active poll is in active polls list
|
||||
// open poll detail
|
||||
await dialog.getByText(pollParams1.title).click();
|
||||
await dialog.getByText("Yes").click();
|
||||
// vote in the poll
|
||||
await expect(dialog.getByTestId("totalVotes").getByText("Based on 2 votes")).toBeAttached();
|
||||
// navigate back to list
|
||||
await dialog.locator(".mx_PollHistory_header").getByRole("button", { name: "Active polls" }).click();
|
||||
|
||||
// go to past polls list
|
||||
await dialog.getByText("Past polls").click();
|
||||
|
||||
await expect(dialog.getByText(pollParams2.title)).toBeAttached();
|
||||
|
||||
// end poll1 while dialog is open
|
||||
await endPoll(bot, roomId, pollId1);
|
||||
|
||||
await expect(dialog.getByText(pollParams2.title)).toBeAttached();
|
||||
await expect(dialog.getByText(pollParams1.title)).toBeAttached();
|
||||
dialog.getByText("Active polls").click();
|
||||
|
||||
// no more active polls
|
||||
await expect(page.getByText("There are no active polls in this room")).toBeAttached();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user