@@ -3,7 +3,7 @@ import { sendKeys } from '@vaadin/test-runner-commands';
33import { aTimeout , fixtureSync , nextRender } from '@vaadin/testing-helpers' ;
44import sinon from 'sinon' ;
55import '../src/vaadin-multi-select-combo-box.js' ;
6- import { getAsyncDataProvider } from './helpers.js' ;
6+ import { getAllItems , getAsyncDataProvider , getFirstItem } from './helpers.js' ;
77
88describe ( 'readonly' , ( ) => {
99 let comboBox , inputElement , internal ;
@@ -78,20 +78,20 @@ describe('readonly', () => {
7878 it ( 'should not set item focus-ring attribute on Arrow Down' , async ( ) => {
7979 await sendKeys ( { down : 'ArrowDown' } ) ;
8080 await sendKeys ( { down : 'ArrowDown' } ) ;
81- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
82- expect ( items [ 0 ] . hasAttribute ( 'focus-ring' ) ) . to . be . false ;
81+ const item = getFirstItem ( comboBox ) ;
82+ expect ( item . hasAttribute ( 'focus-ring' ) ) . to . be . false ;
8383 } ) ;
8484
8585 it ( 'should not set item focus-ring attribute on Arrow Up' , async ( ) => {
8686 await sendKeys ( { down : 'ArrowDown' } ) ;
8787 await sendKeys ( { down : 'ArrowDown' } ) ;
88- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
88+ const items = getAllItems ( comboBox ) ;
8989 expect ( items [ 1 ] . hasAttribute ( 'focus-ring' ) ) . to . be . false ;
9090 } ) ;
9191
9292 it ( 'should only render selected items in the dropdown when readonly' , ( ) => {
9393 inputElement . click ( ) ;
94- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
94+ const items = getAllItems ( comboBox ) ;
9595 expect ( items . length ) . to . equal ( 2 ) ;
9696 expect ( items [ 0 ] . textContent ) . to . equal ( 'apple' ) ;
9797 expect ( items [ 1 ] . textContent ) . to . equal ( 'orange' ) ;
@@ -100,7 +100,7 @@ describe('readonly', () => {
100100 it ( 'should render regular items in the dropdown when readonly is off' , ( ) => {
101101 comboBox . readonly = false ;
102102 inputElement . click ( ) ;
103- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
103+ const items = getAllItems ( comboBox ) ;
104104 expect ( items . length ) . to . equal ( 4 ) ;
105105 expect ( items [ 0 ] . textContent ) . to . equal ( 'apple' ) ;
106106 expect ( items [ 1 ] . textContent ) . to . equal ( 'banana' ) ;
@@ -112,28 +112,28 @@ describe('readonly', () => {
112112 comboBox . selectedItems = [ ] ;
113113 comboBox . selectedItems = [ 'lemon' ] ;
114114 inputElement . click ( ) ;
115- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
115+ const items = getAllItems ( comboBox ) ;
116116 expect ( items . length ) . to . equal ( 1 ) ;
117117 expect ( items [ 0 ] . textContent ) . to . equal ( 'lemon' ) ;
118118 } ) ;
119119
120120 it ( 'should not set selected attribute on the dropdown items' , ( ) => {
121121 inputElement . click ( ) ;
122- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
122+ const items = getAllItems ( comboBox ) ;
123123 expect ( items [ 0 ] . hasAttribute ( 'selected' ) ) . to . be . false ;
124124 expect ( items [ 1 ] . hasAttribute ( 'selected' ) ) . to . be . false ;
125125 } ) ;
126126
127127 it ( 'should set readonly attribute on the dropdown items' , ( ) => {
128128 inputElement . click ( ) ;
129- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
129+ const items = getAllItems ( comboBox ) ;
130130 expect ( items [ 0 ] . hasAttribute ( 'readonly' ) ) . to . be . true ;
131131 expect ( items [ 1 ] . hasAttribute ( 'readonly' ) ) . to . be . true ;
132132 } ) ;
133133
134134 it ( 'should not un-select item on click when readonly' , ( ) => {
135135 inputElement . click ( ) ;
136- const item = document . querySelector ( 'vaadin-multi-select-combo-box-item' ) ;
136+ const item = getFirstItem ( comboBox ) ;
137137 item . click ( ) ;
138138 expect ( comboBox . selectedItems . length ) . to . equal ( 2 ) ;
139139 } ) ;
@@ -180,7 +180,7 @@ describe('readonly', () => {
180180 inputElement . click ( ) ;
181181 // Wait for the async data provider timeout
182182 await aTimeout ( 0 ) ;
183- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
183+ const items = getAllItems ( comboBox ) ;
184184 expect ( items . length ) . to . equal ( 2 ) ;
185185 expect ( items [ 0 ] . textContent ) . to . equal ( 'apple' ) ;
186186 expect ( items [ 1 ] . textContent ) . to . equal ( 'orange' ) ;
@@ -191,7 +191,7 @@ describe('readonly', () => {
191191 inputElement . click ( ) ;
192192 // Wait for the async data provider timeout
193193 await aTimeout ( 0 ) ;
194- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
194+ const items = getAllItems ( comboBox ) ;
195195 expect ( items . length ) . to . equal ( 4 ) ;
196196 expect ( items [ 0 ] . textContent ) . to . equal ( 'apple' ) ;
197197 expect ( items [ 1 ] . textContent ) . to . equal ( 'banana' ) ;
@@ -204,7 +204,7 @@ describe('readonly', () => {
204204 // Wait for the async data provider timeout
205205 await aTimeout ( 0 ) ;
206206 comboBox . size = 4 ;
207- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
207+ const items = getAllItems ( comboBox ) ;
208208 expect ( items . length ) . to . equal ( 2 ) ;
209209 expect ( items [ 0 ] . textContent ) . to . equal ( 'apple' ) ;
210210 expect ( items [ 1 ] . textContent ) . to . equal ( 'orange' ) ;
@@ -224,7 +224,7 @@ describe('readonly', () => {
224224 inputElement . click ( ) ;
225225 // Wait for the async data provider timeout
226226 await aTimeout ( 0 ) ;
227- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
227+ const items = getAllItems ( comboBox ) ;
228228 expect ( items . length ) . to . equal ( 2 ) ;
229229 expect ( items [ 0 ] . textContent ) . to . equal ( 'apple' ) ;
230230 expect ( items [ 1 ] . textContent ) . to . equal ( 'orange' ) ;
@@ -250,7 +250,7 @@ describe('readonly', () => {
250250 comboBox . inputElement . click ( ) ;
251251 // Wait for the async data provider timeout
252252 await aTimeout ( 0 ) ;
253- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
253+ const items = getAllItems ( comboBox ) ;
254254 expect ( items . length ) . to . equal ( 2 ) ;
255255 expect ( items [ 0 ] . textContent ) . to . equal ( 'new item 1' ) ;
256256 expect ( items [ 1 ] . textContent ) . to . equal ( 'new item 2' ) ;
@@ -270,7 +270,7 @@ describe('readonly', () => {
270270
271271 it ( 'should only render selected items in the dropdown when readonly' , ( ) => {
272272 inputElement . click ( ) ;
273- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
273+ const items = getAllItems ( comboBox ) ;
274274 expect ( items . length ) . to . equal ( 2 ) ;
275275 expect ( items [ 0 ] . textContent ) . to . equal ( 'apple' ) ;
276276 expect ( items [ 1 ] . textContent ) . to . equal ( 'orange' ) ;
@@ -279,7 +279,7 @@ describe('readonly', () => {
279279 it ( 'should render regular items in the dropdown when readonly is off' , ( ) => {
280280 comboBox . readonly = false ;
281281 inputElement . click ( ) ;
282- const items = document . querySelectorAll ( 'vaadin-multi-select-combo-box-item' ) ;
282+ const items = getAllItems ( comboBox ) ;
283283 expect ( items . length ) . to . equal ( 4 ) ;
284284 expect ( items [ 0 ] . textContent ) . to . equal ( 'apple' ) ;
285285 expect ( items [ 1 ] . textContent ) . to . equal ( 'banana' ) ;
0 commit comments