Skip to content

Commit 61b052c

Browse files
author
am
committed
fix(messages): exclude non-primary contacts from image click zoom
Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz>
1 parent 29ed325 commit 61b052c

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

‎src/features/messages/ImageReviewStage.test.tsx‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function press(target: HTMLElement, from: { x: number; y: number }, to = from) {
4848
fireEvent.pointerDown(target, {
4949
pointerId: 1,
5050
button: 0,
51+
isPrimary: true,
5152
clientX: from.x,
5253
clientY: from.y,
5354
});
@@ -726,7 +727,7 @@ it("does not zoom any gallery image with a press held across navigation", () =>
726727
const image = screen.getByRole("img", { name: "Attachment preview" });
727728
const stage = image.parentElement;
728729
if (!stage) throw new Error("Missing stage");
729-
fireEvent.pointerDown(image, { pointerId: 1, button: 0 });
730+
fireEvent.pointerDown(image, { pointerId: 1, button: 0, isPrimary: true });
730731
fireEvent.click(screen.getByRole("button", { name: "Next image" }));
731732
expect(screen.getByText("2 / 3")).toBeVisible();
732733
fireEvent.pointerUp(stage, { pointerId: 1 });
@@ -737,6 +738,7 @@ it("does not zoom any gallery image with a press held across navigation", () =>
737738
{
738739
pointerId: 1,
739740
button: 0,
741+
isPrimary: true,
740742
},
741743
);
742744
fireEvent.click(screen.getByRole("button", { name: "Previous image" }));
@@ -760,7 +762,12 @@ it.each([
760762
(_, order) => {
761763
const { stage, image } = setup();
762764
for (const pointerId of [1, 2])
763-
fireEvent.pointerDown(image, { pointerId, button: 0, clientX: 250 });
765+
fireEvent.pointerDown(image, {
766+
pointerId,
767+
button: 0,
768+
isPrimary: pointerId === 1,
769+
clientX: 250,
770+
});
764771
for (const pointerId of order)
765772
fireEvent.pointerUp(stage, { pointerId, clientX: 250 });
766773
expect(percent()).toBe("100%");
@@ -769,15 +776,41 @@ it.each([
769776
},
770777
);
771778

779+
it("does not click-zoom a non-primary image contact without a stage-owned press", () => {
780+
const { stage, image } = setup();
781+
// The primary contact may be on the toolbar or outside this stage.
782+
fireEvent.pointerDown(image, {
783+
pointerId: 2,
784+
button: 0,
785+
isPrimary: false,
786+
clientX: 250,
787+
clientY: 200,
788+
});
789+
fireEvent.pointerUp(stage, { pointerId: 2, clientX: 250, clientY: 200 });
790+
expect(percent()).toBe("100%");
791+
press(image, { x: 250, y: 200 });
792+
expect(percent()).toBe("200%");
793+
});
794+
772795
it.each(["pointerCancel", "lostPointerCapture"] as const)(
773796
"ends only the owning press on %s",
774797
(type) => {
775798
const { stage, image } = setup();
776-
fireEvent.pointerDown(image, { pointerId: 1, button: 0, clientX: 250 });
799+
fireEvent.pointerDown(image, {
800+
pointerId: 1,
801+
button: 0,
802+
isPrimary: true,
803+
clientX: 250,
804+
});
777805
fireEvent[type](stage, { pointerId: 2 });
778806
fireEvent.pointerUp(stage, { pointerId: 1, clientX: 250 });
779807
expect(percent()).toBe("200%");
780-
fireEvent.pointerDown(image, { pointerId: 1, button: 0, clientX: 250 });
808+
fireEvent.pointerDown(image, {
809+
pointerId: 1,
810+
button: 0,
811+
isPrimary: true,
812+
clientX: 250,
813+
});
781814
fireEvent[type](stage, { pointerId: 1 });
782815
fireEvent.pointerUp(stage, { pointerId: 1, clientX: 250 });
783816
expect(percent()).toBe("200%");

‎src/features/messages/ImageReviewStage.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export function ImageReviewStage({
247247
origin: { x: event.clientX, y: event.clientY },
248248
offset,
249249
panning: pannable,
250-
click: event.target === image.current,
250+
click: event.isPrimary && event.target === image.current,
251251
};
252252
// Capture so the release always ends this press, even off the stage.
253253
event.currentTarget.setPointerCapture(event.pointerId);

‎src/features/messages/MediaReviewViewer.motion.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ it("settles the entrance immediately when the user interacts", () => {
211211
screen.getByRole("link", { name: "Open image attachment" }),
212212
{ detail: 1 },
213213
);
214-
fireEvent.pointerDown(screen.getByRole("dialog"));
214+
fireEvent.pointerDown(screen.getByRole("dialog"), { button: 2 });
215215
expect(cancel).toHaveBeenCalledTimes(animate.mock.calls.length);
216216
} finally {
217217
release();
@@ -490,7 +490,7 @@ it.each(["image", "video"] as const)(
490490
expect(animate.mock.calls[start]?.[1]).not.toHaveProperty("fill");
491491
expect(dialog).toHaveAttribute("data-review-resizing");
492492
// A zoom or seek interaction must retire the temporary layout transform.
493-
fireEvent.pointerDown(media);
493+
fireEvent.pointerDown(media, { button: 2 });
494494
expect(dialog).not.toHaveAttribute("data-review-resizing");
495495
fireEvent.click(screen.getByRole("button", { name: "Show comments" }), {
496496
detail: 1,

0 commit comments

Comments
 (0)