Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/components/views/polls/pollHistory/PollListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,31 @@ interface Props {

export const PollListItem: React.FC<Props> = ({ event, onClick }) => {
const pollEvent = event.unstableExtensibleEvent as unknown as PollStartEvent;
const [showTooltip, setShowTooltip] = React.useState(false);

if (!pollEvent) {
return null;
}
const formattedDate = formatLocalDateShort(event.getTs());

return (
<li data-testid={`pollListItem-${event.getId()!}`} className="mx_PollListItem" onClick={onClick}>
<Tooltip label={_t("right_panel|poll|view_poll")} placement="top" isTriggerInteractive={false}>
<div className="mx_PollListItem_content">
<span>{formattedDate}</span>
<PollIcon className="mx_PollListItem_icon" />
<div
className="mx_PollListItem_content"
onMouseEnter={() => setShowTooltip(true)}
onMouseLeave={() => setShowTooltip(false)}
>
<span>{formattedDate}</span>
<PollIcon className="mx_PollListItem_icon" />
<Tooltip
label={_t("right_panel|poll|view_poll")}
placement="top"
isTriggerInteractive={false}
open={showTooltip}
>
<span className="mx_PollListItem_question">{pollEvent.question.text}</span>
</div>
</Tooltip>
</Tooltip>
</div>
</li>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,20 @@ describe("<PollListItem />", () => {

expect(onClick).toHaveBeenCalled();
});

it("handles tooltip mouse events", () => {
const { container } = getComponent();
const contentDiv = container.querySelector(".mx_PollListItem_content");
const questionSpan = container.querySelector(".mx_PollListItem_question");

expect(contentDiv).toBeTruthy();
expect(questionSpan?.textContent).toBe("Question?");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's really relevant to this test to assert these things, or why we need the question div at all. We also really ought to be selecting things by role, or testId if that really isn't possible. In this case, this raises the question of why the inner div is necessary now that the tooltip is on something inside it: then we could just have the mouseenter/leave be on the li and select it using getByRole("listitem", { name: "01/01/70 Question?" }).

Copy link
Author

@Mirzaian Mirzaian Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oki, I moved the mouse events to the li element and added the aria-label. I also added getByRole as you suggested.


// Test that mouse events work without error
fireEvent.mouseEnter(contentDiv!);
fireEvent.mouseLeave(contentDiv!);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise the rest of the test doesn't, so not a blocker, but new code probably ought to use user-event.


// Component should still be functional after state changes
expect(container.querySelector(".mx_PollListItem")).toBeTruthy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test really needs to assert that the tooltip actually appears.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oki, I replaced the querySelector approach with proper tooltip text assertion.

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -87,51 +87,51 @@ exports[`<PollHistory /> renders a list of active polls when there are polls in
class="mx_PollListItem"
data-testid="pollListItem-$2"
>
<span
tabindex="0"
<div
class="mx_PollListItem_content"
>
<span>
02/02/23
</span>
<div
aria-labelledby="_r_a_"
class="mx_PollListItem_content"
class="mx_PollListItem_icon"
/>
<span
tabindex="0"
>
<span>
02/02/23
</span>
<div
class="mx_PollListItem_icon"
/>
<span
aria-labelledby="_r_a_"
class="mx_PollListItem_question"
>
Where?
</span>
</div>
</span>
</span>
</div>
</li>
<li
class="mx_PollListItem"
data-testid="pollListItem-$1"
>
<span
tabindex="0"
<div
class="mx_PollListItem_content"
>
<span>
02/02/23
</span>
<div
aria-labelledby="_r_f_"
class="mx_PollListItem_content"
class="mx_PollListItem_icon"
/>
<span
tabindex="0"
>
<span>
02/02/23
</span>
<div
class="mx_PollListItem_icon"
/>
<span
aria-labelledby="_r_f_"
class="mx_PollListItem_question"
>
Question?
</span>
</div>
</span>
</span>
</div>
</li>
</ol>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ exports[`<PollListItem /> renders a poll 1`] = `
class="mx_PollListItem"
data-testid="pollListItem-$mypoll"
>
<span
tabindex="0"
<div
class="mx_PollListItem_content"
>
<span>
01/01/70
</span>
<div
aria-labelledby="_r_0_"
class="mx_PollListItem_content"
class="mx_PollListItem_icon"
/>
<span
tabindex="0"
>
<span>
01/01/70
</span>
<div
class="mx_PollListItem_icon"
/>
<span
aria-labelledby="_r_0_"
class="mx_PollListItem_question"
>
Question?
</span>
</div>
</span>
</span>
</div>
</li>
</div>
`;