Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make callback on confirmation message instead #1845

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lucasheriques
Copy link
Contributor

@lucasheriques lucasheriques commented Mar 21, 2025

Changes

after I fix I did for this issue, it introduced a bug for feedback surveys where the confirmation message is not shown for feedback survey since it's being closed in the same instant.

so, this PR does two things:

  • address it so the reset for the feedback widget popup happens when the survey is closed
  • creates an end to end test to make sure this error doesn't happen again

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Mar 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Mar 22, 2025 1:46am

Copy link

github-actions bot commented Mar 21, 2025

Size Change: -342 B (-0.01%)

Total Size: 3.63 MB

Filename Size Change
dist/all-external-dependencies.js 220 kB -23 B (-0.01%)
dist/array.full.es5.js 301 kB -58 B (-0.02%)
dist/array.full.js 381 kB -23 B (-0.01%)
dist/array.full.no-external.js 380 kB -23 B (-0.01%)
dist/array.js 188 kB -25 B (-0.01%)
dist/array.no-external.js 187 kB -25 B (-0.01%)
dist/main.js 189 kB -25 B (-0.01%)
dist/module.full.js 381 kB -23 B (-0.01%)
dist/module.full.no-external.js 380 kB -23 B (-0.01%)
dist/module.js 189 kB -25 B (-0.01%)
dist/module.no-external.js 187 kB -25 B (-0.01%)
dist/surveys-preview.js 71.3 kB -22 B (-0.03%)
dist/surveys.js 76.6 kB -22 B (-0.03%)
ℹ️ View Unchanged
Filename Size
dist/customizations.full.js 14.1 kB
dist/dead-clicks-autocapture.js 14.5 kB
dist/exception-autocapture.js 9.94 kB
dist/external-scripts-loader.js 2.75 kB
dist/posthog-recorder.js 211 kB
dist/recorder-v2.js 115 kB
dist/recorder.js 115 kB
dist/tracing-headers.js 1.76 kB
dist/web-vitals.js 10.4 kB

compressed-size-action

@lucasheriques lucasheriques self-assigned this Mar 22, 2025
@lucasheriques lucasheriques added feature/surveys bump patch Bump patch version when this PR gets merged labels Mar 22, 2025
@lucasheriques lucasheriques marked this pull request as ready for review March 22, 2025 01:46
@lucasheriques lucasheriques requested a review from a team as a code owner March 22, 2025 01:46
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR fixes a bug where feedback survey confirmation messages were closing prematurely by moving the survey reset functionality to trigger on confirmation message close instead of survey submission.

  • Added new test in src/__tests__/extensions/surveys/survey-popup.test.tsx to verify onCloseConfirmationMessage callback behavior
  • Removed onPopupSurveySent from SurveyContext in src/extensions/surveys/surveys-utils.tsx in favor of confirmation message close handler
  • Added comprehensive end-to-end test in playwright/surveys/feedback-widget.spec.ts for multiple survey submissions with thank you messages
  • Improved accessibility in BottomSection.tsx and QuestionHeader.tsx with proper ARIA attributes

7 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

previewPageIndex={mockSurvey.questions.length}
/>
)
const cancelButton2 = screen.getByRole('button', { name: 'Close survey', hidden: true })
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The button name 'Close survey' doesn't match the actual button text 'Close' defined in mockSurvey.appearance.thankYouMessageCloseButtonText

Suggested change
const cancelButton2 = screen.getByRole('button', { name: 'Close survey', hidden: true })
const cancelButton2 = screen.getByRole('button', { name: mockSurvey.appearance.thankYouMessageCloseButtonText, hidden: true })

// Click the cancel button
fireEvent.click(cancelButton2)
// Verify that onCloseConfirmationMessage was called
expect(mockOnCloseConfirmationMessage).toHaveBeenCalledTimes(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Should also verify mockRemoveSurveyFromFocus was called to ensure proper cleanup

Comment on lines 819 to 821
if (nextStep === SurveyQuestionBranchingType.End) {
sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)
onPopupSurveySent()
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Survey sent event is triggered but confirmation state is not set. Add setIsSurveySent(true) here to ensure confirmation message shows.

Suggested change
if (nextStep === SurveyQuestionBranchingType.End) {
sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)
onPopupSurveySent()
} else {
if (nextStep === SurveyQuestionBranchingType.End) {
sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)
window.dispatchEvent(new Event('PHSurveySent'))
} else {

Comment on lines +215 to +248
// ... existing code ...
test('auto contrasts text color for feedback tab', async ({ page, context }) => {
const surveysAPICall = page.route('**/surveys/**', async (route) => {
await route.fulfill({
json: {
surveys: [
{
id: '123',
name: 'Test survey',
type: 'widget',
start_date: '2021-01-01T00:00:00Z',
questions: [openTextQuestion],
appearance: {
widgetLabel: 'white widget',
widgetType: 'tab',
widgetColor: 'white',
},
},
],
},
})
})

await start(startOptions, page, context)
await surveysAPICall

await expect(page.locator('.PostHogWidget123').locator('.ph-survey-widget-tab')).toBeVisible()

await expect(page.locator('.PostHogWidget123').locator('.ph-survey-widget-tab')).toHaveCSS('color', black)
await expect(page.locator('.PostHogWidget123').locator('.ph-survey-widget-tab')).toHaveCSS(
'background-color',
white
)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This test is a duplicate of the previous 'auto contrasts text color for feedback tab' test. Should be removed to avoid redundant test coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch Bump patch version when this PR gets merged feature/surveys
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant