Skip to content

Commit 3db7330

Browse files
Merge branch 'fix/issue-400-clean' into fix/issue-400-clean
2 parents 7b2d990 + 5aca8b3 commit 3db7330

File tree

1 file changed

+37
-59
lines changed

1 file changed

+37
-59
lines changed

typescript-sdk/apps/dojo/e2e/featurePages/ToolBaseGenUIPage.ts

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -85,77 +85,55 @@ export class ToolBaseGenUIPage {
8585
}
8686

8787
async extractMainDisplayHaikuContent(page: Page): Promise<string> {
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;
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 '';
10498
}
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, '');
105108
}
106109

107-
if (!activeCard) {
108-
// Fallback to first card if none found visible
109-
activeCard = carousel.locator('[data-testid="haiku-card"]').first();
110+
const mainDisplayLines = activeCard.locator('[data-testid="main-haiku-line"]');
111+
const count = await mainDisplayLines.count();
112+
if (count === 0) {
113+
return '';
110114
}
111115

112-
const mainDisplayLines = activeCard.locator('[data-testid="haiku-japanese-line"]');
113-
const mainCount = await mainDisplayLines.count();
114116
const lines: string[] = [];
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-
}
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);
122121
}
123122

124-
const mainHaikuContent = lines.join("").replace(/\s/g, "");
125-
return mainHaikuContent;
123+
return lines.join('').replace(/\s/g, '');
126124
}
127125

128126
async checkHaikuDisplay(page: Page): Promise<void> {
129127
const chatHaikuContent = await this.extractChatHaikuContent(page);
130128

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);
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);
160138
}
161139
}

0 commit comments

Comments
 (0)