@@ -4,14 +4,18 @@ import { act, useLayoutEffect } from "react";
44import { createRoot } from "react-dom/client" ;
55import { expect , it , vi } from "vite-plus/test" ;
66
7- import { NativePrimaryColumnContext } from "../../native/v5-workspace-context" ;
7+ import {
8+ NativePrimaryColumnContext ,
9+ NativeWorkspaceTabActivityContext ,
10+ } from "../../native/v5-workspace-context" ;
811
912// The Thread in the detail column is the focused route on iPad split view.
1013vi . mock ( "@react-navigation/native" , ( ) => ( {
1114 useNavigation : ( ) => ( { isFocused : ( ) => false } ) ,
1215} ) ) ;
1316
1417import {
18+ recordHomeFocus ,
1519 recordHomeTransitionEnd ,
1620 recordHomeTransitionStart ,
1721 useAtomValueWhileVisible ,
@@ -54,6 +58,18 @@ function setup() {
5458 ) ,
5559 ) ;
5660 } ,
61+ /** A phone has no primary column: Home is the root page of its tab's slot. */
62+ showHomeInTabSlot ( active : boolean ) {
63+ act ( ( ) =>
64+ root . render (
65+ < RegistryContext . Provider value = { registry } >
66+ < NativeWorkspaceTabActivityContext value = { { active, isActive : ( ) => active } } >
67+ < Probe />
68+ </ NativeWorkspaceTabActivityContext >
69+ </ RegistryContext . Provider > ,
70+ ) ,
71+ ) ;
72+ } ,
5773 [ Symbol . dispose ] ( ) {
5874 act ( ( ) => root . unmount ( ) ) ;
5975 registry . dispose ( ) ;
@@ -71,11 +87,51 @@ it("keeps the sidebar thread list live after switching tabs beside a focused Thr
7187
7288 // Chats → PRs → Chats: Chats' column will-appear, then the PRs column's did-disappear.
7389 act ( ( ) => {
74- recordHomeTransitionEnd ( true ) ;
90+ recordHomeTransitionEnd ( true , false ) ;
7591 recordHomeTransitionStart ( false ) ;
76- recordHomeTransitionEnd ( true ) ;
92+ recordHomeTransitionEnd ( true , false ) ;
7793 } ) ;
7894 act ( ( ) => home . registry . set ( shellsAtom , 2 ) ) ;
7995
8096 expect ( home . latest , "new thread shells reach the sidebar list" ) . toBe ( 2 ) ;
8197} ) ;
98+
99+ // Each phone tab slot shows its own copy of the Home route. PRs keeps Home focused; Settings
100+ // is a route of its own.
101+ it . each ( [
102+ { tab : "PRs" , homeFocusedUnderTab : true } ,
103+ { tab : "Settings" , homeFocusedUnderTab : false } ,
104+ ] ) (
105+ "keeps the phone thread list live after a round trip through $tab" ,
106+ ( { homeFocusedUnderTab } ) => {
107+ using home = setup ( ) ;
108+ recordHomeFocus ( ) ;
109+ home . showHomeInTabSlot ( true ) ;
110+ act ( ( ) => home . registry . set ( shellsAtom , 1 ) ) ;
111+ expect ( home . latest ) . toBe ( 1 ) ;
112+
113+ // To the other tab: its slot will-appear, then the Chats slot's did-disappear.
114+ act ( ( ) => {
115+ recordHomeTransitionStart ( false ) ;
116+ recordHomeTransitionEnd ( true , homeFocusedUnderTab ) ;
117+ } ) ;
118+ home . showHomeInTabSlot ( false ) ;
119+ act ( ( ) => home . registry . set ( shellsAtom , 2 ) ) ;
120+ expect ( home . latest , "the list under another tab holds its rows" ) . toBe ( 1 ) ;
121+
122+ // Back to Chats: its slot will-appear, then the other slot's did-disappear comes last.
123+ act ( ( ) => {
124+ recordHomeFocus ( ) ;
125+ recordHomeTransitionStart ( false ) ;
126+ recordHomeTransitionEnd ( true , true ) ;
127+ } ) ;
128+ home . showHomeInTabSlot ( true ) ;
129+ act ( ( ) => home . registry . set ( shellsAtom , 3 ) ) ;
130+ expect ( home . latest , "a server rename reaches the list" ) . toBe ( 3 ) ;
131+
132+ // A pushed Thread takes the focus and still stops the list.
133+ act ( ( ) => recordHomeTransitionEnd ( true , false ) ) ;
134+ act ( ( ) => home . registry . set ( shellsAtom , 4 ) ) ;
135+ expect ( home . latest , "the list under a Thread holds its rows" ) . toBe ( 3 ) ;
136+ } ,
137+ ) ;
0 commit comments