From ece3d508a2a43b4bca281ebf03633d0be49271f5 Mon Sep 17 00:00:00 2001 From: Archit Sehgal <72187362+ar-chit@users.noreply.github.com> Date: Fri, 6 Jun 2025 00:15:47 +0530 Subject: [PATCH] fix: back button in survey published modal closes modal instead of navigating (#5831) Co-authored-by: Matthias Nannt --- .../components/ShareEmbedSurvey.test.tsx | 20 +++++++++++++++---- .../summary/components/ShareEmbedSurvey.tsx | 2 +- .../[surveyId]/(analysis)/summary/page.tsx | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.test.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.test.tsx index 8256aa52b2..fc91d7849a 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.test.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.test.tsx @@ -174,20 +174,32 @@ describe("ShareEmbedSurvey", () => { expect(screen.getByText("PanelInfoViewMockContent")).toBeInTheDocument(); }); - test("calls setOpen(false) when handleInitialPageButton is triggered from EmbedView", async () => { + test("returns to 'start' view when handleInitialPageButton is triggered from EmbedView", async () => { render(); expect(mockEmbedViewComponent).toHaveBeenCalled(); + expect(screen.getByText("EmbedViewMockContent")).toBeInTheDocument(); + const embedViewButton = screen.getByText("EmbedViewMockContent"); await userEvent.click(embedViewButton); - expect(mockSetOpen).toHaveBeenCalledWith(false); + + // Should go back to start view, not close the modal + expect(screen.getByText("environments.surveys.summary.your_survey_is_public 🎉")).toBeInTheDocument(); + expect(screen.queryByText("EmbedViewMockContent")).not.toBeInTheDocument(); + expect(mockSetOpen).not.toHaveBeenCalled(); }); - test("calls setOpen(false) when handleInitialPageButton is triggered from PanelInfoView", async () => { + test("returns to 'start' view when handleInitialPageButton is triggered from PanelInfoView", async () => { render(); expect(mockPanelInfoViewComponent).toHaveBeenCalled(); + expect(screen.getByText("PanelInfoViewMockContent")).toBeInTheDocument(); + const panelInfoViewButton = screen.getByText("PanelInfoViewMockContent"); await userEvent.click(panelInfoViewButton); - expect(mockSetOpen).toHaveBeenCalledWith(false); + + // Should go back to start view, not close the modal + expect(screen.getByText("environments.surveys.summary.your_survey_is_public 🎉")).toBeInTheDocument(); + expect(screen.queryByText("PanelInfoViewMockContent")).not.toBeInTheDocument(); + expect(mockSetOpen).not.toHaveBeenCalled(); }); test("handleOpenChange (when Dialog calls its onOpenChange prop)", () => { diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx index 7dcfb7bc1b..199592775f 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx @@ -86,7 +86,7 @@ export const ShareEmbedSurvey = ({ }; const handleInitialPageButton = () => { - setOpen(false); + setShowView("start"); }; return ( diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page.tsx index 5fbdce4c07..78b3fb464f 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page.tsx @@ -68,7 +68,7 @@ const SurveyPage = async (props: { params: Promise<{ environmentId: string; surv initialSurveySummary={initialSurveySummary} /> - + ); };