@@ -4,7 +4,7 @@ import type {
44} from "@tanstack/react-table" ;
55import { act , useState } from "react" ;
66import { createRoot } from "react-dom/client" ;
7- import { afterEach , describe , expect , it , vi } from "vitest" ;
7+ import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
88
99import { DataGrid } from "./DataGrid" ;
1010import { createReadOnlyColumns , type GridRow } from "./test-utils" ;
@@ -13,11 +13,48 @@ import { createReadOnlyColumns, type GridRow } from "./test-utils";
1313 globalThis as { IS_REACT_ACT_ENVIRONMENT ?: boolean }
1414) . IS_REACT_ACT_ENVIRONMENT = true ;
1515
16+ beforeEach ( ( ) => {
17+ const localStorage = createLocalStorageMock ( ) ;
18+ Object . defineProperty ( globalThis , "localStorage" , {
19+ configurable : true ,
20+ value : localStorage ,
21+ } ) ;
22+ Object . defineProperty ( window , "localStorage" , {
23+ configurable : true ,
24+ value : localStorage ,
25+ } ) ;
26+ } ) ;
27+
1628afterEach ( ( ) => {
1729 vi . restoreAllMocks ( ) ;
1830 document . body . innerHTML = "" ;
1931} ) ;
2032
33+ function createLocalStorageMock ( ) : Storage {
34+ const entries = new Map < string , string > ( ) ;
35+
36+ return {
37+ get length ( ) {
38+ return entries . size ;
39+ } ,
40+ clear ( ) {
41+ entries . clear ( ) ;
42+ } ,
43+ getItem ( key : string ) {
44+ return entries . get ( key ) ?? null ;
45+ } ,
46+ key ( index : number ) {
47+ return Array . from ( entries . keys ( ) ) [ index ] ?? null ;
48+ } ,
49+ removeItem ( key : string ) {
50+ entries . delete ( key ) ;
51+ } ,
52+ setItem ( key : string , value : string ) {
53+ entries . set ( key , value ) ;
54+ } ,
55+ } ;
56+ }
57+
2158function renderGrid ( rows : GridRow [ ] ) {
2259 const container = document . createElement ( "div" ) ;
2360 document . body . appendChild ( container ) ;
@@ -86,4 +123,22 @@ describe("DataGrid layout", () => {
86123
87124 cleanup ( ) ;
88125 } ) ;
126+
127+ it ( "keeps the table wrapper as a plain overflow scroller for wide-grid horizontal scrolling" , ( ) => {
128+ const { cleanup, table } = renderGrid ( [
129+ {
130+ __ps_rowid : "row_1" ,
131+ long_text : "wide" ,
132+ short_text : "Acme Labs" ,
133+ } ,
134+ ] ) ;
135+ const scrollContainer = table . parentElement ;
136+
137+ expect ( scrollContainer ) . toBeInstanceOf ( HTMLDivElement ) ;
138+ expect ( scrollContainer ?. className ) . toContain ( "overflow-auto" ) ;
139+ expect ( scrollContainer ?. className ) . toContain ( "min-w-0" ) ;
140+ expect ( scrollContainer ?. className ) . not . toContain ( "flex" ) ;
141+
142+ cleanup ( ) ;
143+ } ) ;
89144} ) ;
0 commit comments