Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
29 changes: 22 additions & 7 deletions src/components/views/polls/pollHistory/PollListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,34 @@ 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" />
<li
data-testid={`pollListItem-${event.getId()!}`}
className="mx_PollListItem"
onClick={onClick}
onMouseEnter={() => setShowTooltip(true)}
onMouseLeave={() => setShowTooltip(false)}
aria-label={`${formattedDate} ${pollEvent.question.text}`}
>
<div className="mx_PollListItem_content">
<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 @@ -9,6 +9,7 @@
import React from "react";
import { fireEvent, render } from "jest-matrix-react";
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
import userEvent from "@testing-library/user-event";

import { PollListItem } from "../../../../../../src/components/views/polls/pollHistory/PollListItem";
import { makePollStartEvent, mockIntlDateTimeFormat, unmockIntlDateTimeFormat } from "../../../../../test-utils";
Expand All @@ -30,7 +31,7 @@

it("renders a poll", () => {
const { container } = getComponent();
expect(container).toMatchSnapshot();

Check failure on line 34 in test/unit-tests/components/views/polls/pollHistory/PollListItem-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (Element Web) (2)

<PollListItem /> › renders a poll

expect(received).toMatchSnapshot() Snapshot name: `<PollListItem /> renders a poll 1` - Snapshot - 0 + Received + 1 @@ -1,7 +1,8 @@ <div> <li + aria-label="01/01/70 Question?" class="mx_PollListItem" data-testid="pollListItem-$mypoll" > <div class="mx_PollListItem_content" at Object.toMatchSnapshot (test/unit-tests/components/views/polls/pollHistory/PollListItem-test.tsx:34:27)
});

it("renders null when event does not have an extensible poll start event", () => {
Expand All @@ -50,4 +51,20 @@

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

it("shows and hides tooltip on hover", async () => {
const user = userEvent.setup();
const { getByRole, getByText } = getComponent();
const listItem = getByRole("listitem", { name: "01/01/70 Question?" });

// Verify tooltip content is present
const tooltip = getByText("View poll");
expect(tooltip).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this not be in the document at this point? Or at least not be visible? And shouldn't we be testing that's visible when hovering and then disappears again?

Copy link
Author

Choose a reason for hiding this comment

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

I have updated it now and aligned it with the approach used in infotooltip-test.tsx


// Test that hover and unhover interactions work
await user.hover(listItem);
await user.unhover(listItem);

expect(tooltip).toBeInTheDocument();
});
});
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>
`;
Loading