66 within ,
77 userEvent ,
88 renderWithConnections ,
9+ waitFor ,
910} from '@mongodb-js/testing-library-compass' ;
1011import type { PreferencesAccess } from 'compass-preferences-model' ;
1112import { createSandboxFromDefaultPreferences } from 'compass-preferences-model' ;
@@ -20,6 +21,7 @@ const noop = () => {
2021
2122const testOutdatedMessageId = 'crud-outdated-message-id' ;
2223const testErrorMessageId = 'document-list-error-summary' ;
24+ const testDocumentsPerPageId = 'crud-document-per-page-selector' ;
2325
2426const addDataText = 'Add Data' ;
2527const updateDataText = 'Update' ;
@@ -480,20 +482,24 @@ describe('CrudToolbar Component', function () {
480482 } ) ;
481483
482484 describe ( 'documents per page select' , function ( ) {
483- it ( 'should render a select to update documents fetched per page' , function ( ) {
485+ it ( 'should render a select to update documents fetched per page' , async function ( ) {
484486 renderCrudToolbar ( ) ;
485- expect ( screen . getByLabelText ( 'Update number of documents per page' ) ) . to . be
486- . visible ;
487+
488+ await waitFor (
489+ ( ) => expect ( screen . getByTestId ( testDocumentsPerPageId ) ) . to . be . visible
490+ ) ;
487491 } ) ;
488492
489- it ( 'should call updateDocumentsPerPage when select value changes' , function ( ) {
493+ it ( 'should call updateDocumentsPerPage when select value changes' , async function ( ) {
490494 const stub = sinon . stub ( ) ;
491495 renderCrudToolbar ( {
492496 updateMaxDocumentsPerPage : stub ,
493497 } ) ;
494- userEvent . click (
495- screen . getByLabelText ( 'Update number of documents per page' )
496- ) ;
498+
499+ const selector = screen . getByTestId ( testDocumentsPerPageId ) ;
500+
501+ await waitFor ( ( ) => expect ( selector ) . to . be . visible ) ;
502+ userEvent . click ( selector ) ;
497503 userEvent . click ( screen . getByText ( '75' ) ) ;
498504 expect ( stub ) . to . be . calledWithExactly ( 75 ) ;
499505 } ) ;
0 commit comments