From 20832131311a8c5c6c72757b722cac6e93a0bd63 Mon Sep 17 00:00:00 2001 From: Tim Vahlbrock Date: Fri, 1 Nov 2024 12:15:53 +0100 Subject: [PATCH] Fix existing tests but 3 --- src/components/views/messages/MPollBody.tsx | 4 +- src/components/views/polls/PollOption.tsx | 9 +- src/i18n/strings/en_EN.json | 8 +- .../views/messages/MPollBody-test.tsx | 56 +- .../__snapshots__/MPollBody-test.tsx.snap | 811 ++++++++++++++---- 5 files changed, 685 insertions(+), 203 deletions(-) diff --git a/src/components/views/messages/MPollBody.tsx b/src/components/views/messages/MPollBody.tsx index 7bf921f5dd..67c94fd988 100644 --- a/src/components/views/messages/MPollBody.tsx +++ b/src/components/views/messages/MPollBody.tsx @@ -367,8 +367,8 @@ export default class MPollBody extends React.Component { ); })} -
- showDetailedVotes()}>{totalText} +
+ showDetailedVotes()}>{totalText} {isFetchingResponses && }
diff --git a/src/components/views/polls/PollOption.tsx b/src/components/views/polls/PollOption.tsx index 45c06cfbec..47c805e718 100644 --- a/src/components/views/polls/PollOption.tsx +++ b/src/components/views/polls/PollOption.tsx @@ -12,7 +12,6 @@ import React, { ReactNode, useContext } from "react"; import { Icon as TrophyIcon } from "../../../../res/img/element-icons/trophy.svg"; import RoomContext from "../../../contexts/RoomContext"; -import { useRoomMembers } from "../../../hooks/useRoomMembers"; import { _t } from "../../../languageHandler"; import FacePile from "../elements/FacePile"; import StyledRadioButton from "../elements/StyledRadioButton"; @@ -28,13 +27,13 @@ type PollOptionContentProps = { }; const PollOptionContent: React.FC = ({ isWinner, answer, votes, displayVoteCount }) => { const votesText = displayVoteCount ? _t("timeline|m.poll|count_of_votes", { count: votes.length }) : ""; - const room = useContext(RoomContext).room!; - const members = useRoomMembers(room); + const room = useContext(RoomContext).room; + const members = room?.getJoinedMembers() || []; return (
{answer.text}
-
+
{displayVoteCount && members.length <= MAXIMUM_MEMBERS_FOR_FACE_PILE @@ -45,7 +44,7 @@ const PollOptionContent: React.FC = ({ isWinner, answer, style={{ marginRight: "10px" }} /> } - + {isWinner && } {votesText} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index f31af3983a..8ed4e17ec7 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1727,8 +1727,8 @@ "other": "%(count)s votes cast. Vote to see the results" }, "total_n_votes_voted": { - "one": "Based on %(count)s vote. Click here to see the results", - "other": "Based on %(count)s votes. Click here to see the results" + "one": "Based on %(count)s vote. Click here to see full results", + "other": "Based on %(count)s votes. Click here to see full results" }, "total_no_votes": "No votes cast", "total_not_ended": "Results will be visible when the poll is ended", @@ -1879,8 +1879,8 @@ "other": "There are no past polls for the past %(count)s days. Load more polls to view polls for previous months" }, "final_result": { - "one": "Final result based on %(count)s vote. Click here to see the results", - "other": "Final result based on %(count)s votes. Click here to see the results" + "one": "Final result based on %(count)s vote. Click here to see full results", + "other": "Final result based on %(count)s votes. Click here to see full results" }, "load_more": "Load more polls", "loading": "Loading polls", diff --git a/test/unit-tests/components/views/messages/MPollBody-test.tsx b/test/unit-tests/components/views/messages/MPollBody-test.tsx index a4e3fc1e10..eb94b2906e 100644 --- a/test/unit-tests/components/views/messages/MPollBody-test.tsx +++ b/test/unit-tests/components/views/messages/MPollBody-test.tsx @@ -6,26 +6,30 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ -import React from "react"; import { fireEvent, render, RenderResult } from "jest-matrix-react"; import { - MatrixEvent, - Relations, M_POLL_KIND_DISCLOSED, M_POLL_KIND_UNDISCLOSED, M_POLL_RESPONSE, M_POLL_START, - PollStartEventContent, - PollAnswer, M_TEXT, + MatrixEvent, + PollAnswer, + PollStartEventContent, + Relations } from "matrix-js-sdk/src/matrix"; +import React from "react"; +import { IBodyProps } from "../../../../../src/components/views/messages/IBodyProps"; import MPollBody, { allVotes, findTopAnswer, isPollEnded, } from "../../../../../src/components/views/messages/MPollBody"; -import { IBodyProps } from "../../../../../src/components/views/messages/IBodyProps"; +import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext"; +import * as languageHandler from "../../../../../src/languageHandler"; +import { MediaEventHelper } from "../../../../../src/utils/MediaEventHelper"; +import { RoomPermalinkCreator } from "../../../../../src/utils/permalinks/Permalinks"; import { flushPromises, getMockClientWithEventEmitter, @@ -33,10 +37,6 @@ import { mockClientMethodsUser, setupRoomWithPollEvents, } from "../../../../test-utils"; -import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext"; -import { RoomPermalinkCreator } from "../../../../../src/utils/permalinks/Permalinks"; -import { MediaEventHelper } from "../../../../../src/utils/MediaEventHelper"; -import * as languageHandler from "../../../../../src/languageHandler"; const CHECKED = "mx_PollOption_checked"; const userId = "@me:example.com"; @@ -99,7 +99,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "poutine")).toBe("1 vote"); expect(votesCount(renderResult, "italian")).toBe("0 votes"); expect(votesCount(renderResult, "wings")).toBe("1 vote"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 4 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 4 votes. Click here to see full results"); }); it("ignores end poll events from unauthorised users", async () => { @@ -118,7 +118,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "poutine")).toBe("1 vote"); expect(votesCount(renderResult, "italian")).toBe("0 votes"); expect(votesCount(renderResult, "wings")).toBe("1 vote"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 4 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 4 votes. Click here to see full results"); }); it("hides scores if I have not voted", async () => { @@ -159,7 +159,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "poutine")).toBe("1 vote"); expect(votesCount(renderResult, "italian")).toBe("0 votes"); expect(votesCount(renderResult, "wings")).toBe("1 vote"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes. Click here to see full results"); }); it("uses my local vote", async () => { @@ -180,7 +180,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "italian")).toBe("1 vote"); expect(votesCount(renderResult, "wings")).toBe("0 votes"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 4 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 4 votes. Click here to see full results"); }); it("overrides my other votes with my local vote", async () => { @@ -202,7 +202,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "italian")).toBe("1 vote"); expect(votesCount(renderResult, "wings")).toBe("1 vote"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes. Click here to see full results"); // And my vote is highlighted expect(voteButton(renderResult, "wings").className.includes(CHECKED)).toBe(true); @@ -234,7 +234,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "italian")).toBe("0 votes"); expect(votesCount(renderResult, "wings")).toBe("1 vote"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 1 vote"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 1 vote. Click here to see full results"); }); it("doesn't cancel my local vote if someone else votes", async () => { @@ -266,7 +266,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "italian")).toBe("0 votes"); expect(votesCount(renderResult, "wings")).toBe("1 vote"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes. Click here to see full results"); // And my vote is highlighted expect(voteButton(renderResult, "pizza").className.includes(CHECKED)).toBe(true); @@ -293,7 +293,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "poutine")).toBe("0 votes"); expect(votesCount(renderResult, "italian")).toBe("0 votes"); expect(votesCount(renderResult, "wings")).toBe("1 vote"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes. Click here to see full results"); }); it("allows un-voting by passing an empty vote", async () => { @@ -307,7 +307,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "poutine")).toBe("0 votes"); expect(votesCount(renderResult, "italian")).toBe("1 vote"); expect(votesCount(renderResult, "wings")).toBe("0 votes"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 1 vote"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 1 vote. Click here to see full results"); }); it("allows re-voting after un-voting", async () => { @@ -322,7 +322,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "poutine")).toBe("0 votes"); expect(votesCount(renderResult, "italian")).toBe("2 votes"); expect(votesCount(renderResult, "wings")).toBe("0 votes"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 2 votes. Click here to see full results"); }); it("treats any invalid answer as a spoiled ballot", async () => { @@ -340,7 +340,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "poutine")).toBe("0 votes"); expect(votesCount(renderResult, "italian")).toBe("0 votes"); expect(votesCount(renderResult, "wings")).toBe("0 votes"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 0 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 0 votes. Click here to see full results"); }); it("allows re-voting after a spoiled ballot", async () => { @@ -357,7 +357,7 @@ describe("MPollBody", () => { expect(votesCount(renderResult, "poutine")).toBe("1 vote"); expect(votesCount(renderResult, "italian")).toBe("0 votes"); expect(votesCount(renderResult, "wings")).toBe("0 votes"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 1 vote"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Based on 1 vote. Click here to see full results"); }); it("renders nothing if poll has no answers", async () => { @@ -526,7 +526,7 @@ describe("MPollBody", () => { expect(endedVotesCount(renderResult, "poutine")).toBe('
1 vote'); expect(endedVotesCount(renderResult, "italian")).toBe("0 votes"); expect(endedVotesCount(renderResult, "wings")).toBe('
1 vote'); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 2 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 2 votes. Click here to see full results"); }); it("counts a single vote as normal if the poll is ended", async () => { @@ -537,7 +537,7 @@ describe("MPollBody", () => { expect(endedVotesCount(renderResult, "poutine")).toBe('
1 vote'); expect(endedVotesCount(renderResult, "italian")).toBe("0 votes"); expect(endedVotesCount(renderResult, "wings")).toBe("0 votes"); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 1 vote"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 1 vote. Click here to see full results"); }); it("shows ended vote counts of different numbers", async () => { @@ -557,7 +557,7 @@ describe("MPollBody", () => { expect(endedVotesCount(renderResult, "poutine")).toBe("0 votes"); expect(endedVotesCount(renderResult, "italian")).toBe("0 votes"); expect(endedVotesCount(renderResult, "wings")).toBe('
3 votes'); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 5 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 5 votes. Click here to see full results"); }); it("ignores votes that arrived after poll ended", async () => { @@ -577,7 +577,7 @@ describe("MPollBody", () => { expect(endedVotesCount(renderResult, "poutine")).toBe("0 votes"); expect(endedVotesCount(renderResult, "italian")).toBe("0 votes"); expect(endedVotesCount(renderResult, "wings")).toBe('
3 votes'); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 5 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 5 votes. Click here to see full results"); }); it("counts votes that arrived after an unauthorised poll end event", async () => { @@ -600,7 +600,7 @@ describe("MPollBody", () => { expect(endedVotesCount(renderResult, "poutine")).toBe("0 votes"); expect(endedVotesCount(renderResult, "italian")).toBe("0 votes"); expect(endedVotesCount(renderResult, "wings")).toBe('
3 votes'); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 5 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 5 votes. Click here to see full results"); }); it("ignores votes that arrived after the first end poll event", async () => { @@ -627,7 +627,7 @@ describe("MPollBody", () => { expect(endedVotesCount(renderResult, "poutine")).toBe("0 votes"); expect(endedVotesCount(renderResult, "italian")).toBe("0 votes"); expect(endedVotesCount(renderResult, "wings")).toBe('
3 votes'); - expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 5 votes"); + expect(renderResult.getByTestId("totalVotes").innerHTML).toBe("Final result based on 5 votes. Click here to see full results"); }); it("highlights the winning vote in an ended poll", async () => { diff --git a/test/unit-tests/components/views/messages/__snapshots__/MPollBody-test.tsx.snap b/test/unit-tests/components/views/messages/__snapshots__/MPollBody-test.tsx.snap index b24f80146d..80dc66b7c8 100644 --- a/test/unit-tests/components/views/messages/__snapshots__/MPollBody-test.tsx.snap +++ b/test/unit-tests/components/views/messages/__snapshots__/MPollBody-test.tsx.snap @@ -29,10 +29,26 @@ exports[`MPollBody renders a finished poll 1`] = ` > Pizza
-
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -61,10 +77,26 @@ exports[`MPollBody renders a finished poll 1`] = ` > Poutine
-
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -93,13 +125,29 @@ exports[`MPollBody renders a finished poll 1`] = ` > Italian
-
+
- 2 votes + style="display: flex;" + > +
+
+
+ +
+ 2 votes + +
@@ -128,10 +176,26 @@ exports[`MPollBody renders a finished poll 1`] = ` > Wings
-
- 1 vote +
+
+
+
+
+ + 1 vote + +
@@ -147,9 +211,12 @@ exports[`MPollBody renders a finished poll 1`] = `
- Final result based on 3 votes + + Final result based on 3 votes. Click here to see full results +
@@ -184,13 +251,29 @@ exports[`MPollBody renders a finished poll with multiple winners 1`] = ` > Pizza -
+
- 2 votes + style="display: flex;" + > +
+
+
+ +
+ 2 votes + +
@@ -219,10 +302,26 @@ exports[`MPollBody renders a finished poll with multiple winners 1`] = ` > Poutine
-
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -251,10 +350,26 @@ exports[`MPollBody renders a finished poll with multiple winners 1`] = ` > Italian -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -283,13 +398,29 @@ exports[`MPollBody renders a finished poll with multiple winners 1`] = ` > Wings -
+
- 2 votes + style="display: flex;" + > +
+
+
+ +
+ 2 votes + +
@@ -305,9 +436,12 @@ exports[`MPollBody renders a finished poll with multiple winners 1`] = `
- Final result based on 4 votes + + Final result based on 4 votes. Click here to see full results +
@@ -342,10 +476,26 @@ exports[`MPollBody renders a finished poll with no votes 1`] = ` > Pizza -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -374,10 +524,26 @@ exports[`MPollBody renders a finished poll with no votes 1`] = ` > Poutine -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -406,10 +572,26 @@ exports[`MPollBody renders a finished poll with no votes 1`] = ` > Italian -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -438,10 +620,26 @@ exports[`MPollBody renders a finished poll with no votes 1`] = ` > Wings -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -457,9 +655,12 @@ exports[`MPollBody renders a finished poll with no votes 1`] = `
- Final result based on 0 votes + + Final result based on 0 votes. Click here to see full results +
@@ -504,9 +705,15 @@ exports[`MPollBody renders a poll that I have not voted in 1`] = ` > Pizza -
+
+
+ +
+
Poutine
-
+
+
+ +
+
Italian
-
+
+
+ +
+
@@ -636,9 +855,15 @@ exports[`MPollBody renders a poll that I have not voted in 1`] = ` > Wings -
+
+
+ +
+
- 3 votes cast. Vote to see the results + + 3 votes cast. Vote to see the results +
@@ -704,10 +932,26 @@ exports[`MPollBody renders a poll with local, non-local and invalid votes 1`] = > Pizza -
- 1 vote +
+
+
+
+
+ + 1 vote + +
@@ -750,10 +994,26 @@ exports[`MPollBody renders a poll with local, non-local and invalid votes 1`] = > Poutine -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -796,10 +1056,26 @@ exports[`MPollBody renders a poll with local, non-local and invalid votes 1`] = > Italian -
- 3 votes +
+
+
+
+
+ + 3 votes + +
@@ -842,10 +1118,26 @@ exports[`MPollBody renders a poll with local, non-local and invalid votes 1`] = > Wings -
- 1 vote +
+
+
+
+
+ + 1 vote + +
@@ -865,9 +1157,12 @@ exports[`MPollBody renders a poll with local, non-local and invalid votes 1`] =
- Based on 5 votes + + Based on 5 votes. Click here to see full results +
@@ -912,9 +1207,15 @@ exports[`MPollBody renders a poll with no votes 1`] = ` > Pizza -
+
+
+ +
+
Poutine
-
+
+
+ +
+
Italian
-
+
+
+ +
+
Wings
-
+
+
+ +
+
- No votes cast + + No votes cast +
@@ -1112,10 +1434,26 @@ exports[`MPollBody renders a poll with only non-local votes 1`] = ` > Pizza -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -1158,10 +1496,26 @@ exports[`MPollBody renders a poll with only non-local votes 1`] = ` > Poutine -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -1204,10 +1558,26 @@ exports[`MPollBody renders a poll with only non-local votes 1`] = ` > Italian -
- 2 votes +
+
+
+
+
+ + 2 votes + +
@@ -1250,10 +1620,26 @@ exports[`MPollBody renders a poll with only non-local votes 1`] = ` > Wings -
- 1 vote +
+
+
+
+
+ + 1 vote + +
@@ -1273,9 +1659,12 @@ exports[`MPollBody renders a poll with only non-local votes 1`] = `
- Based on 3 votes + + Based on 3 votes. Click here to see full results +
@@ -1310,13 +1699,29 @@ exports[`MPollBody renders an undisclosed, finished poll 1`] = ` > Pizza -
+
- 2 votes + style="display: flex;" + > +
+
+
+ +
+ 2 votes + +
@@ -1345,10 +1750,26 @@ exports[`MPollBody renders an undisclosed, finished poll 1`] = ` > Poutine
-
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -1377,10 +1798,26 @@ exports[`MPollBody renders an undisclosed, finished poll 1`] = ` > Italian -
- 0 votes +
+
+
+
+
+ + 0 votes + +
@@ -1409,13 +1846,29 @@ exports[`MPollBody renders an undisclosed, finished poll 1`] = ` > Wings -
+
- 2 votes + style="display: flex;" + > +
+
+
+ +
+ 2 votes + +
@@ -1431,9 +1884,12 @@ exports[`MPollBody renders an undisclosed, finished poll 1`] = `
- Final result based on 4 votes + + Final result based on 4 votes. Click here to see full results +
@@ -1478,9 +1934,15 @@ exports[`MPollBody renders an undisclosed, unfinished poll 1`] = ` > Pizza -
+
+
+ +
+
@@ -1522,9 +1984,15 @@ exports[`MPollBody renders an undisclosed, unfinished poll 1`] = ` > Poutine -
+
+
+ +
+
Italian
-
+
+
+ +
+
Wings
-
+
+
+ +
+
- Results will be visible when the poll is ended + + Results will be visible when the poll is ended +