@@ -49,25 +49,9 @@ test("user search test", async ({ page }) => {
4949 hasText : "Internal User" ,
5050 } ) ;
5151
52- // Wait for the tab to be visible
53- await internalUserTab . waitFor ( { state : "visible" , timeout : 10000 } ) ;
54- console . log ( "Internal User tab is visible" ) ;
55-
56- // Take another screenshot before clicking
57- await page . screenshot ( { path : "before-tab-click.png" } ) ;
58- console . log ( "Took screenshot before tab click" ) ;
59-
60- await internalUserTab . click ( ) ;
61- console . log ( "Clicked Internal User tab" ) ;
62-
6352 // Wait for the page to load and table to be visible
6453 await page . waitForSelector ( "tbody tr" , { timeout : 10000 } ) ;
6554 await page . waitForTimeout ( 2000 ) ; // Additional wait for table to stabilize
66- console . log ( "Table is visible" ) ;
67-
68- // Take a final screenshot
69- await page . screenshot ( { path : "after-tab-click.png" } ) ;
70- console . log ( "Took screenshot after tab click" ) ;
7155
7256 // Verify search input exists
7357 const searchInput = page . locator ( 'input[placeholder="Search by email..."]' ) ;
@@ -83,7 +67,7 @@ test("user search test", async ({ page }) => {
8367 await searchInput . fill ( testEmail ) ;
8468 console . log ( "Filled search input" ) ;
8569
86- // Wait for the debounced search to complete
70+ // Wait for the debounced search to complete (300ms debounce + buffer)
8771 await page . waitForTimeout ( 500 ) ;
8872 console . log ( "Waited for debounce" ) ;
8973
@@ -94,15 +78,24 @@ test("user search test", async ({ page }) => {
9478 } , initialUserCount ) ;
9579 console . log ( "Results updated" ) ;
9680
81+ // Wait for the results count to update
82+ await page . waitForFunction ( ( initialCount ) => {
83+ const currentCount = document . querySelectorAll ( "tbody tr" ) . length ;
84+ return currentCount !== initialCount ;
85+ } , initialUserCount ) ;
86+
87+ // Get the filtered user count
9788 const filteredUserCount = await page . locator ( "tbody tr" ) . count ( ) ;
9889 console . log ( `Filtered user count: ${ filteredUserCount } ` ) ;
9990
91+ // Verify that the search results have been updated
10092 expect ( filteredUserCount ) . toBeDefined ( ) ;
10193
10294 // Clear the search
10395 await searchInput . clear ( ) ;
10496 console . log ( "Cleared search" ) ;
10597
98+ // Wait for the debounced search to complete
10699 await page . waitForTimeout ( 500 ) ;
107100 console . log ( "Waited for debounce after clear" ) ;
108101
@@ -112,6 +105,13 @@ test("user search test", async ({ page }) => {
112105 } , initialUserCount ) ;
113106 console . log ( "Results reset" ) ;
114107
108+ // Wait for the results to return to initial state
109+ await page . waitForFunction ( ( initialCount ) => {
110+ const currentCount = document . querySelectorAll ( "tbody tr" ) . length ;
111+ return currentCount === initialCount ;
112+ } , initialUserCount ) ;
113+
114+ // Verify the list returns to its original state
115115 const resetUserCount = await page . locator ( "tbody tr" ) . count ( ) ;
116116 console . log ( `Reset user count: ${ resetUserCount } ` ) ;
117117
0 commit comments