Skip to content

AI-native design editor. Open-source Figma alternative.

test(app): add panel UI guardrails

Danila Poyarkov3e750383c0b8
diff --git a/src/components/chat/ChatInput.vue b/src/components/chat/ChatInput.vue
index c753acc89..6271cf0af 100644
--- a/src/components/chat/ChatInput.vue
+++ b/src/components/chat/ChatInput.vue
@@ -35,6 +35,18 @@ const acpAgentName = computed(() => {
const isCustomProvider = computed(
() => providerID.value === 'openai-compatible' || providerID.value === 'anthropic-compatible'
)
+const stopButton = useButtonUI({
+ tone: 'ghost',
+ shape: 'rounded',
+ size: 'sm',
+ ui: { base: 'shrink-0 border border-border px-2 py-1.5' }
+})
+const sendButton = useButtonUI({
+ tone: 'accent',
+ shape: 'rounded',
+ size: 'sm',
+ ui: { base: 'shrink-0 px-2.5 py-1.5 font-medium' }
+})
const customModelName = computed(() => customModelID.value.trim())
const usesCustomModel = computed(
() => !!providerDef.value.supportsCustomModel && !!customModelName.value
@@ -100,14 +112,7 @@ function handleSubmit(e: Event) {
<button
type="button"
data-test-id="chat-stop-button"
- :class="
- useButtonUI({
- tone: 'ghost',
- shape: 'rounded',
- size: 'sm',
- ui: { base: 'shrink-0 border border-border px-2 py-1.5' }
- }).base
- "
+ :class="stopButton.base"
@click="emit('stop')"
>
<icon-lucide-square class="size-3" />
@@ -117,14 +122,7 @@ function handleSubmit(e: Event) {
<button
type="submit"
data-test-id="chat-send-button"
- :class="
- useButtonUI({
- tone: 'accent',
- shape: 'rounded',
- size: 'sm',
- ui: { base: 'shrink-0 px-2.5 py-1.5 font-medium' }
- }).base
- "
+ :class="sendButton.base"
:disabled="!input.trim()"
>
<icon-lucide-send class="size-3" />
diff --git a/tests/e2e/panels/keyboard.spec.ts b/tests/e2e/panels/keyboard.spec.ts
new file mode 100644
index 000000000..d2064eafe
--- /dev/null
+++ b/tests/e2e/panels/keyboard.spec.ts
@@ -0,0 +1,70 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+import { propertySection } from '#tests/helpers/properties'
+
+const editor = useEditorSetupWithClear()
+
+test('property fields follow keyboard tab order', async () => {
+ await editor.page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const node = store.graph.createNode('RECTANGLE', store.state.currentPageId, {
+ x: 120,
+ y: 140,
+ width: 180,
+ height: 100
+ })
+ store.select([node.id])
+ })
+ await editor.canvas.waitForRender()
+
+ const position = propertySection(editor.page, 'Position')
+ const x = position.getByRole('spinbutton', { name: 'X Axis' })
+ const y = position.getByRole('spinbutton', { name: 'Y Axis' })
+ await x.focus()
+ await expect(x).toBeFocused()
+ await editor.page.keyboard.press('Tab')
+ await expect(y).toBeFocused()
+ await editor.page.keyboard.press('Shift+Tab')
+ await expect(x).toBeFocused()
+})
+
+test('select and switch controls work from the keyboard', async () => {
+ const textId = await editor.page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const node = store.graph.createNode('TEXT', store.state.currentPageId, {
+ text: 'Keyboard typography',
+ x: 120,
+ y: 140,
+ width: 260,
+ height: 80
+ })
+ store.select([node.id])
+ return node.id
+ })
+ await editor.canvas.waitForRender()
+
+ const typography = propertySection(editor.page, 'Typography')
+ const textCase = typography.getByRole('combobox', { name: 'Text case' })
+ await textCase.focus()
+ await editor.page.keyboard.press('Enter')
+ const uppercase = editor.page.getByRole('option', { name: 'Uppercase' })
+ await expect(uppercase).toBeVisible()
+ await uppercase.focus()
+ await editor.page.keyboard.press('Enter')
+ await expect(uppercase).not.toBeVisible()
+
+ const ligatures = editor.page.getByRole('switch', { name: 'Standard ligatures' })
+ await expect(ligatures).toBeVisible()
+ await ligatures.focus()
+ await editor.page.keyboard.press('Space')
+ await editor.canvas.waitForRender()
+
+ const state = await editor.page.evaluate((id) => {
+ const store = window.openPencil?.getStore?.()
+ const node = store?.graph.getNode(id)
+ return node ? { textCase: node.textCase, fontFeatures: node.fontFeatures } : null
+ }, textId)
+ expect(state?.textCase).toBe('UPPER')
+ expect(state?.fontFeatures).toContainEqual({ tag: 'LIGA', enabled: false })
+})
diff --git a/tests/e2e/panels/visual.spec.ts b/tests/e2e/panels/visual.spec.ts
new file mode 100644
index 000000000..106e31945
--- /dev/null
+++ b/tests/e2e/panels/visual.spec.ts
@@ -0,0 +1,145 @@
+import { expect, test, type Page } from '@playwright/test'
+
+import { CanvasHelper } from '#tests/helpers/canvas'
+
+let page: Page
+let canvas: CanvasHelper
+
+test.describe.configure({ mode: 'serial' })
+
+test.beforeAll(async ({ browser }) => {
+ page = await browser.newPage()
+ await page.goto('/')
+ canvas = new CanvasHelper(page)
+ await canvas.waitForInit()
+})
+
+test.afterAll(async () => {
+ await page.close()
+})
+
+async function reset() {
+ await canvas.clearCanvas()
+ await canvas.waitForRender()
+}
+
+test('single rectangle panel', async () => {
+ await reset()
+ await page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const node = store.graph.createNode('RECTANGLE', store.state.currentPageId, {
+ name: 'Card',
+ x: 100,
+ y: 100,
+ width: 180,
+ height: 120,
+ cornerRadius: 16
+ })
+ store.select([node.id])
+ })
+ await canvas.waitForRender()
+ await expect(page.getByTestId('design-panel-single')).toHaveScreenshot('single-rectangle.png')
+})
+
+test('text selection panel', async () => {
+ await reset()
+ await page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const node = store.graph.createNode('TEXT', store.state.currentPageId, {
+ name: 'Heading',
+ text: 'Panel typography',
+ x: 100,
+ y: 100,
+ width: 240,
+ height: 80,
+ fontSize: 24
+ })
+ store.select([node.id])
+ })
+ await canvas.waitForRender()
+ await expect(page.getByTestId('design-panel-single')).toHaveScreenshot('text-selection.png')
+})
+
+test('mixed selection panel', async () => {
+ await reset()
+ await page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const first = store.graph.createNode('RECTANGLE', store.state.currentPageId, {
+ x: 100,
+ y: 100,
+ width: 120,
+ height: 80
+ })
+ const second = store.graph.createNode('ELLIPSE', store.state.currentPageId, {
+ x: 260,
+ y: 100,
+ width: 100,
+ height: 100
+ })
+ store.select([first.id, second.id])
+ })
+ await canvas.waitForRender()
+ await expect(page.getByTestId('design-panel-multi')).toHaveScreenshot('mixed-selection.png')
+})
+
+test('instance panel', async () => {
+ await reset()
+ await page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const component = store.graph.createNode('COMPONENT', store.state.currentPageId, {
+ name: 'Button',
+ componentPropertyDefinitions: [
+ { id: '40:1', name: 'Label', type: 'TEXT', defaultValue: 'Button' },
+ { id: '40:2', name: 'Enabled', type: 'BOOLEAN', defaultValue: 'true' }
+ ]
+ })
+ store.graph.createNode('TEXT', component.id, {
+ name: 'Label',
+ text: 'Button',
+ componentPropertyReferences: [{ propertyId: '40:1', field: 'TEXT' }]
+ })
+ store.graph.createNode('FRAME', component.id, {
+ name: 'State',
+ componentPropertyReferences: [{ propertyId: '40:2', field: 'VISIBLE' }]
+ })
+ const instance = store.graph.createInstance(component.id, store.state.currentPageId)
+ if (!instance) throw new Error('Expected instance')
+ store.select([instance.id])
+ })
+ await canvas.waitForRender()
+ await expect(page.getByTestId('design-panel-single')).toHaveScreenshot('instance.png')
+})
+
+test('empty canvas panel', async () => {
+ await reset()
+ await expect(page.getByTestId('design-panel-empty')).toHaveScreenshot('empty-canvas.png')
+})
+
+test('nested groups layer tree', async () => {
+ await reset()
+ await page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const outer = store.graph.createNode('GROUP', store.state.currentPageId, {
+ name: 'Outer group',
+ expanded: true
+ })
+ const inner = store.graph.createNode('GROUP', outer.id, {
+ name: 'Inner group',
+ expanded: true
+ })
+ store.graph.createNode('RECTANGLE', inner.id, { name: 'Nested rectangle' })
+ store.select([inner.id])
+ })
+ await canvas.waitForRender()
+ await page
+ .getByTestId('layers-item')
+ .filter({ hasText: 'Inner group' })
+ .locator('[data-slot="disclosure"]')
+ .click()
+ await expect(page.getByTestId('layers-panel')).toHaveScreenshot('nested-groups-layer-tree.png')
+})
diff --git a/tests/e2e/panels/visual.spec.ts-snapshots/empty-canvas-openpencil-darwin.png b/tests/e2e/panels/visual.spec.ts-snapshots/empty-canvas-openpencil-darwin.png
new file mode 100644
index 000000000..81f10854f
Binary files /dev/null and b/tests/e2e/panels/visual.spec.ts-snapshots/empty-canvas-openpencil-darwin.png differ
diff --git a/tests/e2e/panels/visual.spec.ts-snapshots/instance-openpencil-darwin.png b/tests/e2e/panels/visual.spec.ts-snapshots/instance-openpencil-darwin.png
new file mode 100644
index 000000000..abfb21ea6
Binary files /dev/null and b/tests/e2e/panels/visual.spec.ts-snapshots/instance-openpencil-darwin.png differ
diff --git a/tests/e2e/panels/visual.spec.ts-snapshots/mixed-selection-openpencil-darwin.png b/tests/e2e/panels/visual.spec.ts-snapshots/mixed-selection-openpencil-darwin.png
new file mode 100644
index 000000000..86f212e27
Binary files /dev/null and b/tests/e2e/panels/visual.spec.ts-snapshots/mixed-selection-openpencil-darwin.png differ
diff --git a/tests/e2e/panels/visual.spec.ts-snapshots/nested-groups-layer-tree-openpencil-darwin.png b/tests/e2e/panels/visual.spec.ts-snapshots/nested-groups-layer-tree-openpencil-darwin.png
new file mode 100644
index 000000000..2003eef4a
Binary files /dev/null and b/tests/e2e/panels/visual.spec.ts-snapshots/nested-groups-layer-tree-openpencil-darwin.png differ
diff --git a/tests/e2e/panels/visual.spec.ts-snapshots/single-rectangle-openpencil-darwin.png b/tests/e2e/panels/visual.spec.ts-snapshots/single-rectangle-openpencil-darwin.png
new file mode 100644
index 000000000..aba8d48eb
Binary files /dev/null and b/tests/e2e/panels/visual.spec.ts-snapshots/single-rectangle-openpencil-darwin.png differ
diff --git a/tests/e2e/panels/visual.spec.ts-snapshots/text-selection-openpencil-darwin.png b/tests/e2e/panels/visual.spec.ts-snapshots/text-selection-openpencil-darwin.png
new file mode 100644
index 000000000..aa0f43212
Binary files /dev/null and b/tests/e2e/panels/visual.spec.ts-snapshots/text-selection-openpencil-darwin.png differ
diff --git a/tools/architecture/src/steiger-rules/dynamic-tailwind-classes.ts b/tools/architecture/src/steiger-rules/dynamic-tailwind-classes.ts
index 088582ccc..6f91f9eea 100644
--- a/tools/architecture/src/steiger-rules/dynamic-tailwind-classes.ts
+++ b/tools/architecture/src/steiger-rules/dynamic-tailwind-classes.ts
@@ -26,6 +26,7 @@ type ExpressionNode = UnknownRecord & { type: string }
type VueTemplateNode = {
type?: number
name?: string
+ tag?: string
arg?: { content?: string }
exp?: { ast?: unknown }
props?: VueTemplateNode[]
@@ -129,6 +130,55 @@ export function dynamicClassDiagnostics(sourceRel: string, content: string) {
return diagnostics
}
+function containsUiHookCall(node: unknown, visited = new Set<ExpressionNode>()): boolean {
+ if (!isExpressionNode(node) || visited.has(node)) return false
+ visited.add(node)
+ if (
+ node.type === 'CallExpression' &&
+ isExpressionNode(node.callee) &&
+ node.callee.type === 'Identifier' &&
+ typeof node.callee.name === 'string' &&
+ /^use[A-Z][A-Za-z0-9]*UI$/.test(node.callee.name)
+ ) {
+ return true
+ }
+ return Object.entries(node).some(([key, value]) => {
+ if (key === 'loc' || key === 'start' || key === 'end') return false
+ return Array.isArray(value)
+ ? value.some((child) => containsUiHookCall(child, visited))
+ : containsUiHookCall(value, visited)
+ })
+}
+
+export function vueTemplateGuardrailDiagnostics(sourceRel: string, content: string) {
+ if (!sourceRel.startsWith('src/components/') || !sourceRel.endsWith('.vue')) return []
+ const template = parseVueSfc(content, { filename: sourceRel }).descriptor.template?.ast
+ if (!template) return []
+ const diagnostics: Array<{ message: string; line?: number; column?: number }> = []
+ walkVueTemplateAst(template as VueTemplateNode, (node) => {
+ if (node.type === 1 && node.tag === 'svg') {
+ diagnostics.push({
+ message: 'Use an Iconify/Lucide component instead of raw SVG in app components.',
+ line: node.loc?.start?.line,
+ column: node.loc?.start?.column
+ })
+ }
+ if (node.type === VUE_DIRECTIVE_NODE && containsUiHookCall(node.exp?.ast)) {
+ diagnostics.push({
+ message: 'Resolve use*UI() hooks once in script setup, not inside template expressions.',
+ line: node.loc?.start?.line,
+ column: node.loc?.start?.column
+ })
+ }
+ })
+ return diagnostics
+}
+
+export const noVueTemplateUiHooksOrSvg = createTextRule(
+ 'open-pencil/no-vue-template-ui-hooks-or-svg',
+ vueTemplateGuardrailDiagnostics
+)
+
export const noDynamicTailwindStateClasses = createTextRule(
'open-pencil/no-dynamic-tailwind-state-classes',
dynamicClassDiagnostics
diff --git a/tools/architecture/src/steiger-rules/index.ts b/tools/architecture/src/steiger-rules/index.ts
index fbc57102e..7e8d5a8e6 100644
--- a/tools/architecture/src/steiger-rules/index.ts
+++ b/tools/architecture/src/steiger-rules/index.ts
@@ -2,7 +2,10 @@ import path from 'node:path'
import { parse as parseVueSfc } from 'vue/compiler-sfc'
-import { noDynamicTailwindStateClasses } from './dynamic-tailwind-classes.ts'
+import {
+ noDynamicTailwindStateClasses,
+ noVueTemplateUiHooksOrSvg
+} from './dynamic-tailwind-classes.ts'
import {
collectFolders,
createFileRule,
@@ -514,6 +517,7 @@ export const openPencilArchitecturePlugin = {
noPropertyPanelInternalsOutsidePanel,
noProductionTestIdsInSharedLayers,
noDynamicTailwindStateClasses,
+ noVueTemplateUiHooksOrSvg,
noNativeTitleAttributesInVue,
noShortcutTextInLabels,
noHardcodedMacOSShortcutGlyphs,
diff --git a/tools/architecture/tests/dynamic-classes.test.ts b/tools/architecture/tests/dynamic-classes.test.ts
index 7cdf97df3..e22d1900b 100644
--- a/tools/architecture/tests/dynamic-classes.test.ts
+++ b/tools/architecture/tests/dynamic-classes.test.ts
@@ -1,11 +1,30 @@
import { describe, expect, test } from 'bun:test'
-import { dynamicClassDiagnostics } from '../src/steiger-rules/dynamic-tailwind-classes'
+import {
+ dynamicClassDiagnostics,
+ vueTemplateGuardrailDiagnostics
+} from '../src/steiger-rules/dynamic-tailwind-classes'
function component(classBinding: string) {
return `<template><button :class="${classBinding}" /></template>`
}
+describe('Vue template UI guardrails', () => {
+ test('reports use*UI calls inside bindings', () => {
+ const source = `<template><button :class="useButtonUI({ tone: 'accent' }).base" /></template>`
+ expect(vueTemplateGuardrailDiagnostics('src/components/Test.vue', source)).toHaveLength(1)
+ })
+
+ test('reports raw SVG elements and permits icon components', () => {
+ expect(
+ vueTemplateGuardrailDiagnostics(
+ 'src/components/Test.vue',
+ '<template><div><svg /><icon-lucide-check /></div></template>'
+ )
+ ).toHaveLength(1)
+ })
+})
+
describe('dynamic Tailwind state classes', () => {
test('reports conditional utility strings', () => {
const diagnostics = dynamicClassDiagnostics(