@@ -4,8 +4,9 @@ import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';
4
4
describe ( 'virtual-list' , ( ) => {
5
5
let list ;
6
6
7
- beforeEach ( ( ) => {
7
+ beforeEach ( async ( ) => {
8
8
list = fixtureSync ( `<vaadin-virtual-list></vaadin-virtual-list>` ) ;
9
+ await nextFrame ( ) ;
9
10
} ) ;
10
11
11
12
it ( 'should have a default height' , ( ) => {
@@ -36,6 +37,10 @@ describe('virtual-list', () => {
36
37
expect ( flexBox . firstElementChild . offsetWidth ) . to . equal ( flexBox . offsetWidth ) ;
37
38
} ) ;
38
39
40
+ it ( 'should have role="list"' , ( ) => {
41
+ expect ( list . role ) . to . equal ( 'list' ) ;
42
+ } ) ;
43
+
39
44
describe ( 'with items' , ( ) => {
40
45
beforeEach ( async ( ) => {
41
46
const size = 100 ;
@@ -101,7 +106,7 @@ describe('virtual-list', () => {
101
106
it ( 'should have a last visible index' , ( ) => {
102
107
const item = [ ...list . children ] . find ( ( el ) => el . textContent === `value-${ list . lastVisibleIndex } ` ) ;
103
108
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 ) ;
105
110
} ) ;
106
111
107
112
it ( 'should clear the old content after assigning a new renderer' , ( ) => {
@@ -126,6 +131,34 @@ describe('virtual-list', () => {
126
131
expect ( list . children [ 0 ] . textContent . trim ( ) ) . to . equal ( 'bar' ) ;
127
132
} ) ;
128
133
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
+
129
162
describe ( 'overflow attribute' , ( ) => {
130
163
it ( 'should set overflow attribute to "bottom" when scroll is at the beginning' , ( ) => {
131
164
expect ( list . getAttribute ( 'overflow' ) ) . to . equal ( 'bottom' ) ;
0 commit comments