test: target question card title by testid instead of text

Add data-testid to NativeChatQuestionCard's title element and update the
e2e test to query by testid with a text filter. The transcript row also
renders the question text, so the previous test could match either location,
causing flaky results. Gating on the card's own title node ensures the
assertion verifies the card is actually rendered.

Fixes #20724
This commit is contained in:
Jinjing
2026-09-16 21:25:05 -07:00
parent 77cd61df39
commit bbd449ad75
2 changed files with 15 additions and 4 deletions
@@ -159,7 +159,10 @@ export function NativeChatQuestionCard({
<div className="overflow-hidden rounded-lg border border-input bg-card shadow-xs">
<div className="flex items-start justify-between gap-2 px-3.5 py-2.5">
<p className="min-w-0 break-words text-sm font-semibold text-foreground">
<p
data-testid="native-chat-question-card-title"
className="min-w-0 break-words text-sm font-semibold text-foreground"
>
{q.question}
</p>
<button
@@ -139,7 +139,13 @@ test.describe('Desktop chat AskUserQuestion card (#11761)', () => {
// The pre-fix build leaves the composer mounted here and never renders a
// card, so this assertion is what actually gates the regression.
await expect(orcaPage.getByText(QUESTION)).toBeVisible({ timeout: 10_000 })
// Why (#20724): the transcript row renders the pending question in an
// awaiting-input row as well as the card, so gate on the card's own
// title node instead of any text match.
const cardQuestion = orcaPage
.getByTestId('native-chat-question-card-title')
.filter({ hasText: QUESTION })
await expect(cardQuestion).toBeVisible({ timeout: 10_000 })
await expect(orcaPage.getByRole('button', { name: /Spaces/ })).toBeVisible()
await orcaPage.screenshot({ path: path.join(screenshotDir, '01-question-card.png') })
@@ -151,8 +157,10 @@ test.describe('Desktop chat AskUserQuestion card (#11761)', () => {
await orcaPage.getByRole('button', { name: 'Submit' }).click()
// The card owns the composer slot, so its disappearance is the visible
// signal that the answer was accepted and chat input came back.
await expect(orcaPage.getByText(QUESTION)).toHaveCount(0, { timeout: 20_000 })
// signal that the answer was accepted and chat input came back. The
// resolution receipt keeps the question in the transcript row, so only
// the card paragraph is expected to leave.
await expect(cardQuestion).toHaveCount(0, { timeout: 20_000 })
await orcaPage.screenshot({ path: path.join(screenshotDir, '03-answered.png') })
} finally {
rmSync(scratchDir, { recursive: true, force: true })