Skip to content

refactor(core-components): extract shared Prompt Template test helpers #222

Description

@Victor-w-Madeira

Context

Four sibling specs under tests/tests-automations/regression/core-components/ duplicate the same helpers:

  • prompt-template-component-regression.spec.ts
  • prompt-template-double-brackets-regression.spec.ts
  • prompt-template-invalid-patterns-regression.spec.ts
  • prompt-template-invalid-mustache-patterns-regression.spec.ts

Duplicated pieces (byte-identical or near-identical):

  • addPromptComponent(page) — bootstrap, click blank-flow, search/add Prompt Template, adjustScreenView, assert one node on canvas.
  • dynamicHandlesLocator(page) — CSS locator for the dynamic input handles ([data-testid^="handle-prompt template-shownode-"][data-testid$="-left"]).
  • errorToastLocator(page).error-build-message CSS locator (now duplicated in both invalid-patterns specs).
  • Mustache-mode entry helper — flipDoubleBrackets(page, true) in the double-brackets spec and enableMustacheMode(page) in the mustache invalid-patterns spec do the same job (click toggle_bool_use_double_brackets, wait for button_open_mustache_prompt_modal).
  • Modal-fill helpers — four slightly different shapes:
    • setPromptTemplate(page, value) in the component spec (waits for textarea hidden after save).
    • setPromptTemplate(page, value, mode) in the double-brackets spec (parameterised on "fstring"/"mustache").
    • fillAndSavePromptTemplate(page, value) in the f-string invalid-patterns spec (does NOT wait for hide, since the modal stays open on error).
    • fillAndSaveMustacheTemplate(page, value) in the mustache invalid-patterns spec (mustache textarea + does NOT wait for hide).

This was flagged in the review of PR #220:

Three copies of the same helper across one feature folder is a smell. A tests/helpers/ui/prompt-template.ts module would centralize this — but do it in a small follow-up that touches all three specs together so the diff stays reviewable.

Per project convention, shared-helper extraction is its own PR — risk and impact must be evaluated up front (a regression in addPromptComponent would fail all four specs at once).

Scope

Extract a single helper module under tests/helpers/ui/prompt-template.ts that exposes:

  • addPromptComponent(page: Page): Promise<void>
  • dynamicHandlesLocator(page: Page): Locator
  • errorToastLocator(page: Page): Locator
  • setUseDoubleBrackets(page: Page, enabled: boolean): Promise<void> — unifies flipDoubleBrackets/enableMustacheMode; clicks the toggle and waits for the matching modal-open testid to mount.
  • fillPromptTemplate(page: Page, value: string, opts?: { mode?: "fstring" | "mustache"; waitForHide?: boolean }): Promise<void> — unifies the four variants. waitForHide defaults to true (success path); set to false when submitting invalid input that keeps the modal open. mode defaults to "fstring".

Refactor the four specs to import from the new module. Verify:

  • npm run typecheck clean
  • npm run lint clean
  • All four specs still pass against a live Langflow instance
  • No change to test behavior — same test() count, same assertions, same tags
  • HTML report renders the same test.step() labels

Out of scope

  • Adding or removing tests (this is a pure refactor)
  • Changing the assertions or selectors
  • Extracting helpers from other sibling specs (e.g. chat-input-*, api-request-*, loop-component-*)

Deliverables

  • tests/helpers/ui/prompt-template.ts with the five exports above + JSDoc
  • All four prompt-template specs refactored to import from it
  • PR description states the equivalence (same test() count, same assertions)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions