Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions e2e/specs/workflows/workflow-builder-layout.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { test, expect, createWorkflow, WorkflowBuilder } from '@e2e'

// The builder is a full-screen overlay; on narrow screens the node list
// becomes a drawer and node types are added by tap (touch has no drag-and-drop).

const SIZES = [
{ name: 'phone', width: 375, height: 812 },
{ name: 'tablet', width: 768, height: 1024 },
]

test.describe('workflow builder layout', () => {
for (const size of SIZES) {
test(`the builder fits a ${size.name}: every action stays on screen and Nodes adds a step by tap @workflows`, async ({ agent, adminApi, page }) => {
await createWorkflow(adminApi, agent.id)
await page.setViewportSize({ width: size.width, height: size.height })
const builder = new WorkflowBuilder(page)
await builder.open(agent.id)

for (const action of ['Close', 'Publish', 'Save'] as const) {
await expect(builder.action(action)).toBeInViewport({ ratio: 1 })
}
expect(await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth)).toBeLessThanOrEqual(0)

await expect(builder.nodeTypes).toBeHidden()
await builder.addNodeByTap('Message')
await expect(builder.node('Message')).toBeInViewport()
})
}
})
10 changes: 8 additions & 2 deletions e2e/src/api/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ export interface WorkflowGraph {
* connects, so embed the widget after this.
*/
export async function publishWorkflow(api: ApiClient, agentId: string, graph: WorkflowGraph): Promise<string> {
const workflowId = await createWorkflow(api, agentId)
await api.put(`/workflow/${workflowId}/nodes`, { data: { nodes: graph.nodes, connections: graph.connections ?? [] } })
await api.put(`/workflow/${workflowId}`, { data: { status: 'published' } })
return workflowId
}

/** Creates an empty draft workflow for `agentId`. */
export async function createWorkflow(api: ApiClient, agentId: string): Promise<string> {
const workflow = await api.post<{ id: string }>('/workflow', { data: { name: unique('E2E flow'), agent_id: agentId } })
await api.put(`/workflow/${workflow.id}/nodes`, { data: { nodes: graph.nodes, connections: graph.connections ?? [] } })
await api.put(`/workflow/${workflow.id}`, { data: { status: 'published' } })
return workflow.id
}
3 changes: 2 additions & 1 deletion e2e/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export {
putBackOnSale, routeTicketsToJira, shopifyOrderNow, storefrontAction, uninstallShopify, useShopForAgent,
} from './api/integrations'
export type { FakeShopifyOrder } from './api/integrations'
export { publishWorkflow, type WorkflowGraph } from './api/workflows'
export { createWorkflow, publishWorkflow, type WorkflowGraph } from './api/workflows'
export {
askHelpCenter, createArticle, enableHelpCenter, helpCenterChat, setArticleStatus, setHelpCenterChat, turnOnAskAi, type Article, type HelpCenterChat,
} from './api/help-center'
Expand Down Expand Up @@ -71,6 +71,7 @@ export { SetupWizard } from './pages/setup-wizard.page'
export { TicketsPage } from './pages/tickets.page'
export { WidgetAllowedDomainsPage } from './pages/widget-allowed-domains.page'
export { WidgetInstallPage } from './pages/widget-install.page'
export { WorkflowBuilder } from './pages/workflow-builder.page'
export { unique } from './support/ids'
export { step } from './support/step'
export { allowClipboard, clipboardText } from './support/clipboard'
Expand Down
79 changes: 79 additions & 0 deletions e2e/src/pages/workflow-builder.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { expect, type Locator, type Page } from '@playwright/test'
import { step } from '../support/step'

/** The agent editor's Workflow Builder tab and the full-screen builder it opens. */
export class WorkflowBuilder {
readonly page: Page

constructor(page: Page) {
this.page = page
}

async open(agentId: string): Promise<void> {
await step('Open the workflow builder', async () => {
await this.page.goto(`/ai-agents?agent=${agentId}&tab=workflow-builder`)
await this.page.getByRole('button', { name: 'Open Builder' }).click()
await expect(this.page.getByRole('button', { name: 'Save', exact: true })).toBeVisible()
})
}

/** A node on the canvas, by its name. */
node(name: string): Locator {
// Vue Flow's nodes have no role or accessible name of their own
return this.page.locator('.vue-flow__node').filter({ hasText: name })
}

async selectNode(name: string): Promise<void> {
await this.node(name).click()
await expect(this.page.getByRole('textbox', { name: 'Node Name' })).toHaveValue(name)
}

/** The handover node's team picker. */
get team(): Locator {
return this.page.getByRole('combobox', { name: 'Team' })
}

async chooseTeam(workflowId: string, teamName: string): Promise<void> {
await step(`Hand the node over to ${teamName}`, async () => {
await this.team.selectOption({ label: teamName })
const groupId = await this.team.inputValue()
// The panel writes the node to the builder's local copy on a short delay,
// and Save sends that copy: wait for it, or Save can beat the change
await this.page.waitForFunction(
([key, id]) => (localStorage.getItem(key) ?? '').includes(id),
[`workflow_info_${workflowId}`, groupId],
)
})
}

async save(): Promise<void> {
await step('Save the workflow', async () => {
await this.page.getByRole('button', { name: 'Save', exact: true }).click()
await expect(this.page.getByText('Workflow saved successfully')).toBeVisible()
})
}

/** The builder's header: name, status and the Nodes, Close, Publish and Save actions. */
get header(): Locator {
return this.page.locator('.builder-header')
}

/** A header action by its name; on phones the label is hidden and the name stays. */
action(name: 'Node types' | 'Close' | 'Publish' | 'Unpublish' | 'Save'): Locator {
return this.header.getByRole('button', { name, exact: true })
}

/** The node type list: a sidebar on wide screens, a drawer on narrow ones. */
get nodeTypes(): Locator {
return this.page.locator('#workflow-node-types')
}

/** Narrow screens: open the drawer and tap a node type to add it. */
async addNodeByTap(label: string): Promise<void> {
await step(`Add a ${label} node from the drawer`, async () => {
await this.action('Node types').click()
await this.nodeTypes.getByText(label, { exact: true }).click()
await expect(this.nodeTypes).toBeHidden()
})
}
}
64 changes: 64 additions & 0 deletions frontend/src/components/workflow/NodeTypeIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<script setup lang="ts">
defineProps<{ type: string }>()
</script>

<template>
<svg
class="node-type-svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<template v-if="type === 'landingPage'">
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M3 9h18M9 21V9" />
</template>
<template v-else-if="type === 'message'">
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
</template>
<template v-else-if="type === 'llm'">
<path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
<path d="M19 15v4M17 17h4M5 3v3M3.5 4.5h3" />
</template>
<template v-else-if="type === 'condition'">
<circle cx="6" cy="18" r="3" />
<circle cx="18" cy="6" r="3" />
<path d="M6 3v12M18 9a9 9 0 0 1-9 9" />
</template>
<template v-else-if="type === 'form'">
<rect x="8" y="2" width="8" height="4" rx="1" />
<path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" />
<path d="M9 12h6M9 16h4" />
</template>
<template v-else-if="type === 'userInput'">
<rect x="2" y="6" width="20" height="12" rx="2" />
<path d="M6 10h.01M10 10h.01M14 10h.01M18 10h.01M7 14h10" />
</template>
<template v-else-if="type === 'guardrails'">
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" />
<path d="M9 12l2 2 4-4" />
</template>
<template v-else-if="type === 'humanTransfer'">
<circle cx="12" cy="8" r="4" />
<path d="M20 21a8 8 0 0 0-16 0" />
</template>
<template v-else-if="type === 'end'">
<path d="M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z" />
<path d="M4 22v-7" />
</template>
<template v-else>
<rect x="4" y="4" width="16" height="16" rx="3" />
</template>
</svg>
</template>

<style scoped>
.node-type-svg {
width: 20px;
height: 20px;
}
</style>
Loading
Loading