Files
baserow/e2e-tests/tests/database/form_view_description_richtext.spec.ts
alamin-br 59da1eb2da feat: rich content in form view descriptions (#1851) (#5707)
* feat: rich text editor for form field description (creator)

* feat: render form field description as rich text (respondent)

* feat: rich text editor for form description (creator)

* feat: render form description as rich text (respondent)

Renders the form-level description read-only via RichTextEditor in
FormViewModeForm.vue (the public standard form), matching the field
description treatment from FormPageField.

FormViewModeSurvey.vue was checked and has no separate form-level
description/title render at all (it goes straight to fields), so no
change was needed there.

* docs: changelog for rich form descriptions (#1851)

* fix: only save form description after an actual edit

saveDescription ran on every editor blur and compared tiptap's
normalized markdown against the raw stored value, so clicking into
a legacy plain-text description (with chars like *, #, %) and away
without editing silently rewrote the stored value. Add a dirty flag
set only by update:modelValue (real edits) so blur without an edit
is a no-op.

Also drops the unused editor-class attribute on the description
RichTextEditor (no matching SCSS rule).

* perf: only mount field description editor when needed (v-if)

* fix: preserve in-progress description edit on external update; add e2e coverage

* fix: click-to-edit toggle for form descriptions; fix cursor reset

Replace the always-editable inline RichTextEditor on the form builder with a
shared FormViewDescription component that renders read-only markdown and mounts
the editor only while editing, behind an edit pencil (matching title/submit).

- Restores the edit affordance that regressed vs the old Editable.
- Passes model-value one-way and reads markdown back on blur, so typing after
  moving the cursor no longer resets to the end.
- No floating menu lingers on the form once editing stops.
- Removes the dirty/save-on-blur logic duplicated across FormViewField and
  FormViewModePreviewForm.

* test: cover form description toggle and save-on-blur

* fix: keep description editor menu stuck to cursor line on scroll

Pass the form preview's scroll container (.form-view__preview) to the editor so
its floating/bubble menu tracks the cursor line while the page scrolls, instead
of falling back to the editor's own non-scrolling root.

* Address PR review feedback (#5707)

- Route public form description render sites through FormViewDescription
- Pass scroll container as a resolver prop instead of a closest() lookup
- Wrap long unbroken words in form and field descriptions
- Use palette color variable for the description placeholder

* fix: clamp form description containers to the form column

The flex editor wrapper inside the inline-block description containers
made them shrink-to-fit their max-content width, letting long words
escape the form column on the public form.
2026-07-17 17:40:40 +02:00

115 lines
4.2 KiB
TypeScript

import { expect, test } from "../baserowTest";
import { createDatabase } from "../../fixtures/database/database";
import { createTable } from "../../fixtures/database/table";
import { createField } from "../../fixtures/database/field";
import {
createFormView,
updateFormFieldOptions,
patchView,
} from "../../fixtures/database/view";
import { FormPage } from "../../pages/database/formPage";
import { User } from "../../fixtures/user";
import { Workspace } from "../../fixtures/workspace";
// Form view descriptions (field-level and form-level) are authored as markdown
// and rendered rich to respondents. These tests lock in the two things that
// matter on the public page: markdown becomes real formatting, and unsafe
// markdown (raw HTML / javascript: links) is rendered inert by the shared
// editor config (Markdown html:false + Link protocol allowlist).
test.describe("Form view rich-text descriptions", () => {
test.describe.configure({ timeout: 60_000 });
let user: User;
let workspace: Workspace;
test.beforeEach(async ({ workspacePage }) => {
user = workspacePage.user;
workspace = workspacePage.workspace;
});
test("renders markdown descriptions as formatting", async ({ page, goto }) => {
const database = await createDatabase(user, "Rich Form DB", workspace);
const table = await createTable(user, "Entries", database, [
["Name"],
["Alice"],
]);
const bio = await createField(user, "Bio", "long_text", {}, table);
const view = await createFormView(user, table);
await patchView(user, view, {
description: "Welcome — read the **instructions** and visit our [site](https://baserow.io).",
});
await updateFormFieldOptions(user, view, {
[bio.id]: {
enabled: true,
required: false,
order: 1,
description:
"Fill in your **bio**. See the [guide](https://baserow.io).\n\n- Be concise\n- Be honest",
},
});
const formPage = new FormPage({ page, goto });
await formPage.gotoPublic(view.slug);
const fieldDesc = page.locator(".form-view__field-description").first();
await fieldDesc.waitFor({ state: "visible" });
await expect(fieldDesc.locator("strong")).toHaveCount(1);
await expect(
fieldDesc.locator('a[href="https://baserow.io"]'),
).toHaveCount(1);
expect(await fieldDesc.locator("ul li").count()).toBeGreaterThanOrEqual(2);
const formDesc = page.locator(".form-view__description").first();
await expect(formDesc.locator("strong")).toHaveCount(1);
await expect(
formDesc.locator('a[href="https://baserow.io"]'),
).toHaveCount(1);
});
test("renders unsafe markdown inert (no script, no javascript: link)", async ({
page,
goto,
}) => {
const database = await createDatabase(user, "XSS Form DB", workspace);
const table = await createTable(user, "Entries", database, [
["Name"],
["Bob"],
]);
const bio = await createField(user, "Bio", "long_text", {}, table);
const view = await createFormView(user, table);
await updateFormFieldOptions(user, view, {
[bio.id]: {
enabled: true,
required: false,
order: 1,
description:
"<script>window.__xss = 1</script> **safe** [bad](javascript:alert(1)) [good](https://baserow.io)",
},
});
let dialogFired = false;
page.on("dialog", async (d) => {
dialogFired = true;
await d.dismiss();
});
const formPage = new FormPage({ page, goto });
await formPage.gotoPublic(view.slug);
const fieldDesc = page.locator(".form-view__field-description").first();
await fieldDesc.waitFor({ state: "visible" });
// The injected script neither executed nor was rendered as an element.
expect(await page.evaluate(() => (window as any).__xss)).toBeUndefined();
expect(dialogFired).toBe(false);
await expect(fieldDesc.locator("script")).toHaveCount(0);
// The javascript: link was dropped, not rendered as a clickable anchor.
await expect(fieldDesc.locator('a[href^="javascript:"]')).toHaveCount(0);
// Safe markdown still renders (bold + the https link survive).
await expect(fieldDesc.locator("strong")).toHaveCount(1);
await expect(
fieldDesc.locator('a[href="https://baserow.io"]'),
).toHaveCount(1);
});
});