11import React from 'react' ;
22import { expect } from 'chai' ;
3- import { screen , userEvent } from '@mongodb-js/testing-library-compass' ;
3+ import {
4+ screen ,
5+ userEvent ,
6+ waitFor ,
7+ } from '@mongodb-js/testing-library-compass' ;
48import SavedDiagramsList from './saved-diagrams-list' ;
59import { renderWithStore } from '../../test/setup-store' ;
610import type { DataModelingStore } from '../../test/setup-store' ;
@@ -43,22 +47,25 @@ describe('SavedDiagramsList', function () {
4347 context ( 'when there are no saved diagrams' , function ( ) {
4448 let store : DataModelingStore ;
4549
46- beforeEach ( function ( ) {
50+ beforeEach ( async function ( ) {
4751 const result = renderSavedDiagramsList ( ) ;
4852 store = result . store ;
53+
54+ // wait till the empty list is loaded
55+ await waitFor ( ( ) => {
56+ expect ( screen . getByTestId ( 'empty-content' ) ) . to . be . visible ;
57+ } ) ;
4958 } ) ;
5059
5160 it ( 'shows the empty state' , function ( ) {
5261 expect (
53- screen . getByText (
54- 'No saved Design, Visualize, and Evolve your Data Model'
55- )
56- ) . to . exist ;
62+ screen . getByText ( 'Design, Visualize, and Evolve your Data Model' )
63+ ) . to . be . visible ;
5764 } ) ;
5865
5966 it ( 'allows to start adding diagrams' , function ( ) {
6067 const createDiagramButton = screen . getByRole ( 'button' , {
61- name : 'Generate new diagram' ,
68+ name : 'Generate diagram' ,
6269 } ) ;
6370 expect ( store . getState ( ) . generateDiagramWizard . inProgress ) . to . be . false ;
6471 expect ( createDiagramButton ) . to . be . visible ;
@@ -70,17 +77,22 @@ describe('SavedDiagramsList', function () {
7077 context ( 'when there are diagrams' , function ( ) {
7178 let store : DataModelingStore ;
7279
73- beforeEach ( function ( ) {
80+ beforeEach ( async function ( ) {
7481 const result = renderSavedDiagramsList ( {
7582 loadAll : ( ) =>
7683 Promise . resolve ( [
7784 {
7885 id : 'diagram-1' ,
7986 name : 'Diagram 1' ,
80- } ,
87+ } as MongoDBDataModelDescription ,
8188 ] ) ,
8289 } ) ;
8390 store = result . store ;
91+
92+ // wait till the list is loaded
93+ await waitFor ( ( ) => {
94+ expect ( screen . getByTestId ( 'saved-diagram-list' ) ) . to . be . visible ;
95+ } ) ;
8496 } ) ;
8597
8698 it ( 'shows the list of diagrams' , function ( ) {
@@ -89,7 +101,7 @@ describe('SavedDiagramsList', function () {
89101
90102 it ( 'allows to add another diagram' , function ( ) {
91103 const createDiagramButton = screen . getByRole ( 'button' , {
92- name : 'Generate diagram' ,
104+ name : 'Generate new diagram' ,
93105 } ) ;
94106 expect ( store . getState ( ) . generateDiagramWizard . inProgress ) . to . be . false ;
95107 expect ( createDiagramButton ) . to . be . visible ;
0 commit comments