Skip to content

Commit 01cab61

Browse files
tests: stabilize ToolBaseGenUIPage haiku comparison
1 parent a61605a commit 01cab61

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

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

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,49 +73,55 @@ export class ToolBaseGenUIPage {
7373
}
7474

7575
async extractMainDisplayHaikuContent(page: Page): Promise<string> {
76-
// Wait for main haiku lines to be present
77-
const mainDisplayLines = page.locator('[data-testid="main-haiku-line"]');
78-
const mainCount = await mainDisplayLines.count();
76+
const activeCard = page.locator('[data-testid="main-haiku-display"].active').last();
77+
78+
try {
79+
await activeCard.waitFor({ state: 'visible', timeout: 5000 });
80+
} catch (error) {
81+
// Fallback to any visible haiku lines if the active card isn't available yet
82+
const fallbackLines = page.locator('[data-testid="main-haiku-line"]');
83+
const fallbackCount = await fallbackLines.count();
84+
if (fallbackCount === 0) {
85+
return '';
86+
}
87+
88+
const fallbackLineTexts: string[] = [];
89+
for (let i = 0; i < fallbackCount; i++) {
90+
const fallbackLine = fallbackLines.nth(i);
91+
const japaneseText = await fallbackLine.locator('p').first().innerText();
92+
fallbackLineTexts.push(japaneseText);
93+
}
7994

80-
if (mainCount === 0) {
95+
return fallbackLineTexts.join('').replace(/\s/g, '');
96+
}
97+
98+
const mainDisplayLines = activeCard.locator('[data-testid="main-haiku-line"]');
99+
const count = await mainDisplayLines.count();
100+
if (count === 0) {
81101
return '';
82102
}
83103

84-
// Take only the last 3 lines (most recent haiku)
85-
// Haikus are 3 lines, and they're appended in order
86-
const startIndex = Math.max(0, mainCount - 3);
87104
const lines: string[] = [];
88-
89-
for (let i = startIndex; i < mainCount; i++) {
105+
for (let i = 0; i < count; i++) {
90106
const haikuLine = mainDisplayLines.nth(i);
91107
const japaneseText = await haikuLine.locator('p').first().innerText();
92108
lines.push(japaneseText);
93109
}
94110

95-
const mainHaikuContent = lines.join('').replace(/\s/g, '');
96-
return mainHaikuContent;
111+
return lines.join('').replace(/\s/g, '');
97112
}
98113

99114
async checkHaikuDisplay(page: Page): Promise<void> {
100115
const chatHaikuContent = await this.extractChatHaikuContent(page);
101116

102-
await page.waitForTimeout(5000);
103-
104-
const mainHaikuContent = await this.extractMainDisplayHaikuContent(page);
105-
106-
if (mainHaikuContent === '') {
107-
expect(chatHaikuContent.length).toBeGreaterThan(0);
108-
return;
109-
}
110-
111-
if (chatHaikuContent === mainHaikuContent) {
112-
expect(mainHaikuContent).toBe(chatHaikuContent);
113-
} else {
114-
await page.waitForTimeout(3000);
115-
116-
const updatedMainContent = await this.extractMainDisplayHaikuContent(page);
117-
118-
expect(updatedMainContent).toBe(chatHaikuContent);
119-
}
117+
await expect
118+
.poll(async () => {
119+
const content = await this.extractMainDisplayHaikuContent(page);
120+
return content;
121+
}, {
122+
timeout: 10000,
123+
message: 'Main display did not match the latest chat haiku',
124+
})
125+
.toBe(chatHaikuContent);
120126
}
121127
}

0 commit comments

Comments
 (0)