@@ -414,110 +414,4 @@ describe('AutocompleteController', () => {
414414 } ) ;
415415 } ) ;
416416
417- it ( 'adds live-component support' , async ( ) => {
418- const container = mountDOM ( `
419- <div>
420- <label for="the-select" data-testid="main-element-label">Select something</label>
421- <select
422- id="the-select"
423- data-testid="main-element"
424- data-controller="check autocomplete"
425- ></select>
426- </div>
427- ` ) ;
428-
429- application = startStimulus ( ) ;
430-
431- await waitFor ( ( ) => {
432- expect ( getByTestId ( container , 'main-element' ) ) . toHaveClass ( 'connected' ) ;
433- } ) ;
434-
435- expect ( getByTestId ( container , 'main-element' ) ) . toHaveAttribute ( 'data-live-ignore' ) ;
436- expect ( getByTestId ( container , 'main-element-label' ) ) . toHaveAttribute ( 'data-live-ignore' ) ;
437- const tsDropdown = container . querySelector ( '.ts-wrapper' ) ;
438-
439- await waitFor ( ( ) => {
440- expect ( tsDropdown ) . not . toBeNull ( ) ;
441- } ) ;
442- expect ( tsDropdown ) . toHaveAttribute ( 'data-live-ignore' ) ;
443- } ) ;
444-
445- it ( 'loads new pages on scroll' , async ( ) => {
446- const container = mountDOM ( `
447- <label for="the-select">Items</label>
448- <select
449- id="the-select"
450- data-testid="main-element"
451- data-controller="check autocomplete"
452- data-autocomplete-url-value="/path/to/autocomplete"
453- ></select>
454- ` ) ;
455- document . addEventListener ( 'autocomplete:pre-connect' , ( event ) => {
456- const options = event . detail . options ;
457- // make it so that as soon as we trigger a scroll, tomselect thinks
458- // more need to be loaded
459- options . shouldLoadMore = ( ) => true ;
460- } ) ;
461-
462- application = startStimulus ( ) ;
463-
464- await waitFor ( ( ) => {
465- expect ( getByTestId ( container , 'main-element' ) ) . toHaveClass ( 'connected' ) ;
466- } ) ;
467-
468- // initial Ajax request on focus
469- fetchMock . mock (
470- '/path/to/autocomplete?query=' ,
471- JSON . stringify ( {
472- results : {
473- options : [
474- { value : 1 , text : 'dog1' } ,
475- { value : 2 , text : 'dog2' } ,
476- { value : 3 , text : 'dog3' } ,
477- { value : 4 , text : 'dog4' } ,
478- { value : 5 , text : 'dog5' } ,
479- { value : 6 , text : 'dog6' } ,
480- { value : 7 , text : 'dog7' } ,
481- { value : 8 , text : 'dog8' } ,
482- { value : 9 , text : 'dog9' } ,
483- { value : 10 , text : 'dog10' } ,
484- ]
485- } ,
486- next_page : '/path/to/autocomplete?query=&page=2'
487- } ) ,
488- ) ;
489-
490- const tomSelect = getTomSelectInstance ( container ) ;
491- const controlInput = tomSelect . control_input ;
492-
493- // wait for the initial Ajax request to finish
494- userEvent . click ( controlInput ) ;
495- await waitFor ( ( ) => {
496- expect ( container . querySelectorAll ( '.option[data-selectable]' ) ) . toHaveLength ( 11 ) ; // should be 10, but for some reason dropdown immediately shows "loading more results"
497- } ) ;
498- const dropdownContent = container . querySelector ( '.ts-dropdown-content' ) ;
499- if ( ! dropdownContent ) {
500- throw new Error ( 'cannot find dropdown content element' ) ;
501- }
502-
503- fetchMock . mock (
504- '/path/to/autocomplete?query=&page=2' ,
505- JSON . stringify ( {
506- results : {
507- options : [
508- { value : 11 , text : 'dog11' } ,
509- { value : 12 , text : 'dog12' } ,
510- ] ,
511- next_page : null ,
512- }
513- } ) ,
514- ) ;
515-
516- // trigger a scroll, this will cause TomSelect to check "shouldLoadMore"
517- dropdownContent . dispatchEvent ( new Event ( 'scroll' ) ) ;
518-
519- await waitFor ( ( ) => {
520- expect ( container . querySelectorAll ( '.option[data-selectable]' ) ) . toHaveLength ( 12 ) ;
521- } ) ;
522- } ) ;
523417} ) ;
0 commit comments