Skip to content

Commit de3ea3f

Browse files
committed
feat: add data-testid attribute for custom answer confirmation in wizard components
1 parent fcab04f commit de3ea3f

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

components/instructions-wizard.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,10 @@ export function InstructionsWizard({
877877
</div>
878878
</form>
879879
{hasSavedCustomFreeText ? (
880-
<p className="flex items-center gap-2 text-xs font-semibold text-emerald-600 dark:text-emerald-400">
880+
<p
881+
className="flex items-center gap-2 text-xs font-semibold text-emerald-600 dark:text-emerald-400"
882+
data-testid="custom-answer-confirmation"
883+
>
881884
<CheckCircle2 className="h-3.5 w-3.5" />
882885
<span>
883886
We'll use

components/wizard-edit-answer-dialog.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ export function WizardEditAnswerDialog({
151151
</div>
152152
</form>
153153
{hasPersistedCustomAnswer ? (
154-
<p className="flex items-center gap-2 text-xs font-semibold text-emerald-600 dark:text-emerald-400">
154+
<p
155+
className="flex items-center gap-2 text-xs font-semibold text-emerald-600 dark:text-emerald-400"
156+
data-testid="custom-answer-confirmation"
157+
>
155158
<CheckCircle2 className="h-3.5 w-3.5" />
156159
<span>
157160
We'll use

playwright/tests/wizard-free-text.spec.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,33 @@ test("wizard accepts custom free text answers and shows them in the summary", as
3030
await expect(customInput).toBeVisible()
3131
await customInput.fill(customAnswer)
3232

33-
const confirmationMessage = page.locator('p', { hasText: "We'll use" }).first()
33+
await expect(questionHeading).toHaveText("What build tooling do you use?")
34+
35+
const confirmationMessage = page.getByTestId("custom-answer-confirmation")
3436
await expect(confirmationMessage).toBeVisible()
3537
await expect(confirmationMessage).toContainText(customAnswer)
3638
await expect(confirmationMessage).toContainText(
3739
"for this question when we generate your context file."
3840
)
3941

40-
await page.waitForFunction(
41-
({ questionId, expected }) => {
42-
const raw = window.localStorage.getItem("devcontext:wizard:react")
43-
if (!raw) {
44-
return false
45-
}
42+
await expect.poll(
43+
() =>
44+
page.evaluate(({ questionId }) => {
45+
const raw = window.localStorage.getItem("devcontext:wizard:react")
46+
if (!raw) {
47+
return null
48+
}
4649

47-
try {
48-
const state = JSON.parse(raw)
49-
return state.freeTextResponses?.[questionId] === expected
50-
} catch (error) {
51-
console.warn("Unable to parse wizard state", error)
52-
return false
53-
}
54-
},
55-
{ questionId: "react-fileStructure", expected: customAnswer }
56-
)
50+
try {
51+
const state = JSON.parse(raw)
52+
return state.freeTextResponses?.[questionId] ?? null
53+
} catch (error) {
54+
console.warn("Unable to parse wizard state", error)
55+
return "PARSE_ERROR"
56+
}
57+
}, { questionId: "react-fileStructure" }),
58+
{ timeout: 15000 }
59+
).toBe(customAnswer)
5760

5861
const storedState = await page.evaluate(() => {
5962
const raw = window.localStorage.getItem("devcontext:wizard:react")

0 commit comments

Comments
 (0)