@@ -4,8 +4,9 @@ import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';
44describe ( 'virtual-list' , ( ) => {
55 let list ;
66
7- beforeEach ( ( ) => {
7+ beforeEach ( async ( ) => {
88 list = fixtureSync ( `<vaadin-virtual-list></vaadin-virtual-list>` ) ;
9+ await nextFrame ( ) ;
910 } ) ;
1011
1112 it ( 'should have a default height' , ( ) => {
@@ -36,6 +37,10 @@ describe('virtual-list', () => {
3637 expect ( flexBox . firstElementChild . offsetWidth ) . to . equal ( flexBox . offsetWidth ) ;
3738 } ) ;
3839
40+ it ( 'should have role="list"' , ( ) => {
41+ expect ( list . role ) . to . equal ( 'list' ) ;
42+ } ) ;
43+
3944 describe ( 'with items' , ( ) => {
4045 beforeEach ( async ( ) => {
4146 const size = 100 ;
@@ -101,7 +106,7 @@ describe('virtual-list', () => {
101106 it ( 'should have a last visible index' , ( ) => {
102107 const item = [ ...list . children ] . find ( ( el ) => el . textContent === `value-${ list . lastVisibleIndex } ` ) ;
103108 const itemRect = item . getBoundingClientRect ( ) ;
104- expect ( list . getBoundingClientRect ( ) . bottom ) . to . be . within ( itemRect . top , itemRect . bottom ) ;
109+ expect ( list . getBoundingClientRect ( ) . bottom ) . to . be . within ( itemRect . top , itemRect . bottom + 1 ) ;
105110 } ) ;
106111
107112 it ( 'should clear the old content after assigning a new renderer' , ( ) => {
@@ -126,6 +131,34 @@ describe('virtual-list', () => {
126131 expect ( list . children [ 0 ] . textContent . trim ( ) ) . to . equal ( 'bar' ) ;
127132 } ) ;
128133
134+ it ( 'should have items with role="listitem"' , ( ) => {
135+ expect ( list . children [ 0 ] . role ) . to . equal ( 'listitem' ) ;
136+ } ) ;
137+
138+ it ( 'should assign aria-setsize and aria-posinset' , ( ) => {
139+ list . scrollToIndex ( list . items . length - 1 ) ;
140+ const item = [ ...list . children ] . find ( ( el ) => el . textContent === `value-${ list . lastVisibleIndex } ` ) ;
141+ expect ( item . ariaSetSize ) . to . equal ( '100' ) ;
142+ expect ( item . ariaPosInSet ) . to . equal ( '100' ) ;
143+ } ) ;
144+
145+ describe ( 'item accessible name generator' , ( ) => {
146+ beforeEach ( async ( ) => {
147+ list . itemAccessibleNameGenerator = ( item ) => `Accessible ${ item . value } ` ;
148+ await nextFrame ( ) ;
149+ } ) ;
150+
151+ it ( 'should generate aria-label to the items' , ( ) => {
152+ expect ( list . children [ 0 ] . ariaLabel ) . to . equal ( 'Accessible value-0' ) ;
153+ } ) ;
154+
155+ it ( 'should remove aria-label from the items' , async ( ) => {
156+ list . itemAccessibleNameGenerator = undefined ;
157+ await nextFrame ( ) ;
158+ expect ( list . children [ 0 ] . ariaLabel ) . to . be . null ;
159+ } ) ;
160+ } ) ;
161+
129162 describe ( 'overflow attribute' , ( ) => {
130163 it ( 'should set overflow attribute to "bottom" when scroll is at the beginning' , ( ) => {
131164 expect ( list . getAttribute ( 'overflow' ) ) . to . equal ( 'bottom' ) ;
0 commit comments