From 9a8545bf34eb875e17be26dbea8aed067ae1531a Mon Sep 17 00:00:00 2001 From: Kerry Date: Thu, 22 Dec 2022 10:29:11 +1300 Subject: [PATCH] Fix: Editing a poll will silently change it to a closed poll (#9809) * add failing test case * dont reset poll disclosure on editing --- .../views/elements/PollCreateDialog.tsx | 2 +- .../views/elements/PollCreateDialog-test.tsx | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/views/elements/PollCreateDialog.tsx b/src/components/views/elements/PollCreateDialog.tsx index 3d987c3d96..653d69864d 100644 --- a/src/components/views/elements/PollCreateDialog.tsx +++ b/src/components/views/elements/PollCreateDialog.tsx @@ -138,7 +138,7 @@ export default class PollCreateDialog extends ScrollableBaseModal a.trim()).filter((a) => !!a), - this.state.kind, + this.state.kind.name, ).serialize(); if (!this.props.editingMxEvent) { diff --git a/test/components/views/elements/PollCreateDialog-test.tsx b/test/components/views/elements/PollCreateDialog-test.tsx index 1459e501fc..fdfb4b50e7 100644 --- a/test/components/views/elements/PollCreateDialog-test.tsx +++ b/test/components/views/elements/PollCreateDialog-test.tsx @@ -252,6 +252,25 @@ describe("PollCreateDialog", () => { }, }); }); + + it("retains poll disclosure type when editing", () => { + const previousEvent: MatrixEvent = new MatrixEvent( + PollStartEvent.from("Poll Q", ["Answer 1", "Answer 2"], M_POLL_KIND_DISCLOSED).serialize(), + ); + previousEvent.event.event_id = "$prevEventId"; + + const dialog = mount( + , + ); + + changeValue(dialog, "Question or topic", "Poll Q updated"); + dialog.find("button").simulate("click"); + + const [, , eventType, sentEventContent] = mockClient.sendEvent.mock.calls[0]; + expect(M_POLL_START.matches(eventType)).toBeTruthy(); + // didnt change + expect(sentEventContent["m.new_content"][M_POLL_START.name].kind).toEqual(M_POLL_KIND_DISCLOSED.name); + }); }); function createRoom(): Room {