-
Notifications
You must be signed in to change notification settings - Fork 146
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,87 @@ | ||||||
import '@testing-library/jest-dom' | ||||||
import { cleanup, fireEvent, render, screen } from '@testing-library/preact' | ||||||
import { SurveyPopup } from '../../../extensions/surveys' | ||||||
import { Survey, SurveyQuestionType, SurveyType } from '../../../posthog-surveys-types' | ||||||
|
||||||
describe('SurveyPopup', () => { | ||||||
// Create a basic mock survey for testing | ||||||
const mockSurvey: Survey = { | ||||||
id: 'test-survey', | ||||||
name: 'Test Survey', | ||||||
description: 'A test survey', | ||||||
type: SurveyType.Popover, | ||||||
feature_flag_keys: null, | ||||||
linked_flag_key: null, | ||||||
targeting_flag_key: null, | ||||||
internal_targeting_flag_key: null, | ||||||
questions: [ | ||||||
{ | ||||||
type: SurveyQuestionType.Open, | ||||||
question: 'Test question', | ||||||
description: 'Test description', | ||||||
id: 'q1', | ||||||
}, | ||||||
], | ||||||
appearance: { | ||||||
displayThankYouMessage: true, | ||||||
thankYouMessageHeader: 'Thank you for your feedback!', | ||||||
thankYouMessageDescription: 'We appreciate your input.', | ||||||
backgroundColor: '#ffffff', | ||||||
borderColor: '#e5e5e5', | ||||||
thankYouMessageCloseButtonText: 'Close', | ||||||
whiteLabel: true, | ||||||
}, | ||||||
conditions: null, | ||||||
start_date: null, | ||||||
end_date: null, | ||||||
current_iteration: null, | ||||||
current_iteration_start_date: null, | ||||||
schedule: null, | ||||||
} | ||||||
|
||||||
beforeEach(() => { | ||||||
// Reset DOM | ||||||
cleanup() | ||||||
localStorage.clear() | ||||||
jest.clearAllMocks() | ||||||
}) | ||||||
|
||||||
test('calls onCloseConfirmationMessage when X button is clicked in the confirmation message', () => { | ||||||
// Create a mock function to test if it gets called | ||||||
const mockOnCloseConfirmationMessage = jest.fn() | ||||||
const mockRemoveSurveyFromFocus = jest.fn() | ||||||
render( | ||||||
<SurveyPopup | ||||||
survey={mockSurvey} | ||||||
removeSurveyFromFocus={mockRemoveSurveyFromFocus} | ||||||
isPopup={true} | ||||||
onCloseConfirmationMessage={mockOnCloseConfirmationMessage} | ||||||
// Force the confirmation message to show | ||||||
previewPageIndex={mockSurvey.questions.length} | ||||||
/> | ||||||
) | ||||||
const cancelButton2 = screen.getByRole('button', { name: 'Close survey', hidden: true }) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
// Click the cancel button | ||||||
fireEvent.click(cancelButton2) | ||||||
// Verify that onCloseConfirmationMessage was called | ||||||
expect(mockOnCloseConfirmationMessage).toHaveBeenCalledTimes(1) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Should also verify mockRemoveSurveyFromFocus was called to ensure proper cleanup |
||||||
}) | ||||||
|
||||||
test('calls onCloseConfirmationMessage when survey is closed in the confirmation message', () => { | ||||||
const mockOnCloseConfirmationMessage = jest.fn() | ||||||
const mockRemoveSurveyFromFocus = jest.fn() | ||||||
render( | ||||||
<SurveyPopup | ||||||
survey={mockSurvey} | ||||||
removeSurveyFromFocus={mockRemoveSurveyFromFocus} | ||||||
isPopup={true} | ||||||
onCloseConfirmationMessage={mockOnCloseConfirmationMessage} | ||||||
previewPageIndex={mockSurvey.questions.length} | ||||||
/> | ||||||
) | ||||||
|
||||||
const closeButton = screen.getByRole('button', { name: /close/i }) | ||||||
fireEvent.click(closeButton) | ||||||
expect(mockOnCloseConfirmationMessage).toHaveBeenCalledTimes(1) | ||||||
}) | ||||||
}) |
There was a problem hiding this comment.
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.