@@ -100,18 +100,35 @@ describe('Chat', () => {
100100 cy . get ( '.from-emerald-500' ) . scrollIntoView ( ) . wait ( 500 ) . click ( { force : true } )
101101 cy . url ( ) . should ( 'include' , '/knowledge' )
102102
103- // Wait longer for backend processing in CI environment
104- cy . wait ( 8000 )
103+ // Polling strategy: Try multiple times with reloads in between
104+ // Backend processing (chunking, embedding) can take longer in CI
105+ const maxAttempts = 5
106+ const attemptDelay = 5000
107+
108+ function checkForDocument ( attempt = 1 ) {
109+ cy . wait ( attemptDelay )
110+ cy . reload ( )
111+ cy . wait ( 2000 )
105112
106- // Reload the page to ensure fresh data
107- cy . reload ( )
108- cy . wait ( 2000 )
113+ cy . get ( 'body' ) . then ( ( $body ) => {
114+ const exists = $body . find ( '.overflow-y-auto > :nth-child(1) > .items-start' ) . length > 0
109115
110- // Verify the saved chat appears in knowledge base with longer timeout
111- cy . get ( '.rounded-xl > .w-80 > .overflow-y-auto > :nth-child(1)' , { timeout : 30000 } ) . should ( 'exist' )
116+ if ( ! exists && attempt < maxAttempts ) {
117+ cy . log ( `Document not found, attempt ${ attempt } /${ maxAttempts } , retrying...` )
118+ checkForDocument ( attempt + 1 )
119+ } else if ( ! exists ) {
120+ throw new Error ( `Document not found after ${ maxAttempts } attempts. Backend processing may have failed.` )
121+ }
122+ } )
123+ }
124+
125+ checkForDocument ( )
126+
127+ // Verify the saved chat appears in knowledge base
128+ cy . get ( '.rounded-xl > .w-80 > .overflow-y-auto > :nth-child(1)' , { timeout : 10000 } ) . should ( 'exist' )
112129
113130 // Verify the chat title appears in the knowledge base
114- cy . get ( '.overflow-y-auto > :nth-child(1) > .items-start > .flex-1 > .font-medium' , { timeout : 30000 } )
131+ cy . get ( '.overflow-y-auto > :nth-child(1) > .items-start > .flex-1 > .font-medium' , { timeout : 10000 } )
115132 . should ( 'exist' )
116133
117134 // Click on the knowledge base item
@@ -174,14 +191,32 @@ describe('Chat', () => {
174191 // Navigate back to knowledge base
175192 cy . get ( '.from-emerald-500' ) . scrollIntoView ( ) . wait ( 500 ) . click ( { force : true } )
176193 cy . url ( ) . should ( 'include' , '/knowledge' )
177- cy . wait ( 5000 )
178194
179- // Reload the page to ensure fresh data
180- cy . reload ( )
181- cy . wait ( 2000 )
195+ // Polling strategy: Try multiple times with reloads in between
196+ const maxAttempts = 5
197+ const attemptDelay = 5000
198+
199+ function checkForDocument ( attempt = 1 ) {
200+ cy . wait ( attemptDelay )
201+ cy . reload ( )
202+ cy . wait ( 2000 )
203+
204+ cy . get ( 'body' ) . then ( ( $body ) => {
205+ const exists = $body . find ( '.overflow-y-auto > :nth-child(1) > .items-start' ) . length > 0
206+
207+ if ( ! exists && attempt < maxAttempts ) {
208+ cy . log ( `Document not found, attempt ${ attempt } /${ maxAttempts } , retrying...` )
209+ checkForDocument ( attempt + 1 )
210+ } else if ( ! exists ) {
211+ throw new Error ( `Document not found after ${ maxAttempts } attempts` )
212+ }
213+ } )
214+ }
215+
216+ checkForDocument ( )
182217
183218 // Click on the saved chat again
184- cy . get ( '.overflow-y-auto > :nth-child(1) > .items-start' , { timeout : 30000 } ) . click ( )
219+ cy . get ( '.overflow-y-auto > :nth-child(1) > .items-start' , { timeout : 10000 } ) . click ( )
185220 cy . wait ( 3000 )
186221
187222 // Click on the inline-flex button to add tag
@@ -202,14 +237,32 @@ describe('Chat', () => {
202237 // Navigate to knowledge base
203238 cy . get ( '.from-emerald-500' ) . scrollIntoView ( ) . wait ( 500 ) . click ( { force : true } )
204239 cy . url ( ) . should ( 'include' , '/knowledge' )
205- cy . wait ( 5000 )
206240
207- // Reload the page to ensure fresh data
208- cy . reload ( )
209- cy . wait ( 2000 )
241+ // Polling strategy: Try multiple times with reloads in between
242+ const maxAttempts = 5
243+ const attemptDelay = 5000
244+
245+ function checkForDocument ( attempt = 1 ) {
246+ cy . wait ( attemptDelay )
247+ cy . reload ( )
248+ cy . wait ( 2000 )
249+
250+ cy . get ( 'body' ) . then ( ( $body ) => {
251+ const exists = $body . find ( '.overflow-y-auto > :nth-child(1) > .items-start' ) . length > 0
252+
253+ if ( ! exists && attempt < maxAttempts ) {
254+ cy . log ( `Document not found, attempt ${ attempt } /${ maxAttempts } , retrying...` )
255+ checkForDocument ( attempt + 1 )
256+ } else if ( ! exists ) {
257+ throw new Error ( `Document not found after ${ maxAttempts } attempts` )
258+ }
259+ } )
260+ }
261+
262+ checkForDocument ( )
210263
211264 // Click on the saved chat to open it
212- cy . get ( '.overflow-y-auto > :nth-child(1) > .items-start' , { timeout : 30000 } ) . click ( )
265+ cy . get ( '.overflow-y-auto > :nth-child(1) > .items-start' , { timeout : 10000 } ) . click ( )
213266 cy . wait ( 3000 )
214267
215268 // Click the edit button
0 commit comments