Skip to content
Merged
Changes from all 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
38 changes: 27 additions & 11 deletions packages/stacks-svelte/src/components/Popover/Popover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const defaultProps = {
id: "test",
};

const waitForFloatingPosition = () =>
new Promise<void>((resolve) => {
requestAnimationFrame(() => {
requestAnimationFrame(() => resolve());
});
});

const stubHoverSupport = (initialMatches: boolean) => {
let matches = initialMatches;
const listeners = new Set<(event: MediaQueryListEvent) => void>();
Expand Down Expand Up @@ -655,13 +662,6 @@ describe("Popover", () => {
it("should shift the popover content horizontally when it would overflow the viewport", async () => {
await setViewport({ width: 260, height: 260 });

const waitForFloatingPosition = () =>
new Promise<void>((resolve) => {
requestAnimationFrame(() => {
requestAnimationFrame(() => resolve());
});
});

render(Popover, {
props: {
...defaultProps,
Expand Down Expand Up @@ -1864,6 +1864,8 @@ describe("Popover", () => {

it("keeps the tooltip open while selecting text after focusing its trigger", async () => {
const clock = sinon.useFakeTimers({
// Drive dismissal timers while letting the browser lay out real frames.
toFake: ["setTimeout", "clearTimeout"],
shouldAdvanceTime: true,
shouldClearNativeTimers: true,
});
Expand All @@ -1884,12 +1886,23 @@ describe("Popover", () => {
await clock.runAllAsync();
await tick();
const text = screen.getByText("Popover Content");
const { left, right, top, height } = text.getBoundingClientRect();
const y = Math.round(top + height / 2);
await waitFor(async () => {
const before = text.getBoundingClientRect().toJSON();
await waitForFloatingPosition();
expect(text.getBoundingClientRect().toJSON()).to.deep.equal(
before
);
});
const lines = text.getClientRects();
const first = lines[0];
const last = lines[lines.length - 1];
try {
await sendMouse({
type: "move",
position: [Math.ceil(left), y],
position: [
Math.ceil(first.left),
Math.round(first.top + first.height / 2),
],
});
await sendMouse({ type: "down" });
await clock.runAllAsync();
Expand All @@ -1898,7 +1911,10 @@ describe("Popover", () => {

await sendMouse({
type: "move",
position: [Math.floor(right), y],
position: [
Math.floor(last.right),
Math.round(last.top + last.height / 2),
],
});
await sendMouse({ type: "up" });
expect(window.getSelection()?.toString()).to.equal(
Expand Down