1- import { describe , expect , it } from "vite-plus/test" ;
1+ import { describe , expect , it , vi } from "vite-plus/test" ;
22
33import { act , render } from "../../test/render" ;
44import { useResizableWidth } from "./useResizableWidth" ;
55
66const STORAGE_KEY = "t3code:test:resizable-width" ;
77
88function Probe ( ) {
9- const { width } = useResizableWidth ( {
9+ const { width, handlers } = useResizableWidth ( {
1010 storageKey : STORAGE_KEY ,
1111 defaultWidth : 400 ,
1212 minWidth : 300 ,
1313 maxWidth : 800 ,
1414 edge : "left" ,
1515 } ) ;
16- return < output > { width } </ output > ;
16+ return (
17+ < div >
18+ < output > { width } </ output >
19+ < div role = "separator" { ...handlers } />
20+ </ div >
21+ ) ;
22+ }
23+
24+ function dragLeftBy ( handle : Element , distance : number ) {
25+ const init = { bubbles : true , button : 0 , pointerId : 1 } ;
26+ handle . dispatchEvent ( new PointerEvent ( "pointerdown" , { ...init , clientX : 500 } ) ) ;
27+ handle . dispatchEvent ( new PointerEvent ( "pointermove" , { ...init , clientX : 500 - distance } ) ) ;
28+ handle . dispatchEvent ( new PointerEvent ( "pointerup" , { ...init , clientX : 500 - distance } ) ) ;
1729}
1830
1931describe ( "useResizableWidth" , ( ) => {
@@ -32,4 +44,27 @@ describe("useResizableWidth", () => {
3244 } ) ;
3345 await expect . element ( screen . getByText ( "640" ) ) . toBeInTheDocument ( ) ;
3446 } ) ;
47+
48+ it ( "starts the next drag from a width storage rejected" , async ( ) => {
49+ using _storage = { [ Symbol . dispose ] : ( ) => localStorage . removeItem ( STORAGE_KEY ) } ;
50+ await using screen = await render ( < Probe /> , {
51+ // A bare hook probe; nothing here navigates.
52+ router : false ,
53+ } ) ;
54+ // Synthetic pointer ids are not active pointers, so the browser would reject capture.
55+ using _capture = vi
56+ . spyOn ( HTMLElement . prototype , "setPointerCapture" )
57+ . mockImplementation ( ( ) => { } ) ;
58+ using _write = vi . spyOn ( Storage . prototype , "setItem" ) . mockImplementation ( ( ) => {
59+ throw new DOMException ( "Storage is full." , "QuotaExceededError" ) ;
60+ } ) ;
61+ using _log = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
62+ const handle = screen . getByRole ( "separator" ) . element ( ) ;
63+
64+ await act ( ( ) => dragLeftBy ( handle , 100 ) ) ;
65+ await expect . element ( screen . getByText ( "500" ) ) . toBeInTheDocument ( ) ;
66+
67+ await act ( ( ) => dragLeftBy ( handle , 50 ) ) ;
68+ await expect . element ( screen . getByText ( "550" ) ) . toBeInTheDocument ( ) ;
69+ } ) ;
3570} ) ;
0 commit comments