1- import type { Page } from "@playwright/test" ;
21import { expect , test } from "../../../fixtures/fixtures" ;
3- import { adjustScreenView } from "../../../helpers/ui/adjust-screen-view" ;
4- import { awaitBootstrapTest } from "../../../helpers/other/await-bootstrap-test" ;
2+ import {
3+ addPromptComponent ,
4+ dynamicHandlesLocator ,
5+ fillPromptTemplate ,
6+ } from "../../../helpers/ui/prompt-template" ;
57
68// Run serially to avoid 500 errors from concurrent POST /api/v1/flows/
79// when several workers create a blank flow at the same time.
810test . describe . configure ( { mode : "serial" } ) ;
911
10- // Verified testids from live UI inspection:
11- // add button: "add-component-button-prompt-template"
12- // node title: "title-Prompt Template"
13- // modal open btn: "button_open_prompt_modal"
14- // modal textarea: "modal-promptarea_prompt_template" (unique to the prompt modal — use as anchor)
15- // modal save btn: "genericModalBtnSave"
16- // modal preview: "edit-prompt-sanitized" (shown after save; click to re-edit)
17- // output handle: "handle-prompt template-shownode-prompt-right"
18- // dynamic handles: "handle-prompt template-shownode-{varname}-left"
19-
20- // Locator matching only the dynamic (left-side) input handles created from
21- // {variable} placeholders. The output `-right` handle is excluded by the suffix
22- // filter so counts reflect dynamic-handle-only deltas.
23- const dynamicHandlesLocator = ( page : Page ) =>
24- page . locator (
25- '[data-testid^="handle-prompt template-shownode-"][data-testid$="-left"]' ,
26- ) ;
27-
28- async function addPromptComponent ( page : Page ) {
29- await awaitBootstrapTest ( page ) ;
30- await expect ( page . getByTestId ( "blank-flow" ) ) . toBeAttached ( { timeout : 30000 } ) ;
31- await page . getByTestId ( "blank-flow" ) . click ( ) ;
32-
33- await page . getByTestId ( "sidebar-search-input" ) . click ( ) ;
34- await page . getByTestId ( "sidebar-search-input" ) . fill ( "prompt" ) ;
35- await expect (
36- page . getByTestId ( "add-component-button-prompt-template" ) ,
37- ) . toBeAttached ( { timeout : 30000 } ) ;
38- await page . getByTestId ( "add-component-button-prompt-template" ) . click ( ) ;
39-
40- await adjustScreenView ( page ) ;
41- await expect ( page . locator ( ".react-flow__node" ) ) . toHaveCount ( 1 , {
42- timeout : 10000 ,
43- } ) ;
44- }
45-
46- // Open the prompt modal and replace its current value with `value`.
47- // Handles the post-save preview state by clicking it to re-enter edit mode.
48- // The function returns after the save dialog closes; downstream assertions
49- // must wait on their specific expected handle state (auto-retry via expect()),
50- // because the canvas re-render is asynchronous to the modal close.
51- async function setPromptTemplate ( page : Page , value : string ) {
52- await page . getByTestId ( "button_open_prompt_modal" ) . click ( ) ;
53-
54- const textarea = page . getByTestId ( "modal-promptarea_prompt_template" ) ;
55-
56- // After a previous save, the modal initially shows the sanitized preview
57- // (read-only) instead of the textarea. Clicking the preview re-enters edit
58- // mode and mounts the textarea.
59- const preview = page . getByTestId ( "edit-prompt-sanitized" ) ;
60- if ( await preview . isVisible ( { timeout : 2000 } ) . catch ( ( ) => false ) ) {
61- await preview . click ( ) ;
62- }
63-
64- await expect ( textarea ) . toBeVisible ( { timeout : 10000 } ) ;
65- await textarea . click ( ) ;
66- await page . keyboard . press ( "Control+a" ) ;
67- await textarea . fill ( value ) ;
68-
69- await page . getByTestId ( "genericModalBtnSave" ) . click ( ) ;
70- // The textarea testid is scoped to the prompt modal, so its disappearance
71- // is a reliable signal that the modal closed and the save round-trip began.
72- await expect ( textarea ) . toBeHidden ( { timeout : 10000 } ) ;
73- }
74-
7512test (
7613 "Prompt Template component — renders on canvas with output handle" ,
7714 { tag : [ "@stable" , "@release" , "@regression" , "@components" ] } ,
11249 await test . step (
11350 "Save template with two {variable} placeholders" ,
11451 async ( ) => {
115- await setPromptTemplate ( page , "Hello {name}, your job is {profession}." ) ;
52+ await fillPromptTemplate ( page , "Hello {name}, your job is {profession}." ) ;
11653 } ,
11754 ) ;
11855
15289 await test . step (
15390 "Save template `Hello {name}!` — expect 1 dynamic handle for {name}" ,
15491 async ( ) => {
155- await setPromptTemplate ( page , "Hello {name}!" ) ;
92+ await fillPromptTemplate ( page , "Hello {name}!" ) ;
15693 await expect ( nameHandle ) . toBeVisible ( { timeout : 10000 } ) ;
15794 await expect ( dynamicHandlesLocator ( page ) ) . toHaveCount ( 1 ) ;
15895 } ,
16198 await test . step (
16299 "Save template without variables — expect 0 dynamic handles" ,
163100 async ( ) => {
164- await setPromptTemplate ( page , "Hello world!" ) ;
101+ await fillPromptTemplate ( page , "Hello world!" ) ;
165102 await expect ( nameHandle ) . toHaveCount ( 0 , { timeout : 10000 } ) ;
166103 await expect ( dynamicHandlesLocator ( page ) ) . toHaveCount ( 0 ) ;
167104 } ,
@@ -180,7 +117,7 @@ test(
180117 await test . step (
181118 "Save template `Hello {name}, you are {role}.` — both handles render" ,
182119 async ( ) => {
183- await setPromptTemplate ( page , "Hello {name}, you are {role}." ) ;
120+ await fillPromptTemplate ( page , "Hello {name}, you are {role}." ) ;
184121 await expect (
185122 page . getByTestId ( "handle-prompt template-shownode-name-left" ) ,
186123 ) . toBeVisible ( { timeout : 10000 } ) ;
@@ -193,7 +130,7 @@ test(
193130 await test . step (
194131 "Replace {role} with {title} — old handle is gone, new one appears, {name} stays" ,
195132 async ( ) => {
196- await setPromptTemplate ( page , "Hello {name}, you are {title}." ) ;
133+ await fillPromptTemplate ( page , "Hello {name}, you are {title}." ) ;
197134 await expect (
198135 page . getByTestId ( "handle-prompt template-shownode-name-left" ) ,
199136 ) . toBeVisible ( { timeout : 10000 } ) ;
@@ -219,7 +156,7 @@ test(
219156 await test . step (
220157 "Save template with 3 variables — expect 3 dynamic handles" ,
221158 async ( ) => {
222- await setPromptTemplate ( page , "{a} and {b} and {c}" ) ;
159+ await fillPromptTemplate ( page , "{a} and {b} and {c}" ) ;
223160 await expect ( dynamicHandlesLocator ( page ) ) . toHaveCount ( 3 , {
224161 timeout : 10000 ,
225162 } ) ;
@@ -229,7 +166,7 @@ test(
229166 await test . step (
230167 "Save plain-text template — all dynamic handles disappear" ,
231168 async ( ) => {
232- await setPromptTemplate ( page , "No variables here." ) ;
169+ await fillPromptTemplate ( page , "No variables here." ) ;
233170 await expect ( dynamicHandlesLocator ( page ) ) . toHaveCount ( 0 , {
234171 timeout : 10000 ,
235172 } ) ;
@@ -254,7 +191,7 @@ test(
254191 await test . step (
255192 "Save template — the {topic} handle confirms save was applied" ,
256193 async ( ) => {
257- await setPromptTemplate ( page , expected ) ;
194+ await fillPromptTemplate ( page , expected ) ;
258195 await expect (
259196 page . getByTestId ( "handle-prompt template-shownode-topic-left" ) ,
260197 ) . toBeVisible ( { timeout : 10000 } ) ;
0 commit comments