11import { test , expect } from "@playwright/test" ;
22
3+ async function retryClickAndCheckTestIdText (
4+ page ,
5+ buttonTestId ,
6+ valueTestId ,
7+ expectedText ,
8+ retries = 10 ,
9+ delay = 500
10+ ) {
11+ for ( let i = 0 ; i < retries ; i ++ ) {
12+ await page . getByTestId ( buttonTestId ) . click ( ) ;
13+ const text = await page . getByTestId ( valueTestId ) . textContent ( ) ;
14+ if ( text ?. includes ( expectedText ) ) {
15+ expect ( text ) . toContain ( expectedText ) ; // Assert condition
16+ return ;
17+ }
18+ await page . waitForTimeout ( delay ) ;
19+ }
20+ throw new Error (
21+ `Text "${ expectedText } " not found in "${ valueTestId } " after ${ retries } retries.`
22+ ) ;
23+ }
24+
325test ( "maxChunks and cleanup" , async ( { page } ) => {
426 await page . goto ( "http://localhost:3000/#size=32" ) ;
527 await page . getByLabel ( "Max total chunks:" ) . dblclick ( ) ;
@@ -12,32 +34,14 @@ test("maxChunks and cleanup", async ({ page }) => {
1234 await page . getByLabel ( "Item size (KiB): *" ) . fill ( "1300" ) ;
1335 await page . goto ( "http://localhost:3000/#size=1300" ) ;
1436 await page . getByTestId ( "set-item-button" ) . click ( ) ;
15- // ensures enough time for IDB to take effect
16- await page . getByTestId ( "count-button" ) . click ( ) ;
17- await page . getByTestId ( "count-button" ) . click ( ) ;
18- await page . getByTestId ( "count-button" ) . click ( ) ;
19- await page . getByTestId ( "count-button" ) . click ( ) ;
20- await page . getByTestId ( "count-button" ) . click ( ) ;
21- await page . getByTestId ( "count-button" ) . click ( ) ;
22- await page . getByTestId ( "count-button" ) . click ( ) ;
23- await page . getByTestId ( "count-button" ) . click ( ) ;
24- await page . getByTestId ( "count-button" ) . click ( ) ;
25- await page . getByTestId ( "count-button" ) . click ( ) ;
26- await expect ( page . getByText ( "52" ) ) . toBeVisible ( ) ;
37+ await retryClickAndCheckTestIdText ( page , "count-button" , "count-value" , "52" ) ;
2738 await page . getByTestId ( "set-item-button" ) . click ( ) ;
28- // ensures enough time for IDB to take effect
29- await page . getByTestId ( "count-button" ) . click ( ) ;
30- await page . getByTestId ( "count-button" ) . click ( ) ;
31- await page . getByTestId ( "count-button" ) . click ( ) ;
32- await page . getByTestId ( "count-button" ) . click ( ) ;
33- await page . getByTestId ( "count-button" ) . click ( ) ;
34- await expect ( page . getByText ( "104" ) ) . toBeVisible ( ) ;
39+ await retryClickAndCheckTestIdText (
40+ page ,
41+ "count-button" ,
42+ "count-value" ,
43+ "104"
44+ ) ;
3545 await page . getByTestId ( "cleanup-button" ) . click ( ) ;
36- // ensures enough time for IDB to take effect
37- await page . getByTestId ( "count-button" ) . click ( ) ;
38- await page . getByTestId ( "count-button" ) . click ( ) ;
39- await page . getByTestId ( "count-button" ) . click ( ) ;
40- await page . getByTestId ( "count-button" ) . click ( ) ;
41- await page . getByTestId ( "count-button" ) . click ( ) ;
42- await expect ( page . getByText ( "52" ) ) . toBeVisible ( ) ;
46+ await retryClickAndCheckTestIdText ( page , "count-button" , "count-value" , "52" ) ;
4347} ) ;
0 commit comments