From dab34098f808a531a1c8df68517fba1ea49289fa Mon Sep 17 00:00:00 2001 From: Alasdair Wilson Date: Wed, 27 Nov 2024 11:43:14 +0000 Subject: [PATCH] fix component test from failing due to change in open close button behaviour --- components/content/Thread.tsx | 17 +++++++++-------- cypress/component/CommentThread.cy.tsx | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/components/content/Thread.tsx b/components/content/Thread.tsx index 3f370a3c..c2b0c8cf 100644 --- a/components/content/Thread.tsx +++ b/components/content/Thread.tsx @@ -104,17 +104,18 @@ const Thread = ({ thread, active, setActive, onDelete, finaliseThread }: ThreadP const calculatePosition = () => { if (triggerRef.current) { const rect = triggerRef.current.getBoundingClientRect() - const popupWidth = 355 // Adjust this value based on your actual popup width + console.log(rect) + const popupWidth = 355 const viewportWidth = window.innerWidth - let leftPosition = rect.right + 10 // Position to the right of the thread + let leftPosition = rect.left + 40 if (leftPosition + popupWidth > viewportWidth) { - // If the popup overflows the viewport, adjust to the left + // if the popup is going to expand the viewport then we move it to the left leftPosition = rect.left - popupWidth - 10 } setPopupPosition({ - top: rect.top + window.scrollY, // Account for vertical scroll + top: rect.top + window.scrollY, left: leftPosition, }) } @@ -124,7 +125,7 @@ const Thread = ({ thread, active, setActive, onDelete, finaliseThread }: ThreadP if (active) { calculatePosition() // Calculate the position when the popup is active } - }, [active]) // Recalculate when the active state changes + }, [active]) const sortedComments = useMemo(() => { if (!commentThread) return [] @@ -207,12 +208,12 @@ const Thread = ({ thread, active, setActive, onDelete, finaliseThread }: ThreadP const renderPopup = () => { if (!active) return null - + console.log(popupPosition) return createPortal(
@@ -243,7 +244,7 @@ const Thread = ({ thread, active, setActive, onDelete, finaliseThread }: ThreadP

{}

- setActive(false)}> + setActive(false)}> {!isPlaceholder && ( diff --git a/cypress/component/CommentThread.cy.tsx b/cypress/component/CommentThread.cy.tsx index ace674c1..80af89ba 100644 --- a/cypress/component/CommentThread.cy.tsx +++ b/cypress/component/CommentThread.cy.tsx @@ -106,8 +106,8 @@ describe("CommentThread component", () => { ) }) - it("should open and close the thread", () => { - cy.get('[data-cy="Thread:1:OpenCloseButton"]').click() + it("should close the thread", () => { + cy.get('[data-cy="Thread:1:CloseButton"]').click() cy.get("@setActive").should("be.calledWith", false) })