@@ -85,55 +85,77 @@ export class ToolBaseGenUIPage {
8585 }
8686
8787 async extractMainDisplayHaikuContent ( page : Page ) : Promise < string > {
88- const activeCard = page . locator ( '[data-testid="main-haiku-display"].active' ) . last ( ) ;
89-
90- try {
91- await activeCard . waitFor ( { state : 'visible' , timeout : 5000 } ) ;
92- } catch ( error ) {
93- // Fallback to any visible haiku lines if the active card isn't available yet
94- const fallbackLines = page . locator ( '[data-testid="main-haiku-line"]' ) ;
95- const fallbackCount = await fallbackLines . count ( ) ;
96- if ( fallbackCount === 0 ) {
97- return '' ;
88+ await page . waitForTimeout ( 2000 ) ;
89+ const carousel = page . locator ( '[data-testid="haiku-carousel"]' ) ;
90+ await carousel . waitFor ( { state : "visible" , timeout : 10000 } ) ;
91+
92+ // Find the visible carousel item (the active slide)
93+ const carouselItems = carousel . locator ( '[data-testid^="carousel-item-"]' ) ;
94+ const itemCount = await carouselItems . count ( ) ;
95+ let activeCard = null ;
96+
97+ // Find the visible/active carousel item
98+ for ( let i = 0 ; i < itemCount ; i ++ ) {
99+ const item = carouselItems . nth ( i ) ;
100+ const isVisible = await item . isVisible ( ) ;
101+ if ( isVisible ) {
102+ activeCard = item . locator ( '[data-testid="haiku-card"]' ) ;
103+ break ;
98104 }
99-
100- const fallbackLineTexts : string [ ] = [ ] ;
101- for ( let i = 0 ; i < fallbackCount ; i ++ ) {
102- const fallbackLine = fallbackLines . nth ( i ) ;
103- const japaneseText = await fallbackLine . locator ( 'p' ) . first ( ) . innerText ( ) ;
104- fallbackLineTexts . push ( japaneseText ) ;
105- }
106-
107- return fallbackLineTexts . join ( '' ) . replace ( / \s / g, '' ) ;
108105 }
109106
110- const mainDisplayLines = activeCard . locator ( '[data-testid="main-haiku-line"]' ) ;
111- const count = await mainDisplayLines . count ( ) ;
112- if ( count === 0 ) {
113- return '' ;
107+ if ( ! activeCard ) {
108+ // Fallback to first card if none found visible
109+ activeCard = carousel . locator ( '[data-testid="haiku-card"]' ) . first ( ) ;
114110 }
115111
112+ const mainDisplayLines = activeCard . locator ( '[data-testid="haiku-japanese-line"]' ) ;
113+ const mainCount = await mainDisplayLines . count ( ) ;
116114 const lines : string [ ] = [ ] ;
117- for ( let i = 0 ; i < count ; i ++ ) {
118- const haikuLine = mainDisplayLines . nth ( i ) ;
119- const japaneseText = await haikuLine . locator ( 'p' ) . first ( ) . innerText ( ) ;
120- lines . push ( japaneseText ) ;
115+
116+ if ( mainCount > 0 ) {
117+ for ( let i = 0 ; i < mainCount ; i ++ ) {
118+ const haikuLine = mainDisplayLines . nth ( i ) ;
119+ const japaneseText = await haikuLine . innerText ( ) ;
120+ lines . push ( japaneseText ) ;
121+ }
121122 }
122123
123- return lines . join ( '' ) . replace ( / \s / g, '' ) ;
124+ const mainHaikuContent = lines . join ( "" ) . replace ( / \s / g, "" ) ;
125+ return mainHaikuContent ;
124126 }
125127
126128 async checkHaikuDisplay ( page : Page ) : Promise < void > {
127129 const chatHaikuContent = await this . extractChatHaikuContent ( page ) ;
128130
129- await expect
130- . poll ( async ( ) => {
131- const content = await this . extractMainDisplayHaikuContent ( page ) ;
132- return content ;
133- } , {
134- timeout : 10000 ,
135- message : 'Main display did not match the latest chat haiku' ,
136- } )
137- . toBe ( chatHaikuContent ) ;
131+ await page . waitForTimeout ( 3000 ) ;
132+
133+ // Check that the haiku exists somewhere in the carousel
134+ const carousel = page . locator ( '[data-testid="haiku-carousel"]' ) ;
135+ await carousel . waitFor ( { state : "visible" , timeout : 10000 } ) ;
136+
137+ const allCarouselCards = carousel . locator ( '[data-testid="haiku-card"]' ) ;
138+ const cardCount = await allCarouselCards . count ( ) ;
139+
140+ let foundMatch = false ;
141+ for ( let i = 0 ; i < cardCount ; i ++ ) {
142+ const card = allCarouselCards . nth ( i ) ;
143+ const lines = card . locator ( '[data-testid="haiku-japanese-line"]' ) ;
144+ const lineCount = await lines . count ( ) ;
145+ const cardLines : string [ ] = [ ] ;
146+
147+ for ( let j = 0 ; j < lineCount ; j ++ ) {
148+ const text = await lines . nth ( j ) . innerText ( ) ;
149+ cardLines . push ( text ) ;
150+ }
151+
152+ const cardContent = cardLines . join ( "" ) . replace ( / \s / g, "" ) ;
153+ if ( cardContent === chatHaikuContent ) {
154+ foundMatch = true ;
155+ break ;
156+ }
157+ }
158+
159+ expect ( foundMatch ) . toBe ( true ) ;
138160 }
139161}
0 commit comments