Skip to content

Commit 85868a3

Browse files
authored
fix: reset PollComposer state on poll creation form submission (#2795)
1 parent 39672fe commit 85868a3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/components/Poll/PollCreationDialog/PollCreationDialogControls.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export const PollCreationDialogControls = ({
3333
messageComposer
3434
.createPoll()
3535
.then(() => handleSubmitMessage())
36-
.then(close)
36+
.then(() => {
37+
messageComposer.pollComposer.initState();
38+
close();
39+
})
3740
.catch(console.error);
3841
}}
3942
type='submit'

src/components/Poll/__tests__/PollCreationDialog.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ describe('PollCreationDialog', () => {
363363
const createPollSpy = jest
364364
.spyOn(client, 'createPoll')
365365
.mockImplementationOnce(() => Promise.resolve({ poll }));
366+
const initPollStateSpy = jest
367+
.spyOn(channel.messageComposer.pollComposer, 'initState')
368+
.mockImplementation();
366369

367370
await act(async () => {
368371
await fireEvent.change(getNameInput(), { target: { value: formState.name } });
@@ -407,14 +410,25 @@ describe('PollCreationDialog', () => {
407410
expect.objectContaining(expectedPollPayload),
408411
);
409412
expect(close).toHaveBeenCalledTimes(1);
413+
expect(initPollStateSpy).toHaveBeenCalledTimes(1);
410414
});
411415
});
412416

413417
it('closes the form on cancel', async () => {
414-
await renderComponent();
418+
const {
419+
channels: [channel],
420+
client,
421+
} = await initClientWithChannels({ customUser: user });
422+
const initPollStateSpy = jest
423+
.spyOn(channel.messageComposer.pollComposer, 'initState')
424+
.mockImplementation();
425+
426+
await renderComponent({ channel, client });
427+
415428
act(() => {
416429
fireEvent.click(screen.getByText(CANCEL_BUTTON_TEXT));
417430
});
418431
expect(close).toHaveBeenCalledTimes(1);
432+
expect(initPollStateSpy).toHaveBeenCalledTimes(1);
419433
});
420434
});

0 commit comments

Comments
 (0)