@@ -8,16 +8,28 @@ import {
88import { scopedThreadKey } from "@t3tools/client-runtime/environment" ;
99import { AsyncResult , Atom , AtomRegistry } from "effect/reactivity" ;
1010import { expect , it , vi } from "vite-plus/test" ;
11+ import { page } from "vite-plus/test/browser" ;
1112import { useEffect } from "react" ;
1213
1314import { act , render } from "../../test/render" ;
1415import { DevicePanel } from "../components/device/DevicePanel" ;
15- import { useAgentOpenedPreviews } from "../components/preview/useAgentOpenedPreviews" ;
16+ import {
17+ startAgentOpenedPreviews ,
18+ resetDeviceSessionBaselinesForTests ,
19+ } from "../components/preview/agentOpenedPreviews" ;
1620import { usePreviewMiniPlayerStore } from "../previewMiniPlayerStore" ;
17- import { readThreadPreviewState } from "../previewStateStore " ;
21+ import { appAtomRegistry } from "../rpc/atomRegistry " ;
1822import { deviceEnvironment , useDeviceState } from "./device" ;
1923
24+ vi . mock ( import ( "./presentation" ) , async ( original ) => ( {
25+ ...( await original ( ) ) ,
26+ environmentSummaries : {
27+ ...( await original ( ) ) . environmentSummaries ,
28+ connectedEnvironmentIdsAtom : Atom . make ( [ EnvironmentId . make ( "device-loading" ) ] ) ,
29+ } ,
30+ } ) ) ;
2031vi . mock ( import ( "../hooks/useSettings" ) , ( ) => ( {
32+ getClientSettings : ( ( ) => ( { browserAutoShowFloatingPreview : true } ) ) as never ,
2133 useClientSettings : ( (
2234 select : ( settings : { browserAutoShowFloatingPreview : boolean } ) => unknown ,
2335 ) => select ( { browserAutoShowFloatingPreview : true } ) ) as never ,
@@ -31,6 +43,11 @@ vi.mock(import("../components/device/DeviceHostUpdates"), () => ({
3143} ) ) ;
3244
3345it ( "baselines the first device snapshot without reopening dismissed devices" , async ( ) => {
46+ const viewport = { width : window . innerWidth , height : window . innerHeight } ;
47+ await page . viewport ( 1280 , 800 ) ;
48+ await using _viewport = {
49+ [ Symbol . asyncDispose ] : ( ) => page . viewport ( viewport . width , viewport . height ) ,
50+ } ;
3451 const threadRef = {
3552 environmentId : EnvironmentId . make ( "device-loading" ) ,
3653 threadId : ThreadId . make ( "thread" ) ,
@@ -65,29 +82,21 @@ it("baselines the first device snapshot without reopening dismissed devices", as
6582 hubBasePath : "/api/device-hub" ,
6683 revision : 1 ,
6784 } ;
68- const registry = AtomRegistry . make ( ) ;
69- using _registry = { [ Symbol . dispose ] : ( ) => registry . dispose ( ) } ;
85+ const registry = appAtomRegistry ;
86+ resetDeviceSessionBaselinesForTests ( ) ;
87+ using _baselines = { [ Symbol . dispose ] : resetDeviceSessionBaselinesForTests } ;
7088 const stateAtom = Atom . make < AsyncResult . AsyncResult < DeviceServiceState > > ( AsyncResult . initial ( ) ) ;
7189 using _subscription = vi . spyOn ( deviceEnvironment , "state" ) . mockReturnValue ( stateAtom ) ;
7290 using _store = {
7391 [ Symbol . dispose ] : ( ) => usePreviewMiniPlayerStore . getState ( ) . removeThread ( threadRef ) ,
7492 } ;
93+ using _following = { [ Symbol . dispose ] : startAgentOpenedPreviews ( ) } ;
7594 let loaded = false ;
7695 function Probe ( ) {
7796 const device = useDeviceState ( threadRef . environmentId ) ;
7897 useEffect ( ( ) => {
7998 loaded = device . loaded ;
8099 } , [ device . loaded ] ) ;
81- useAgentOpenedPreviews ( {
82- threadRef,
83- deviceState : device . state ,
84- deviceStateLoaded : device . loaded ,
85- previewState : readThreadPreviewState ( threadRef ) ,
86- serverBrowserAvailable : false ,
87- panelSurfaces : [ ] ,
88- miniPlayerSource : null ,
89- sheetLayout : false ,
90- } ) ;
91100 return null ;
92101 }
93102 await using _screen = await render (
0 commit comments