Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(polls-history): correct poll ID extraction and persist deletions (#18145)

Muneebadf0f93fb2d3
diff --git a/react/features/polls-history/middleware.ts b/react/features/polls-history/middleware.ts
index 367d51babb..2e05873725 100644
--- a/react/features/polls-history/middleware.ts
+++ b/react/features/polls-history/middleware.ts
@@ -28,16 +28,20 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
}
case REMOVE_POLL: {
- const { poll, pollId } = action;
+ const { poll } = action;
- dispatch(removePollFromHistory(meetingId, pollId, poll));
+ if (meetingId) {
+ dispatch(removePollFromHistory(meetingId, poll.pollId, poll));
+ }
break;
}
case SAVE_POLL: {
- const { poll, pollId } = action;
+ const { poll } = action;
- dispatch(savePollInHistory(meetingId, pollId, poll));
+ if (meetingId) {
+ dispatch(savePollInHistory(meetingId, poll.pollId, poll));
+ }
break;
}
}
diff --git a/react/features/polls-history/reducer.ts b/react/features/polls-history/reducer.ts
index 960e916558..f3626b3b95 100644
--- a/react/features/polls-history/reducer.ts
+++ b/react/features/polls-history/reducer.ts
@@ -24,13 +24,32 @@ ReducerRegistry.register<IPollsHistoryState>(STORE_NAME, (state = INITIAL_STATE,
switch (action.type) {
case REMOVE_POLL_FROM_HISTORY: {
- if (Object.keys(state.polls[action.meetingId] ?? {})?.length === 1) {
- delete state.polls[action.meetingId];
- } else {
- delete state.polls[action.meetingId]?.[action.pollId];
+ const meetingPolls = state.polls[action.meetingId];
+
+ if (!meetingPolls || !action.pollId || !(action.pollId in meetingPolls)) {
+ return state;
}
- return state;
+ if (Object.keys(meetingPolls).length === 1) {
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ const { [action.meetingId]: _removedMeeting, ...newPolls } = state.polls;
+
+ return {
+ ...state,
+ polls: newPolls
+ };
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ const { [action.pollId]: _removedPoll, ...newMeetingPolls } = meetingPolls;
+
+ return {
+ ...state,
+ polls: {
+ ...state.polls,
+ [action.meetingId]: newMeetingPolls
+ }
+ };
}
case SAVE_POLL_IN_HISTORY: {
diff --git a/tests/pageobjects/ChatPanel.ts b/tests/pageobjects/ChatPanel.ts
index 041552890e..8d06b1543c 100644
--- a/tests/pageobjects/ChatPanel.ts
+++ b/tests/pageobjects/ChatPanel.ts
@@ -64,6 +64,19 @@ export default class ChatPanel extends BasePageObject {
});
}
+ /**
+ * Waits for the new poll input to disappear.
+ */
+ async waitForNewPollInputNonExisting() {
+ await this.participant.driver.$(
+ '#polls-create-input')
+ .waitForExist({
+ reverse: true,
+ timeout: 2000,
+ timeoutMsg: 'New poll input still exists'
+ });
+ }
+
/**
* Waits for the option input to be visible.
* @param index
@@ -196,6 +209,24 @@ export default class ChatPanel extends BasePageObject {
return this.participant.driver.$(`#poll-${pollId}`).isDisplayed();
}
+ /**
+ * Clicks the close button of the given saved poll and waits for the poll to disappear.
+ * @param pollId
+ */
+ async closePoll(pollId: string) {
+ const closeButton = this.participant.driver.$(`#poll-${pollId} [aria-label="Close poll"]`);
+
+ await closeButton.scrollIntoView();
+ await closeButton.waitForClickable({ timeout: 2000 });
+ await closeButton.click();
+
+ await this.participant.driver.$(`#poll-${pollId}`).waitForExist({
+ reverse: true,
+ timeout: 3000,
+ timeoutMsg: `Poll ${pollId} still visible`
+ });
+ }
+
/**
* Gets the result text for the given option in the given poll.
* @param pollId
diff --git a/tests/specs/misc/polls.spec.ts b/tests/specs/misc/polls.spec.ts
index 4e8b06cbc2..7b758a97df 100644
--- a/tests/specs/misc/polls.spec.ts
+++ b/tests/specs/misc/polls.spec.ts
@@ -131,4 +131,110 @@ describe('Polls', () => {
expect(await p2.getChatPanel().getResult(pollId, 0)).toBe('1 (100%)');
});
+
+ it('save multiple polls in history and persist deletion', async () => {
+ const { p1 } = ctx;
+
+ if (!await p1.getChatPanel().isOpen()) {
+ await p1.getToolbar().clickChatButton();
+ }
+ if (!await p1.getChatPanel().isPollsTabVisible()) {
+ await p1.getChatPanel().openPollsTab();
+ }
+
+ const createAndSavePoll = async (question: string, opt1: string, opt2: string) => {
+ await p1.getChatPanel().clickCreatePollButton();
+ await p1.getChatPanel().waitForNewPollInput();
+ await p1.getChatPanel().fillPollQuestion(question);
+ await p1.getChatPanel().waitForOptionInput(0);
+ await p1.getChatPanel().waitForOptionInput(1);
+ await p1.getChatPanel().fillPollOption(0, opt1);
+ await p1.getChatPanel().fillPollOption(1, opt2);
+ await p1.getChatPanel().clickSavePollButton();
+ await p1.getChatPanel().waitForNewPollInputNonExisting();
+ await p1.getChatPanel().waitForSendButton();
+ };
+
+ // 1. Create and save two distinct draft polls.
+ await createAndSavePoll('Question Alpha', 'Option 1', 'Option 2');
+ await createAndSavePoll('Question Beta', 'Option 1', 'Option 2');
+
+ // 2. Resolve actual poll IDs by question content (no dictionary ordering assumption).
+ const getPollIdByQuestion = async (questionText: string): Promise<string> => {
+ const pollId: string = await p1.driver.waitUntil(async () => {
+ const id: string | undefined = await p1.driver.execute((q: string) => {
+ const polls = APP.store.getState()['features/polls']?.polls || {};
+ const match = Object.values(polls).find((p: any) => p.question === q);
+
+ return match?.pollId;
+ }, questionText);
+
+ return id || false;
+ }, {
+ timeout: 3000,
+ timeoutMsg: `Could not find saved poll with question: "${questionText}"`
+ });
+
+ return pollId;
+ };
+
+ const pollAlphaId = await getPollIdByQuestion('Question Alpha');
+ const pollBetaId = await getPollIdByQuestion('Question Beta');
+
+ expect(pollAlphaId).toBeDefined();
+ expect(pollBetaId).toBeDefined();
+ expect(pollAlphaId).not.toBe(pollBetaId);
+
+ // 3. Verify both distinct poll IDs exist in history and no "undefined" key exists.
+ const history = await p1.driver.execute(() => {
+ const state = APP.store.getState();
+ const room = state['features/base/conference'].room;
+
+ return state['features/polls-history']?.polls?.[room] || {};
+ });
+
+ expect(history[pollAlphaId]).toBeDefined();
+ expect(history[pollBetaId]).toBeDefined();
+ expect(history.undefined).toBeUndefined();
+ expect(Object.keys(history).includes('undefined')).toBe(false);
+
+ // 4. Remove Poll Alpha via UI close button.
+ await p1.getChatPanel().closePoll(pollAlphaId);
+ expect(await p1.getChatPanel().isPollVisible(pollBetaId)).toBe(true);
+
+ // 5. Verify Poll Alpha is removed from store while Poll Beta remains.
+ await p1.driver.waitUntil(async () => {
+ const h = await p1.driver.execute(() => {
+ const state = APP.store.getState();
+ const room = state['features/base/conference'].room;
+
+ return state['features/polls-history']?.polls?.[room] || {};
+ });
+
+ return !(pollAlphaId in h) && (pollBetaId in h);
+ }, {
+ timeout: 3000,
+ timeoutMsg: 'Poll Alpha was not removed from polls-history store'
+ });
+
+ // 6. Verify deletion persistence in localStorage.
+ await p1.driver.waitUntil(async () => {
+ const persisted = await p1.driver.execute(() => {
+ const raw = localStorage.getItem('features/polls-history');
+
+ if (!raw) {
+ return null;
+ }
+ const state = JSON.parse(raw);
+ const room = APP.store.getState()['features/base/conference'].room;
+
+ return state.polls?.[room] || {};
+ });
+
+ return persisted && !(pollAlphaId in persisted) && (pollBetaId in persisted);
+ }, {
+ timeout: 5000,
+ timeoutMsg: 'Poll Alpha deletion was not persisted to localStorage'
+ });
+ });
});