@@ -27,12 +27,9 @@ import {
2727 getStyleValue ,
2828 findFirstVisibleItem ,
2929 findLastVisibleItem ,
30+ isVerticalScrollBarVisible ,
3031} from "./utils" ;
3132
32- const isVerticalScrollBarVisible = async ( e : Locator ) => {
33- return e . evaluate ( ( e ) => e . scrollHeight > ( e as HTMLElement ) . offsetHeight ) ;
34- } ;
35-
3633test . describe ( "smoke" , ( ) => {
3734 test ( "vertically scrollable" , async ( { page } ) => {
3835 await page . goto ( storyUrl ( "basics-vlist--default" ) ) ;
@@ -112,39 +109,6 @@ test.describe("smoke", () => {
112109 ) . toBeVisible ( ) ;
113110 } ) ;
114111
115- test ( "reverse" , async ( { page } ) => {
116- await page . goto ( storyUrl ( "basics-vlist--reverse" ) , {
117- waitUntil : "domcontentloaded" ,
118- } ) ;
119- await page . evaluate ( ( ) => {
120- ( window as any ) . _displayed = false ;
121- const mo = new MutationObserver ( ( entries ) => {
122- for ( const e of entries ) {
123- for ( const n of [ ...e . addedNodes ] ) {
124- const walker = document . createTreeWalker ( n , NodeFilter . SHOW_TEXT ) ;
125- let node : Node ;
126- while ( ( node = walker . nextNode ( ) ! ) ) {
127- if ( node . textContent === "0" ) {
128- ( window as any ) . _displayed = true ;
129- return ;
130- }
131- }
132- }
133- }
134- } ) ;
135- mo . observe ( document . body , { childList : true , subtree : true } ) ;
136- } ) ;
137-
138- const component = await getScrollable ( page ) ;
139-
140- // check if last is displayed
141- const last = component . getByText ( "999" , { exact : true } ) ;
142- await expect ( last ) . toBeVisible ( ) ;
143- expect ( await relativeBottom ( component , last ) ) . toEqual ( 0 ) ;
144- // check if start is not displayed
145- expect ( await page . evaluate ( ( ) => ( window as any ) . _displayed ) ) . toBe ( false ) ;
146- } ) ;
147-
148112 test ( "display: none" , async ( { page } ) => {
149113 await page . goto ( storyUrl ( "basics-vlist--default" ) ) ;
150114
@@ -1324,123 +1288,6 @@ test.describe("check if item shift compensation works", () => {
13241288 expect ( i ) . toBeGreaterThanOrEqual ( 8 ) ;
13251289 } ) ;
13261290
1327- test ( "prepending when total height is lower than viewport height and reverse:true" , async ( {
1328- page,
1329- browserName,
1330- } ) => {
1331- const [ component , container ] = await Promise . all ( [
1332- getScrollable ( page ) ,
1333- getVirtualizer ( page ) ,
1334- ] ) ;
1335-
1336- await page . getByRole ( "checkbox" , { name : "reverse" } ) . click ( ) ;
1337-
1338- await page . getByRole ( "checkbox" , { name : "prepend" } ) . click ( ) ;
1339- const decreaseRadio = page . getByRole ( "radio" , { name : "decrease" } ) ;
1340- const increaseRadio = page . getByRole ( "radio" , { name : "increase" } ) ;
1341- const valueInput = page . getByRole ( "spinbutton" ) ;
1342- const updateButton = page . getByRole ( "button" , { name : "update" } ) ;
1343-
1344- const initialLength = await getItems ( container ) . count ( ) ;
1345- expect ( initialLength ) . toBeGreaterThan ( 1 ) ;
1346-
1347- let i = 0 ;
1348- while ( true ) {
1349- i ++ ;
1350- await valueInput . clear ( ) ;
1351- await valueInput . fill ( String ( i ) ) ;
1352-
1353- // preprend
1354- await increaseRadio . click ( ) ;
1355- await updateButton . click ( ) ;
1356-
1357- const items = getItems ( container ) ;
1358-
1359- // Check if all items are visible
1360- await expect ( items ) . toHaveCount ( i + initialLength ) ;
1361-
1362- const isScrollBarVisible = await isVerticalScrollBarVisible ( component ) ;
1363- const itemBottom = await relativeBottom ( component , items . last ( ) ) ;
1364-
1365- if ( isScrollBarVisible ) {
1366- // Check if sticked to bottom
1367- expectInRange ( itemBottom , {
1368- min : - 0.1 ,
1369- max : browserName === "firefox" ? 0.45 : 0.1 ,
1370- } ) ;
1371- break ;
1372- } else {
1373- // Check if bottom is always visible and on bottom
1374- expectInRange ( itemBottom , { min : - 0.1 , max : 0.1 } ) ;
1375- }
1376-
1377- // remove
1378- await decreaseRadio . click ( ) ;
1379- await updateButton . click ( ) ;
1380- }
1381-
1382- expect ( i ) . toBeGreaterThanOrEqual ( 8 ) ;
1383- } ) ;
1384-
1385- test ( "stick to bottom even if many items are removed from top" , async ( {
1386- page,
1387- browserName,
1388- } ) => {
1389- await page . goto ( storyUrl ( "basics-vlist--increasing-items" ) ) ;
1390- const [ component , container ] = await Promise . all ( [
1391- getScrollable ( page ) ,
1392- getVirtualizer ( page ) ,
1393- ] ) ;
1394-
1395- await page . getByRole ( "checkbox" , { name : "reverse" } ) . click ( ) ;
1396-
1397- await page . getByRole ( "checkbox" , { name : "prepend" } ) . click ( ) ;
1398- const decreaseRadio = page . getByRole ( "radio" , { name : "decrease" } ) ;
1399- const increaseRadio = page . getByRole ( "radio" , { name : "increase" } ) ;
1400- const valueInput = page . getByRole ( "spinbutton" ) ;
1401- const updateButton = page . getByRole ( "button" , { name : "update" } ) ;
1402-
1403- // preprend many
1404- await valueInput . clear ( ) ;
1405- await valueInput . fill ( "50" ) ;
1406- await increaseRadio . click ( ) ;
1407- await updateButton . click ( ) ;
1408-
1409- // scroll to bottom
1410- await scrollToBottom ( component ) ;
1411-
1412- // remove many
1413- await valueInput . clear ( ) ;
1414- await valueInput . fill ( "1" ) ;
1415- await decreaseRadio . click ( ) ;
1416- let i = 0 ;
1417- while ( true ) {
1418- i ++ ;
1419- await updateButton . click ( ) ;
1420-
1421- const isScrollBarVisible = await isVerticalScrollBarVisible ( component ) ;
1422- const itemBottom = await relativeBottom (
1423- component ,
1424- getItems ( container ) . last ( )
1425- ) ;
1426-
1427- // Check if bottom is always visible and on bottom
1428- expectInRange ( itemBottom , {
1429- min : browserName === "firefox" ? - 0.6 : - 0.5 ,
1430- max : 0.5 ,
1431- } ) ;
1432-
1433- if ( ! isScrollBarVisible ) {
1434- break ;
1435- } else {
1436- // may have subpixel error so scroll to bottom again
1437- await component . evaluate ( ( e ) => ( e . scrollTop += e . scrollHeight ) ) ;
1438- }
1439- }
1440-
1441- expect ( i ) . toBeGreaterThanOrEqual ( 30 ) ;
1442- } ) ;
1443-
14441291 test ( "check if prepending cancels imperative scroll" , async ( { page } ) => {
14451292 await page . goto ( storyUrl ( "advanced-chat--default" ) ) ;
14461293 await page . getByRole ( "checkbox" , { name : "auto update" } ) . click ( ) ;
0 commit comments