@@ -18,11 +18,9 @@ test.describe('Async Formula', () => {
1818 // Before waiting, cells should be empty or show pending state
1919 expect ( await a1 . locator ( '.gs-cell-rendered' ) . textContent ( ) ) . toBe ( '' ) ;
2020
21- // Wait for async results to resolve
22- // Chain: A1 (750ms) → A2 (750ms) → A3 (750ms) → A4 (750ms) = ~3s
23- // A5, A6, A7 use literal args so they resolve in first cycle (~750ms)
24- // Adding buffer for render time
25- await page . waitForTimeout ( 5000 ) ;
21+ // Wait for the slowest cell in the chain (A4) to resolve
22+ // Chain: A1 → A2 → A3 → A4
23+ await expect ( a4 . locator ( '.gs-cell-rendered' ) ) . toHaveText ( '360' , { timeout : 8000 } ) ;
2624
2725 // A1: SUM_DELAY(10, 20) = 30
2826 expect ( await a1 . locator ( '.gs-cell-rendered' ) . textContent ( ) ) . toBe ( '30' ) ;
@@ -75,11 +73,8 @@ test.describe('Async Formula', () => {
7573 // Initially, A1 should be empty
7674 expect ( await a1 . locator ( '.gs-cell-rendered' ) . textContent ( ) ) . toBe ( '' ) ;
7775
78- // Wait for first async computation (A1 takes 1 second + render time)
79- await page . waitForTimeout ( 1500 ) ;
80-
81- // A1 should have computed result
82- expect ( await a1 . locator ( '.gs-cell-rendered' ) . textContent ( ) ) . toBe ( '30' ) ;
76+ // Wait for first async computation (A1 takes ~750ms)
77+ await expect ( a1 . locator ( '.gs-cell-rendered' ) ) . toHaveText ( '30' , { timeout : 3000 } ) ;
8378
8479 // Click on another cell to trigger re-render without changing A1
8580 await b1 . click ( ) ;
@@ -95,31 +90,24 @@ test.describe('Async Formula', () => {
9590 const a1 = sheet . locator ( "[data-address='A1']" ) ;
9691 const a2 = sheet . locator ( "[data-address='A2']" ) ;
9792
98- // Wait for first async computation
99- // A1 takes 1s, then A2 depends on A1 (another 1s) = 2s + buffer
100- await page . waitForTimeout ( 3000 ) ;
101-
102- // A2 should depend on A1, initial value: SUM_DELAY(30, 100) = 130
103- let a2Content = await a2 . locator ( '.gs-cell-rendered' ) . textContent ( ) ;
104- expect ( a2Content ) . toBe ( '130' ) ;
93+ // Wait for first async computation: A1 (1s) → A2 (1s)
94+ await expect ( a2 . locator ( '.gs-cell-rendered' ) ) . toHaveText ( '130' , { timeout : 5000 } ) ;
10595
106- // Change A1 value by double-clicking to enter edit mode
10796 // Change A1 value by clicking and typing into the formula bar to ensure replacement
10897 await a1 . click ( ) ;
10998 const formulaBar = sheet . locator ( '.gs-formula-bar textarea' ) ;
11099 await formulaBar . fill ( '=SUM_DELAY(40, 50)' ) ;
111100 await formulaBar . press ( 'Enter' ) ;
112101
113- // Wait for re-computation: A1 takes 1s, then A2 depends on new A1 (another 1s) = 2s + buffer
114- await page . waitForTimeout ( 3000 ) ;
102+ // Wait for re-computation: A1 takes 1s, then A2 depends on new A1 (another 1s)
103+ await expect ( a1 . locator ( '.gs-cell-rendered' ) ) . toHaveText ( '90' , { timeout : 5000 } ) ;
115104
116105 // A1 should now be 90 (40 + 50)
117106 const a1NewContent = await a1 . locator ( '.gs-cell-rendered' ) . textContent ( ) ;
118107 expect ( a1NewContent ) . toBe ( '90' ) ;
119108
120109 // A2 should be updated to SUM_DELAY(90, 100) = 190
121- const a2NewContent = await a2 . locator ( '.gs-cell-rendered' ) . textContent ( ) ;
122- expect ( a2NewContent ) . toBe ( '190' ) ;
110+ await expect ( a2 . locator ( '.gs-cell-rendered' ) ) . toHaveText ( '190' , { timeout : 5000 } ) ;
123111 } ) ;
124112
125113 test ( 'should propagate pending through async dependency chain' , async ( { page } ) => {
@@ -136,15 +124,9 @@ test.describe('Async Formula', () => {
136124 const a4InitialContent = await a4 . locator ( '.gs-cell-rendered' ) . textContent ( ) ;
137125 expect ( a4InitialContent ) . toBe ( '' ) ;
138126
139- // Wait for async dependency chain to resolve
140- // A1 (1s) → A2 (1s) → A3 (1s) → A4 (1s) = 4s + buffer
141- await page . waitForTimeout ( 5000 ) ;
142-
143- const a1Content = await a1 . locator ( '.gs-cell-rendered' ) . textContent ( ) ;
144- expect ( a1Content ) . toBe ( '30' ) ;
145-
146- const a4Content = await a4 . locator ( '.gs-cell-rendered' ) . textContent ( ) ;
147- expect ( a4Content ) . toBe ( '360' ) ;
127+ // Wait for async dependency chain to resolve: A1 → A2 → A3 → A4
128+ await expect ( a1 . locator ( '.gs-cell-rendered' ) ) . toHaveText ( '30' , { timeout : 8000 } ) ;
129+ await expect ( a4 . locator ( '.gs-cell-rendered' ) ) . toHaveText ( '360' , { timeout : 8000 } ) ;
148130 } ) ;
149131
150132 test ( 'should display async error code #ASYNC! when async function throws' , async ( { page } ) => {
@@ -155,8 +137,7 @@ test.describe('Async Formula', () => {
155137
156138 // A8 contains =SUM_DELAY() with no arguments, which should throw an error
157139 const a8Rendered = a8 . locator ( '.gs-cell-rendered' ) ;
158- // Verify that the error code is displayed after a short wait for React render
159- await page . waitForTimeout ( 500 ) ;
140+ await expect ( a8Rendered ) . not . toHaveText ( '' , { timeout : 3000 } ) ;
160141 const a8Content = await a8Rendered . textContent ( ) ;
161142 expect ( a8Content ?. trim ( ) ) . toBe ( '#ASYNC!' ) ;
162143 } ) ;
0 commit comments