@@ -3,7 +3,12 @@ import { createRoot, type Root } from "react-dom/client";
33import { afterEach , beforeEach , expect , it , vi } from "vite-plus/test" ;
44import { EnvironmentId , ThreadId } from "@t3tools/contracts" ;
55
6- const fixture = vi . hoisted ( ( ) => ( { active : true , currentThread : "thread-a" , stop : vi . fn ( ) } ) ) ;
6+ const fixture = vi . hoisted ( ( ) => ( {
7+ active : true ,
8+ currentThread : "thread-a" ,
9+ currentEnvironment : "environment" ,
10+ stop : vi . fn ( ) ,
11+ } ) ) ;
712const RouteName = createContext ( "Thread" ) ;
813const target = {
914 environmentId : EnvironmentId . make ( "environment" ) ,
@@ -12,8 +17,18 @@ const target = {
1217vi . mock ( "@react-navigation/native" , ( ) => ( {
1318 useRoute : ( ) => ( { name : useContext ( RouteName ) } ) ,
1419 useNavigationState : (
15- select : ( state : { routes : Array < { name : string ; params : { threadId : string } } > } ) => unknown ,
16- ) => select ( { routes : [ { name : "Thread" , params : { threadId : fixture . currentThread } } ] } ) ,
20+ select : ( state : {
21+ routes : Array < { name : string ; params : { threadId : string ; environmentId : string } } > ;
22+ } ) => unknown ,
23+ ) =>
24+ select ( {
25+ routes : [
26+ {
27+ name : "Thread" ,
28+ params : { threadId : fixture . currentThread , environmentId : fixture . currentEnvironment } ,
29+ } ,
30+ ] ,
31+ } ) ,
1732} ) ) ;
1833vi . mock ( "react-native" , ( ) => ( { Alert : { alert : vi . fn ( ) } } ) ) ;
1934vi . mock ( "./voiceModePresentation" , ( ) => ( { resolveVoiceModeNotice : ( ) => null } ) ) ;
@@ -37,6 +52,7 @@ let root: Root;
3752beforeEach ( ( ) => {
3853 fixture . active = true ;
3954 fixture . currentThread = "thread-a" ;
55+ fixture . currentEnvironment = "environment" ;
4056 fixture . stop . mockClear ( ) ;
4157 ( globalThis as { IS_REACT_ACT_ENVIRONMENT ?: boolean } ) . IS_REACT_ACT_ENVIRONMENT = true ;
4258 root = createRoot ( document . createElement ( "div" ) ) ;
@@ -64,12 +80,16 @@ it("keeps voice running when Files closes and stops when the owning Thread leave
6480 act ( ( ) => root . unmount ( ) ) ;
6581 expect ( fixture . stop ) . toHaveBeenCalledTimes ( 1 ) ;
6682} ) ;
67- it ( "stops the previous thread when navigation selects a different thread" , ( ) => {
68- render ( false ) ;
69- fixture . currentThread = "thread-b" ;
70- render ( false ) ;
71- expect ( fixture . stop ) . toHaveBeenCalledTimes ( 1 ) ;
72- } ) ;
83+ it . each ( [ "thread" , "environment" ] ) (
84+ "stops the previous thread when navigation selects a different %s" ,
85+ ( changed ) => {
86+ render ( false ) ;
87+ if ( changed === "thread" ) fixture . currentThread = "thread-b" ;
88+ else fixture . currentEnvironment = "another-environment" ;
89+ render ( false ) ;
90+ expect ( fixture . stop ) . toHaveBeenCalledTimes ( 1 ) ;
91+ } ,
92+ ) ;
7393
7494it ( "stops voice when its fullscreen thread closes over the still-mounted thread" , ( ) => {
7595 render ( true , "ThreadInspectorFullscreen" ) ;
0 commit comments