Skip to content

Commit 0e88233

Browse files
committed
refactor(webview): make handleDismiss synchronous in DismissibleUpsell
test(webview): add scenario where dismissOnClick=true without onClick tracks only UPSELL_DISMISSED; update tests; all tests passing locally
1 parent ecbf671 commit 0e88233

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

webview-ui/src/components/common/DismissibleUpsell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const DismissibleUpsell = memo(
7878
}
7979
}, [upsellId])
8080

81-
const handleDismiss = async () => {
81+
const handleDismiss = () => {
8282
// Track telemetry for dismissal
8383
telemetryClient.capture(TelemetryEventName.UPSELL_DISMISSED, {
8484
upsellId: upsellId,

webview-ui/src/components/common/__tests__/DismissibleUpsell.spec.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,46 @@ describe("DismissibleUpsell", () => {
531531
})
532532
})
533533

534+
it("dismisses on container click when dismissOnClick is true and no onClick is provided; tracks only dismissal", async () => {
535+
const onDismiss = vi.fn()
536+
const { container } = render(
537+
<DismissibleUpsell upsellId="test-upsell" onDismiss={onDismiss} dismissOnClick={true}>
538+
<div>Test content</div>
539+
</DismissibleUpsell>,
540+
)
541+
542+
// Make component visible
543+
makeUpsellVisible()
544+
545+
// Wait for component to be visible
546+
await waitFor(() => {
547+
expect(screen.getByText("Test content")).toBeInTheDocument()
548+
})
549+
550+
// Click on the container (not the dismiss button)
551+
const containerDiv = screen.getByText("Test content").parentElement as HTMLElement
552+
fireEvent.click(containerDiv)
553+
554+
// onDismiss should be called
555+
expect(onDismiss).toHaveBeenCalledTimes(1)
556+
557+
// Telemetry: only dismissal should be tracked
558+
expect(mockCapture).toHaveBeenCalledWith(TelemetryEventName.UPSELL_DISMISSED, {
559+
upsellId: "test-upsell",
560+
})
561+
expect(mockCapture).not.toHaveBeenCalledWith(TelemetryEventName.UPSELL_CLICKED, expect.anything())
562+
563+
// Dismiss message should be sent
564+
expect(mockPostMessage).toHaveBeenCalledWith({
565+
type: "dismissUpsell",
566+
upsellId: "test-upsell",
567+
})
568+
569+
// Component should be hidden
570+
await waitFor(() => {
571+
expect(container.firstChild).toBeNull()
572+
})
573+
})
534574
it("does not dismiss when clicked if dismissOnClick is false", async () => {
535575
const onClick = vi.fn()
536576
const onDismiss = vi.fn()

0 commit comments

Comments
 (0)