11import { expect } from '@esm-bundle/chai' ;
2- import { aTimeout , enterKeyDown , fire , fixtureSync , nextFrame } from '@vaadin/testing-helpers' ;
2+ import { aTimeout , enterKeyDown , fixtureSync , nextFrame } from '@vaadin/testing-helpers' ;
33import sinon from 'sinon' ;
44import '@vaadin/text-field/vaadin-text-field.js' ;
55import './not-animated-styles.js' ;
@@ -14,7 +14,8 @@ import {
1414 getSelectedItem ,
1515 getViewportItems ,
1616 getVisibleItemsCount ,
17- makeItems
17+ makeItems ,
18+ setInputValue
1819} from './helpers.js' ;
1920
2021registerStyles (
@@ -57,15 +58,6 @@ describe('lazy loading', () => {
5758 callback ( dataProviderItems , SIZE ) ;
5859 } ;
5960
60- const setInputValue = ( value ) => {
61- if ( comboBox . inputElement . tagName === 'IRON-INPUT' ) {
62- comboBox . inputElement . _initSlottedInput ( ) ;
63- comboBox . inputElement . inputElement . value = value ;
64- } else {
65- comboBox . inputElement . value = value ;
66- }
67- } ;
68-
6961 before ( ( ) => {
7062 sinon . stub ( console , 'warn' ) ;
7163 } ) ;
@@ -141,8 +133,7 @@ describe('lazy loading', () => {
141133 expect ( comboBox . autoOpenDisabled ) . to . be . true ;
142134 expect ( comboBox . opened ) . to . be . false ;
143135 comboBox . dataProvider = spyDataProvider ;
144- setInputValue ( 'item 1' ) ;
145- fire ( comboBox . inputElement , 'input' ) ;
136+ setInputValue ( comboBox , 'item 1' ) ;
146137 comboBox . opened = true ;
147138 expect ( comboBox . filter ) . to . equal ( 'item 1' ) ;
148139 const { filter } = spyDataProvider . lastCall . args [ 0 ] ;
@@ -351,8 +342,7 @@ describe('lazy loading', () => {
351342
352343 // FIXME: fails for combo-box-light (items are not updated)
353344 ( isComboBoxLight ? it . skip : it ) ( 'should not be invoked if items are filtered' , ( ) => {
354- setInputValue ( '1' ) ;
355- fire ( comboBox . inputElement , 'input' ) ;
345+ setInputValue ( comboBox , '1' ) ;
356346
357347 spyDataProvider . resetHistory ( ) ;
358348
@@ -414,8 +404,7 @@ describe('lazy loading', () => {
414404 comboBox . dataProvider = spyAsyncDataProvider ;
415405 comboBox . opened = true ;
416406
417- setInputValue ( 'custom value' ) ;
418- fire ( comboBox . inputElement , 'input' ) ;
407+ setInputValue ( comboBox , 'custom value' ) ;
419408
420409 enterKeyDown ( comboBox . inputElement ) ;
421410 expect ( comboBox . value ) . to . eql ( 'custom value' ) ;
@@ -888,6 +877,7 @@ describe('lazy loading', () => {
888877
889878 describe ( 'using data provider, lost focus before data is returned' , ( ) => {
890879 let returnedItems ;
880+
891881 const bluringDataProvider = ( params , callback ) => {
892882 comboBox . blur ( ) ;
893883 callback ( returnedItems , returnedItems . length ) ;
@@ -899,16 +889,15 @@ describe('lazy loading', () => {
899889 comboBox . opened = true ;
900890 comboBox . dataProvider = bluringDataProvider ;
901891 comboBox . opened = false ;
902- comboBox . focus ( ) ;
892+ comboBox . inputElement . focus ( ) ;
903893 } ) ;
904894
905895 it ( 'should set value without auto-open-disabled' , ( ) => {
906896 comboBox . autoOpenDisabled = false ;
907897 expect ( comboBox . autoOpenDisabled ) . to . be . false ;
908898
909- const filterValue = 'item 12' ;
910- comboBox . _inputElementValue = filterValue ;
911- comboBox . filter = filterValue ;
899+ setInputValue ( comboBox , 'item 12' ) ;
900+
912901 expect ( comboBox . opened ) . to . be . false ;
913902 expect ( comboBox . hasAttribute ( 'focused' ) ) . to . be . false ;
914903 expect ( comboBox . value ) . to . equal ( 'item 12' ) ;
@@ -918,9 +907,8 @@ describe('lazy loading', () => {
918907 comboBox . autoOpenDisabled = true ;
919908 expect ( comboBox . autoOpenDisabled ) . to . be . true ;
920909
921- const filterValue = 'item 12' ;
922- comboBox . _inputElementValue = filterValue ;
923- comboBox . filter = filterValue ;
910+ setInputValue ( comboBox , 'item 12' ) ;
911+
924912 expect ( comboBox . opened ) . to . be . false ;
925913 expect ( comboBox . hasAttribute ( 'focused' ) ) . to . be . false ;
926914 expect ( comboBox . value ) . to . equal ( 'item 12' ) ;
@@ -930,9 +918,8 @@ describe('lazy loading', () => {
930918 comboBox . autoOpenDisabled = false ;
931919 expect ( comboBox . autoOpenDisabled ) . to . be . false ;
932920
933- const filterValue = 'ItEm 12' ;
934- comboBox . _inputElementValue = filterValue ;
935- comboBox . filter = filterValue ;
921+ setInputValue ( comboBox , 'ItEm 12' ) ;
922+
936923 expect ( comboBox . opened ) . to . be . false ;
937924 expect ( comboBox . hasAttribute ( 'focused' ) ) . to . be . false ;
938925 expect ( comboBox . value ) . to . equal ( 'item 12' ) ;
@@ -942,9 +929,8 @@ describe('lazy loading', () => {
942929 comboBox . autoOpenDisabled = true ;
943930 expect ( comboBox . autoOpenDisabled ) . to . be . true ;
944931
945- const filterValue = 'iTem 12' ;
946- comboBox . _inputElementValue = filterValue ;
947- comboBox . filter = filterValue ;
932+ setInputValue ( comboBox , 'iTem 12' ) ;
933+
948934 expect ( comboBox . opened ) . to . be . false ;
949935 expect ( comboBox . hasAttribute ( 'focused' ) ) . to . be . false ;
950936 expect ( comboBox . value ) . to . equal ( 'item 12' ) ;
@@ -953,17 +939,15 @@ describe('lazy loading', () => {
953939 it ( 'should set first value of multiple matches that differ only in case' , ( ) => {
954940 returnedItems = [ 'item 12' , 'IteM 12' ] ;
955941
956- const filterValue = 'IteM 12' ;
957- comboBox . _inputElementValue = filterValue ;
958- comboBox . filter = filterValue ;
942+ setInputValue ( comboBox , 'IteM 12' ) ;
943+
959944 expect ( comboBox . opened ) . to . be . false ;
960945 expect ( comboBox . hasAttribute ( 'focused' ) ) . to . be . false ;
961946 expect ( comboBox . value ) . to . equal ( 'item 12' ) ;
962947 } ) ;
963948
964949 it ( 'should keep empty value if it is not an exact match' , ( ) => {
965- comboBox . _inputElementValue = 'item' ;
966- comboBox . filter = 'item' ;
950+ setInputValue ( comboBox , 'item' ) ;
967951 expect ( comboBox . opened ) . to . be . false ;
968952 expect ( comboBox . hasAttribute ( 'focused' ) ) . to . be . false ;
969953 expect ( comboBox . value ) . to . equal ( '' ) ;
@@ -975,9 +959,8 @@ describe('lazy loading', () => {
975959 expect ( comboBox . value ) . to . equal ( 'other value' ) ;
976960
977961 returnedItems = [ 'item 12' ] ;
978- const filterValue = 'item 1' ;
979- comboBox . _inputElementValue = filterValue ;
980- comboBox . filter = filterValue ;
962+ setInputValue ( comboBox , 'item 1' ) ;
963+
981964 expect ( comboBox . opened ) . to . be . false ;
982965 expect ( comboBox . hasAttribute ( 'focused' ) ) . to . be . false ;
983966 expect ( comboBox . value ) . to . equal ( 'other value' ) ;
@@ -986,14 +969,15 @@ describe('lazy loading', () => {
986969 it ( 'should keep previous value if allow-custom-value is set' , ( ) => {
987970 comboBox . allowCustomValue = true ;
988971 comboBox . open ( ) ;
989- setInputValue ( 'other value' ) ;
990- fire ( comboBox . inputElement , 'input' ) ;
972+ setInputValue ( comboBox , 'other value' ) ;
991973 comboBox . close ( ) ;
992974 expect ( comboBox . value ) . to . eql ( 'other value' ) ;
993975
994976 comboBox . focus ( ) ;
995- setInputValue ( 'item 12' ) ;
996- comboBox . filter = 'item 12' ;
977+ // FIXME: fails when using `setInputValue()`
978+ const filterValue = 'item 12' ;
979+ comboBox . inputElement . value = filterValue ;
980+ comboBox . filter = filterValue ;
997981
998982 expect ( comboBox . value ) . to . eql ( 'other value' ) ;
999983 expect ( comboBox . inputElement . value ) . to . eql ( 'other value' ) ;
0 commit comments