@@ -125,19 +125,19 @@ export class ToolBaseGenUIPage {
125125 return mainHaikuContent ;
126126 }
127127
128- async checkHaikuDisplay ( page : Page ) : Promise < void > {
129- const chatHaikuContent = await this . extractChatHaikuContent ( page ) ;
130-
131- await page . waitForTimeout ( 3000 ) ;
132-
133- // Check that the haiku exists somewhere in the carousel
128+ private async carouselIncludesHaiku (
129+ page : Page ,
130+ chatHaikuContent : string ,
131+ ) : Promise < boolean > {
134132 const carousel = page . locator ( '[data-testid="haiku-carousel"]' ) ;
135- await carousel . waitFor ( { state : "visible" , timeout : 10000 } ) ;
133+
134+ if ( ! ( await carousel . isVisible ( ) ) ) {
135+ return false ;
136+ }
136137
137138 const allCarouselCards = carousel . locator ( '[data-testid="haiku-card"]' ) ;
138139 const cardCount = await allCarouselCards . count ( ) ;
139140
140- let foundMatch = false ;
141141 for ( let i = 0 ; i < cardCount ; i ++ ) {
142142 const card = allCarouselCards . nth ( i ) ;
143143 const lines = card . locator ( '[data-testid="haiku-japanese-line"]' ) ;
@@ -151,11 +151,21 @@ export class ToolBaseGenUIPage {
151151
152152 const cardContent = cardLines . join ( "" ) . replace ( / \s / g, "" ) ;
153153 if ( cardContent === chatHaikuContent ) {
154- foundMatch = true ;
155- break ;
154+ return true ;
156155 }
157156 }
158157
159- expect ( foundMatch ) . toBe ( true ) ;
158+ return false ;
159+ }
160+
161+ async checkHaikuDisplay ( page : Page ) : Promise < void > {
162+ const chatHaikuContent = await this . extractChatHaikuContent ( page ) ;
163+
164+ await expect
165+ . poll (
166+ async ( ) => this . carouselIncludesHaiku ( page , chatHaikuContent ) ,
167+ { timeout : 20000 , intervals : [ 500 , 1000 , 2000 ] } ,
168+ )
169+ . toBe ( true ) ;
160170 }
161171}
0 commit comments