@@ -41,6 +41,12 @@ async function waitForBoardShell(page: Page): Promise<void> {
4141 await dismissOverlays ( page ) ;
4242}
4343
44+ async function waitForToolbar ( page : Page ) : Promise < void > {
45+ await expect ( page . getByRole ( 'button' , { name : 'Select' } ) . first ( ) ) . toBeVisible ( {
46+ timeout : 30000 ,
47+ } ) ;
48+ }
49+
4450export async function waitForMainBoard ( page : Page ) : Promise < void > {
4551 let lastError : unknown ;
4652
@@ -186,6 +192,8 @@ export async function selectTool(page: Page, toolName: string): Promise<boolean>
186192 await page . waitForTimeout ( 100 ) ;
187193 }
188194
195+ await waitForToolbar ( page ) ;
196+
189197 const directToolLabels : Record < string , string > = {
190198 arrow : 'Arrow' ,
191199 select : 'Select' ,
@@ -230,9 +238,10 @@ export async function selectTool(page: Page, toolName: string): Promise<boolean>
230238 if ( toolName in shapeToolLabels ) {
231239 const dropdownButton = page
232240 . getByTestId ( 'shapes-dropdown-trigger' )
241+ . or ( page . getByRole ( 'button' , { name : 'Shapes' } ) )
233242 . first ( ) ;
234243
235- if ( ! ( await dropdownButton . isVisible ( { timeout : 3000 } ) . catch ( ( ) => false ) ) ) {
244+ if ( ! ( await dropdownButton . isVisible ( { timeout : 10000 } ) . catch ( ( ) => false ) ) ) {
236245 return false ;
237246 }
238247
@@ -264,15 +273,18 @@ export async function getElementCount(page: Page): Promise<number> {
264273 return page . evaluate ( ( ) => {
265274 const boardRoot = document . querySelector ( '[data-board="true"]' ) ;
266275 const count = boardRoot ?. getAttribute ( 'data-element-count' ) ;
276+ const renderedElementCount = document . querySelectorAll (
277+ '.board-wrapper [plait-data-id]' ,
278+ ) . length ;
267279
268280 if ( count !== null && count !== undefined ) {
269281 const parsed = Number . parseInt ( count , 10 ) ;
270282 if ( ! Number . isNaN ( parsed ) ) {
271- return parsed ;
283+ return Math . max ( parsed , renderedElementCount ) ;
272284 }
273285 }
274286
275- return document . querySelectorAll ( '.board-wrapper [plait-data-id]' ) . length ;
287+ return renderedElementCount ;
276288 } ) ;
277289}
278290
0 commit comments