diff --git a/src/renderer/src/components/emulator-pane/MobileEmulatorTabIntroCallout.test.tsx b/src/renderer/src/components/emulator-pane/MobileEmulatorTabIntroCallout.test.tsx new file mode 100644 index 000000000..f5ccbbd20 --- /dev/null +++ b/src/renderer/src/components/emulator-pane/MobileEmulatorTabIntroCallout.test.tsx @@ -0,0 +1,102 @@ +// @vitest-environment happy-dom + +import { act } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { MobileEmulatorTabIntroCallout } from './MobileEmulatorTabIntroCallout' + +const { keepIntro, hideIntro, dismissIntro } = vi.hoisted(() => ({ + keepIntro: vi.fn(), + hideIntro: vi.fn(), + dismissIntro: vi.fn() +})) + +vi.mock('./use-mobile-emulator-tab-intro-actions', () => ({ + useMobileEmulatorTabIntroActions: () => ({ keepIntro, hideIntro, dismissIntro }) +})) + +// Why: the Tooltip primitive needs a provider/portal we don't care about here; +// render its trigger children directly so the test stays focused on wiring. +vi.mock('@/components/ui/tooltip', () => ({ + Tooltip: ({ children }: { children: React.ReactNode }) => children, + TooltipTrigger: ({ children }: { children: React.ReactNode }) => children, + TooltipContent: () => null +})) + +let root: Root | null = null +let container: HTMLDivElement | null = null + +beforeEach(async () => { + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) + await act(async () => { + root?.render() + }) +}) + +afterEach(async () => { + if (root) { + await act(async () => { + root?.unmount() + }) + } + root = null + container?.remove() + container = null + vi.clearAllMocks() +}) + +function click(matcher: string): void { + const button = Array.from(container?.querySelectorAll('button') ?? []).find( + (el) => el.textContent?.trim() === matcher || el.getAttribute('aria-label') === matcher + ) + if (!button) { + throw new Error(`button not found: ${matcher}`) + } + act(() => { + button.dispatchEvent(new MouseEvent('click', { bubbles: true })) + }) +} + +describe('MobileEmulatorTabIntroCallout', () => { + it('runs keepIntro when Keep is clicked', () => { + click('Keep') + expect(keepIntro).toHaveBeenCalledTimes(1) + expect(hideIntro).not.toHaveBeenCalled() + expect(dismissIntro).not.toHaveBeenCalled() + }) + + it('runs hideIntro when Hide is clicked', () => { + click('Hide') + expect(hideIntro).toHaveBeenCalledTimes(1) + expect(keepIntro).not.toHaveBeenCalled() + expect(dismissIntro).not.toHaveBeenCalled() + }) + + it('runs dismissIntro when the X is clicked', () => { + click('Dismiss') + expect(dismissIntro).toHaveBeenCalledTimes(1) + expect(keepIntro).not.toHaveBeenCalled() + expect(hideIntro).not.toHaveBeenCalled() + }) + + it('exposes no menu-closing prop, so reintroducing Issue 1 is a compile error', () => { + // Why: Issue 1's root cause was a parent-supplied close callback + // (onAction={() => setNewTabMenuOpen(false)}). The callout must accept no + // such prop — re-adding one fails this typechecked file's @ts-expect-error. + // @ts-expect-error - MobileEmulatorTabIntroCallout intentionally takes no props + const reintroduced = undefined} /> + expect(reintroduced).toBeDefined() + }) + + it('prevents the default pointer-down so the dropdown menu stays open', () => { + const callout = container?.querySelector('.mobile-emulator-tab-intro-callout--menu') + expect(callout).not.toBeNull() + const event = new MouseEvent('pointerdown', { bubbles: true, cancelable: true }) + act(() => { + callout?.dispatchEvent(event) + }) + expect(event.defaultPrevented).toBe(true) + }) +}) diff --git a/src/renderer/src/components/emulator-pane/MobileEmulatorTabIntroCallout.tsx b/src/renderer/src/components/emulator-pane/MobileEmulatorTabIntroCallout.tsx index 2d1924737..e97bdaab1 100644 --- a/src/renderer/src/components/emulator-pane/MobileEmulatorTabIntroCallout.tsx +++ b/src/renderer/src/components/emulator-pane/MobileEmulatorTabIntroCallout.tsx @@ -4,25 +4,15 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip import { translate } from '@/i18n/i18n' import { useMobileEmulatorTabIntroActions } from './use-mobile-emulator-tab-intro-actions' -type MobileEmulatorTabIntroCalloutProps = { - onAction?: () => void -} - -export function MobileEmulatorTabIntroCallout({ - onAction -}: MobileEmulatorTabIntroCalloutProps): React.JSX.Element { +export function MobileEmulatorTabIntroCallout(): React.JSX.Element { const { keepIntro, hideIntro, dismissIntro } = useMobileEmulatorTabIntroActions() - const runAndNotify = (action: () => void): void => { - action() - onAction?.() - } - return (
event.preventDefault()} >

@@ -37,7 +27,7 @@ export function MobileEmulatorTabIntroCallout({ size="sm" variant="outline" className="h-6 px-2 text-[11px]" - onClick={() => runAndNotify(keepIntro)} + onClick={keepIntro} > {translate( 'auto.components.emulator.pane.MobileEmulatorTabIntroCallout.8014b4b80b', @@ -49,7 +39,7 @@ export function MobileEmulatorTabIntroCallout({ size="sm" variant="ghost" className="h-6 px-2 text-[11px] text-muted-foreground" - onClick={() => runAndNotify(hideIntro)} + onClick={hideIntro} > {translate( 'auto.components.emulator.pane.MobileEmulatorTabIntroCallout.6e051a40b7', @@ -67,7 +57,7 @@ export function MobileEmulatorTabIntroCallout({ 'Dismiss' )} className="size-6 text-muted-foreground" - onClick={() => runAndNotify(dismissIntro)} + onClick={dismissIntro} > diff --git a/src/renderer/src/components/emulator-pane/mobile-emulator-hidden-toast.test.tsx b/src/renderer/src/components/emulator-pane/mobile-emulator-hidden-toast.test.tsx new file mode 100644 index 000000000..9ec333557 --- /dev/null +++ b/src/renderer/src/components/emulator-pane/mobile-emulator-hidden-toast.test.tsx @@ -0,0 +1,37 @@ +// @vitest-environment happy-dom + +import { afterEach, describe, expect, it, vi } from 'vitest' +import { toast } from 'sonner' +import type { AppState } from '@/store/types' +import { showMobileEmulatorHiddenToast } from './mobile-emulator-hidden-toast' + +vi.mock('sonner', () => ({ + toast: { + dismiss: vi.fn(), + info: vi.fn() + } +})) + +afterEach(() => { + vi.clearAllMocks() +}) + +describe('showMobileEmulatorHiddenToast', () => { + it('auto-dismisses after 30s while staying dismissible', () => { + showMobileEmulatorHiddenToast({ + openSettingsPage: vi.fn() as unknown as AppState['openSettingsPage'], + openSettingsTarget: vi.fn() as unknown as AppState['openSettingsTarget'] + }) + + const infoMock = vi.mocked(toast.info) + expect(infoMock).toHaveBeenCalledTimes(1) + const options = infoMock.mock.calls[0]?.[1] + // Why: a finite duration is the fix for the toast lingering forever; assert + // the exact value so a regression to Infinity is caught. + expect(options).toMatchObject({ + id: 'mobile-emulator-hidden', + duration: 30_000, + dismissible: true + }) + }) +}) diff --git a/src/renderer/src/components/emulator-pane/mobile-emulator-hidden-toast.tsx b/src/renderer/src/components/emulator-pane/mobile-emulator-hidden-toast.tsx index d73a0ccdc..d62b44f9f 100644 --- a/src/renderer/src/components/emulator-pane/mobile-emulator-hidden-toast.tsx +++ b/src/renderer/src/components/emulator-pane/mobile-emulator-hidden-toast.tsx @@ -3,6 +3,9 @@ import type { AppState } from '@/store/types' import { translate } from '@/i18n/i18n' const MOBILE_EMULATOR_HIDDEN_TOAST_ID = 'mobile-emulator-hidden' +// Why: auto-dismiss the nudge after 30s so it can't linger forever; it stays +// dismissible early and the Settings re-enable link is reachable until then. +const MOBILE_EMULATOR_HIDDEN_TOAST_DURATION_MS = 30_000 type MobileEmulatorHiddenToastDeps = { openSettingsPage: AppState['openSettingsPage'] @@ -10,8 +13,6 @@ type MobileEmulatorHiddenToastDeps = { } export function showMobileEmulatorHiddenToast(deps: MobileEmulatorHiddenToastDeps): void { - // Why: matches other one-time opt-out nudges — stay on screen until the user - // dismisses it so the Settings re-enable path is easy to find. toast.info( translate( 'auto.components.emulator.pane.mobile.emulator.hidden.toast.e8f098a870', @@ -42,7 +43,7 @@ export function showMobileEmulatorHiddenToast(deps: MobileEmulatorHiddenToastDep .

), - duration: Infinity, + duration: MOBILE_EMULATOR_HIDDEN_TOAST_DURATION_MS, dismissible: true } ) diff --git a/src/renderer/src/components/emulator-pane/use-mobile-emulator-tab-intro-actions.test.tsx b/src/renderer/src/components/emulator-pane/use-mobile-emulator-tab-intro-actions.test.tsx index f83485ff1..137c20f63 100644 --- a/src/renderer/src/components/emulator-pane/use-mobile-emulator-tab-intro-actions.test.tsx +++ b/src/renderer/src/components/emulator-pane/use-mobile-emulator-tab-intro-actions.test.tsx @@ -121,7 +121,7 @@ describe('useMobileEmulatorTabIntroActions', () => { expect(closeUnifiedTab).toHaveBeenCalledWith('simulator-tab') expect(toast.info).toHaveBeenCalledWith( 'Mobile Emulator hidden', - expect.objectContaining({ id: 'mobile-emulator-hidden' }) + expect.objectContaining({ id: 'mobile-emulator-hidden', duration: 30_000 }) ) expect(toast.error).not.toHaveBeenCalled() }) diff --git a/src/renderer/src/components/tab-bar/TabBar.tsx b/src/renderer/src/components/tab-bar/TabBar.tsx index 5f5982f49..fc7008ae6 100644 --- a/src/renderer/src/components/tab-bar/TabBar.tsx +++ b/src/renderer/src/components/tab-bar/TabBar.tsx @@ -769,7 +769,7 @@ function TabBarInner({ isMacOs && mobileEmulatorEnabled && onNewSimulatorTab ? ( - setNewTabMenuOpen(false)} /> + ) : null const standardCreateMenuItems = newTabMenuOrder === 'markdown-first' ? ( @@ -1193,7 +1193,14 @@ function TabBarInner({ ) : null} - +