@@ -262,13 +262,14 @@ test.describe('Player Summary Statistics', () => {
262262 test ( 'should show confirmation dialog when sync button clicked' , async ( { page } ) => {
263263 // Navigate to Management tab
264264 await page . waitForSelector ( 'nav[aria-label="Tabs"]' , { timeout : 10000 } ) ;
265- await page . locator ( 'button:has-text("Management")' ) . click ( ) ;
266- await page . waitForTimeout ( 500 ) ;
265+ const managementTab = page . locator ( 'button:has-text("Management")' ) ;
266+ await managementTab . click ( ) ;
267+ await managementTab . waitFor ( { state : 'visible' } ) ;
267268
268269 // Click sync button
269270 const syncButton = page . locator ( 'button:has-text("Sync Fixtures")' ) ;
271+ await syncButton . waitFor ( { state : 'visible' } ) ;
270272 await syncButton . click ( ) ;
271- await page . waitForTimeout ( 300 ) ;
272273
273274 // Check for confirmation dialog
274275 const dialogHeading = page . locator ( 'h3:has-text("Confirm Fixture Sync")' ) ;
@@ -282,7 +283,6 @@ test.describe('Player Summary Statistics', () => {
282283
283284 // Cancel the dialog
284285 await cancelButton . click ( ) ;
285- await page . waitForTimeout ( 300 ) ;
286286
287287 // Dialog should be hidden
288288 await expect ( dialogHeading ) . not . toBeVisible ( ) ;
@@ -291,25 +291,30 @@ test.describe('Player Summary Statistics', () => {
291291 test ( 'should show loading state during sync' , async ( { page } ) => {
292292 // Navigate to Management tab
293293 await page . waitForSelector ( 'nav[aria-label="Tabs"]' , { timeout : 10000 } ) ;
294- await page . locator ( 'button:has-text("Management")' ) . click ( ) ;
295- await page . waitForTimeout ( 500 ) ;
294+ const managementTab = page . locator ( 'button:has-text("Management")' ) ;
295+ await managementTab . click ( ) ;
296+ await managementTab . waitFor ( { state : 'visible' } ) ;
296297
297298 // Click sync button
298299 const syncButton = page . locator ( 'button:has-text("Sync Fixtures")' ) ;
300+ await syncButton . waitFor ( { state : 'visible' } ) ;
299301 await syncButton . click ( ) ;
300- await page . waitForTimeout ( 300 ) ;
301302
302303 // Click Sync Now
303304 const syncNowButton = page . locator ( 'button:has-text("Sync Now")' ) ;
305+ await syncNowButton . waitFor ( { state : 'visible' } ) ;
304306 await syncNowButton . click ( ) ;
305307
306- // Should show loading state (briefly)
307- // Note: This might be too fast to catch in real scenarios
308- const syncingButton = page . locator ( 'button:has-text("Syncing...")' ) ;
309- // We don't assert visibility because sync might complete too quickly
310-
311- // Wait for sync to complete - look for success notification or completion
312- await page . waitForTimeout ( 2000 ) ;
308+ // Wait for sync operation to complete
309+ // Either the button will briefly show "Syncing..." or sync completes immediately
310+ try {
311+ // Try to wait for the syncing state to appear and then disappear
312+ const syncingButton = page . locator ( 'button:has-text("Syncing...")' ) ;
313+ await syncingButton . waitFor ( { state : 'visible' , timeout : 1000 } ) ;
314+ await syncingButton . waitFor ( { state : 'hidden' , timeout : 5000 } ) ;
315+ } catch {
316+ // Sync might complete too quickly to catch the intermediate state
317+ }
313318
314319 // After sync, button should be back to normal state
315320 await expect ( syncButton ) . toBeVisible ( ) ;
0 commit comments