1- import { describe , expect , it } from "vite-plus/test" ;
1+ import { describe , expect , it , vi } from "vite-plus/test" ;
2+ import { userEvent } from "vite-plus/test/browser" ;
23
34import { render } from "../../../test/render" ;
45import { type SidebarRouteReveal , useActiveRowReveal } from "./routeReveal" ;
@@ -17,6 +18,7 @@ function RevealList(props: {
1718 < li
1819 key = { key }
1920 ref = { key === props . activeKey ? ( row ) => revealActiveRow ( row , key ) : undefined }
21+ tabIndex = { - 1 }
2022 style = { { height : ROW_HEIGHT_PX } }
2123 >
2224 { key }
@@ -46,6 +48,41 @@ describe("useActiveRowReveal", () => {
4648 await expect . element ( target ) . toBeInViewport ( ) ;
4749 } ) ;
4850
51+ it ( "leaves the list where it is when the user clicked the row that opened the thread" , async ( ) => {
52+ const reveal = newReveal ( ) ;
53+ const keys = rowKeys ( 50 ) ;
54+ await using screen = await render (
55+ < RevealList reveal = { reveal } rowKeys = { keys } activeKey = "thread-0" /> ,
56+ // No router: the route arrives as the activeKey prop.
57+ { router : false } ,
58+ ) ;
59+ await userEvent . hover ( screen . getByText ( "thread-2" , { exact : true } ) ) ;
60+ // Even a no-op scroll forces a layout of the thread being opened.
61+ using scrollIntoView = vi . spyOn ( Element . prototype , "scrollIntoView" ) ;
62+
63+ await screen . rerender ( < RevealList reveal = { reveal } rowKeys = { keys } activeKey = "thread-2" /> ) ;
64+
65+ await vi . waitFor ( ( ) => expect ( reveal . pendingKey ) . toBeNull ( ) ) ;
66+ expect ( scrollIntoView ) . not . toHaveBeenCalled ( ) ;
67+ } ) ;
68+
69+ it ( "reveals a focused row scrolled out of view when the keyboard opens its thread" , async ( ) => {
70+ const reveal = newReveal ( ) ;
71+ const keys = rowKeys ( 50 ) ;
72+ await using screen = await render (
73+ < RevealList reveal = { reveal } rowKeys = { keys } activeKey = "thread-0" /> ,
74+ // No router: the route arrives as the activeKey prop.
75+ { router : false } ,
76+ ) ;
77+ const target = screen . getByText ( "thread-40" , { exact : true } ) ;
78+ target . element ( ) . focus ( { preventScroll : true } ) ;
79+ await expect . element ( target ) . not . toBeInViewport ( ) ;
80+
81+ await screen . rerender ( < RevealList reveal = { reveal } rowKeys = { keys } activeKey = "thread-40" /> ) ;
82+
83+ await expect . element ( target ) . toBeInViewport ( ) ;
84+ } ) ;
85+
4986 it ( "reveals the active row when it mounts after the shells arrive" , async ( ) => {
5087 const reveal = newReveal ( ) ;
5188 // The route already names the thread, but its environment's shells have not
0 commit comments