Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(workflows): send a test email from the template library editor (#90875)

Harley Alexander49d13783b007
diff --git a/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx b/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx
index 346d13ce4cf7..9b446d56908f 100644
--- a/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx
+++ b/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx
@@ -15,6 +15,8 @@ import { ProductKey } from '~/queries/schema/schema-general'
import { messageTemplateLogic } from './messageTemplateLogic'
import { MessageTemplateSceneLogicProps, messageTemplateSceneLogic } from './messageTemplateSceneLogic'
+import { messageTemplateTestSendLogic } from './messageTemplateTestSendLogic'
+import { SendTestEmailModal } from './SendTestEmailModal'
export const scene: SceneExport<MessageTemplateSceneLogicProps> = {
component: MessageTemplate,
@@ -49,6 +51,10 @@ export function MessageTemplate(props: MessageTemplateSceneLogicProps): JSX.Elem
const { setIsSaveTemplateModalOpen } = useActions(emailTemplaterLogic)
+ const testSendLogic = messageTemplateTestSendLogic(props)
+ const { isModalOpen: isSendTestEmailModalOpen } = useValues(testSendLogic)
+ const { setModalOpen: setSendTestEmailModalOpen } = useActions(testSendLogic)
+
// Attach template logic to scene logic so it persists across tab switches
useAttachedLogic(logic, sceneLogic)
@@ -72,6 +78,15 @@ export function MessageTemplate(props: MessageTemplateSceneLogicProps): JSX.Elem
actions={
<>
<LemonDivider vertical />
+ <LemonButton
+ data-attr="send-test-message-template"
+ type="secondary"
+ onClick={() => setSendTestEmailModalOpen(true)}
+ disabledReason={!template.content.email?.subject ? 'Add a subject first' : undefined}
+ size="small"
+ >
+ Send test
+ </LemonButton>
{templateChanged && (
<LemonButton
data-attr="cancel-message-template"
@@ -143,6 +158,7 @@ export function MessageTemplate(props: MessageTemplateSceneLogicProps): JSX.Elem
/>
<TemplatePickerModal isOpen={templatePickerOpen} onClose={() => setTemplatePickerOpen(false)} />
+ <SendTestEmailModal {...props} isOpen={isSendTestEmailModalOpen} />
<div className="flex flex-col flex-1 gap-2 min-h-0 relative">
{messageLoading || templateLoading ? (
diff --git a/products/workflows/frontend/TemplateLibrary/SendTestEmailModal.tsx b/products/workflows/frontend/TemplateLibrary/SendTestEmailModal.tsx
new file mode 100644
index 000000000000..22671911dbed
--- /dev/null
+++ b/products/workflows/frontend/TemplateLibrary/SendTestEmailModal.tsx
@@ -0,0 +1,102 @@
+import { useActions, useValues } from 'kea'
+
+import { IconExternal } from '@posthog/icons'
+import { LemonBanner, LemonButton, LemonInput, LemonLabel, LemonSelect, Spinner } from '@posthog/lemon-ui'
+
+import { LemonModal } from 'lib/lemon-ui/LemonModal'
+import { urls } from 'scenes/urls'
+
+import { MessageTemplateLogicProps } from './messageTemplateLogic'
+import { messageTemplateTestSendLogic } from './messageTemplateTestSendLogic'
+
+export function SendTestEmailModal(props: MessageTemplateLogicProps & { isOpen: boolean }): JSX.Element {
+ const { isOpen, ...logicProps } = props
+ const logic = messageTemplateTestSendLogic(logicProps)
+ const {
+ recipientEmail,
+ senderIntegrationId,
+ emailIntegrations,
+ integrationsLoading,
+ sendDisabledReason,
+ testSendResult,
+ testSendResultLoading,
+ } = useValues(logic)
+ const { setModalOpen, setRecipientEmail, setSenderIntegrationId, sendTestEmail } = useActions(logic)
+
+ return (
+ <LemonModal
+ title="Send test email"
+ isOpen={isOpen}
+ onClose={() => setModalOpen(false)}
+ footer={
+ <>
+ <LemonButton type="secondary" onClick={() => setModalOpen(false)}>
+ Cancel
+ </LemonButton>
+ <LemonButton
+ type="primary"
+ data-attr="send-test-email-submit"
+ loading={testSendResultLoading}
+ disabledReason={sendDisabledReason}
+ onClick={() => sendTestEmail()}
+ >
+ Send test email
+ </LemonButton>
+ </>
+ }
+ >
+ <div className="flex flex-col gap-4 min-w-100">
+ <div className="flex flex-col gap-1">
+ <LemonLabel>Send to</LemonLabel>
+ <LemonInput
+ type="email"
+ value={recipientEmail}
+ onChange={setRecipientEmail}
+ placeholder="[email protected]"
+ data-attr="send-test-email-recipient"
+ />
+ </div>
+ <div className="flex flex-col gap-1">
+ <LemonLabel>From</LemonLabel>
+ {integrationsLoading && emailIntegrations.length === 0 ? (
+ <Spinner />
+ ) : emailIntegrations.length > 0 ? (
+ <LemonSelect
+ value={senderIntegrationId}
+ onChange={(id) => setSenderIntegrationId(id)}
+ options={emailIntegrations.map((integration) => ({
+ label: integration.display_name,
+ value: integration.id,
+ }))}
+ data-attr="send-test-email-sender"
+ fullWidth
+ />
+ ) : (
+ <div className="flex gap-2 items-center">
+ <span className="text-muted">No email senders configured yet</span>
+ <LemonButton
+ size="small"
+ type="secondary"
+ to={urls.workflows('channels')}
+ targetBlank
+ icon={<IconExternal />}
+ >
+ Connect email sender
+ </LemonButton>
+ </div>
+ )}
+ </div>
+ {testSendResult && testSendResult.status === 'skipped' ? (
+ <LemonBanner type="warning">
+ {testSendResult.logs?.map((log) => log.message).join(' ') ||
+ 'The send was skipped for this recipient.'}
+ </LemonBanner>
+ ) : testSendResult && testSendResult.status === 'error' ? (
+ <LemonBanner type="error">
+ {testSendResult.errors?.join(', ') || 'Failed to send test email'}
+ </LemonBanner>
+ ) : null}
+ </div>
+ </LemonModal>
+ )
+}
diff --git a/products/workflows/frontend/TemplateLibrary/messageTemplateTestSendLogic.test.ts b/products/workflows/frontend/TemplateLibrary/messageTemplateTestSendLogic.test.ts
new file mode 100644
index 000000000000..4a58a325eda8
--- /dev/null
+++ b/products/workflows/frontend/TemplateLibrary/messageTemplateTestSendLogic.test.ts
@@ -0,0 +1,182 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { messageTemplateLogic } from './messageTemplateLogic'
+import { messageTemplateTestSendLogic } from './messageTemplateTestSendLogic'
+
+jest.mock('lib/lemon-ui/LemonToast', () => ({
+ lemonToast: {
+ success: jest.fn(),
+ warning: jest.fn(),
+ error: jest.fn(),
+ },
+}))
+
+const mockToast = require('lib/lemon-ui/LemonToast').lemonToast
+
+describe('messageTemplateTestSendLogic', () => {
+ let logic: ReturnType<typeof messageTemplateTestSendLogic.build>
+ let templateLogic: ReturnType<typeof messageTemplateLogic.build>
+ let capturedBody: any
+
+ beforeEach(async () => {
+ jest.clearAllMocks()
+ capturedBody = null
+
+ useMocks({
+ get: {
+ '/api/environments/:team_id/integrations/': {
+ results: [
+ {
+ id: 4,
+ kind: 'email',
+ display_name: 'Unverified sender <[email protected]>',
+ config: { verified: false },
+ },
+ {
+ id: 5,
+ kind: 'email',
+ display_name: 'Sender <[email protected]>',
+ config: { verified: true },
+ },
+ { id: 6, kind: 'slack', display_name: 'Slack' },
+ ],
+ },
+ },
+ post: {
+ '/api/environments/:team_id/hog_flows/:id/invocations/': async ({ request }: { request: Request }) => {
+ capturedBody = await request.json()
+ return [200, { status: 'success', nextActionId: null }]
+ },
+ },
+ })
+
+ initKeaTests()
+
+ templateLogic = messageTemplateLogic({ id: 'new' })
+ templateLogic.mount()
+ templateLogic.actions.setTemplateValue('content.email.subject', 'Welcome')
+
+ logic = messageTemplateTestSendLogic({ id: 'new' })
+ logic.mount()
+
+ // The sender select defaults to the first email integration once it loads.
+ await expectLogic(integrationsLogic).toDispatchActions(['loadIntegrationsSuccess'])
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ templateLogic?.unmount()
+ })
+
+ it('prefills the recipient with the current user email when the modal opens', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.setModalOpen(true)
+ }).toMatchValues({ recipientEmail: '[email protected]' })
+ })
+
+ it('defaults the sender to the first verified email integration, excluding unverified and non-email kinds', async () => {
+ await expectLogic(logic).toMatchValues({
+ senderIntegrationId: 5,
+ emailIntegrations: [expect.objectContaining({ id: 5 })],
+ })
+ })
+
+ it('sends a one-step synthetic workflow carrying the typed recipient and template content, stripping any cc/bcc', async () => {
+ templateLogic.actions.setTemplateValue('content.email.cc', '[email protected]')
+ templateLogic.actions.setTemplateValue('content.email.bcc', '[email protected]')
+ logic.actions.setRecipientEmail('[email protected]')
+
+ await expectLogic(logic, () => {
+ logic.actions.sendTestEmail()
+ }).toDispatchActions(['sendTestEmailSuccess'])
+
+ expect(capturedBody.mock_async_functions).toBe(false)
+ expect(capturedBody.current_action_id).toBe('send_test_email')
+ expect(capturedBody.configuration.actions.filter((a: any) => a.type === 'trigger')).toHaveLength(1)
+
+ const emailAction = capturedBody.configuration.actions.find((a: any) => a.type === 'function_email')
+ expect(emailAction.config.inputs.email.value).toMatchObject({
+ subject: 'Welcome',
+ to: { email: '[email protected]', name: '' },
+ from: { integrationId: 5 },
+ cc: '',
+ bcc: '',
+ })
+
+ expect(mockToast.success).toHaveBeenCalledWith('Test email sent to [email protected]')
+ expect(logic.values.isModalOpen).toBe(false)
+ })
+
+ it('treats a skipped send as a distinct outcome from a failure', async () => {
+ useMocks({
+ post: {
+ '/api/environments/:team_id/hog_flows/:id/invocations/': () => [
+ 200,
+ { status: 'skipped', logs: [{ message: 'Recipient has opted out.' }] },
+ ],
+ },
+ })
+
+ logic.actions.setModalOpen(true)
+ logic.actions.setRecipientEmail('[email protected]')
+
+ await expectLogic(logic, () => {
+ logic.actions.sendTestEmail()
+ }).toDispatchActions(['sendTestEmailSuccess'])
+
+ expect(mockToast.warning).toHaveBeenCalledWith('Test email skipped, see details below')
+ expect(mockToast.error).not.toHaveBeenCalled()
+ expect(logic.values.isModalOpen).toBe(true)
+ expect(logic.values.testSendResult?.status).toBe('skipped')
+ })
+
+ it('keeps the modal open and surfaces the error when the send fails', async () => {
+ useMocks({
+ post: {
+ '/api/environments/:team_id/hog_flows/:id/invocations/': () => [
+ 200,
+ { status: 'error', errors: ['The selected email integration domain is not verified'] },
+ ],
+ },
+ })
+
+ logic.actions.setModalOpen(true)
+ logic.actions.setRecipientEmail('[email protected]')
+
+ await expectLogic(logic, () => {
+ logic.actions.sendTestEmail()
+ }).toDispatchActions(['sendTestEmailSuccess'])
+
+ expect(mockToast.error).toHaveBeenCalledWith('Failed to send test email')
+ expect(logic.values.isModalOpen).toBe(true)
+ expect(logic.values.testSendResult?.errors).toEqual(['The selected email integration domain is not verified'])
+ })
+
+ it('disables sending until subject, body, recipient, and sender are all valid', async () => {
+ templateLogic.actions.setTemplateValue('content.email.subject', '')
+ await expectLogic(logic).toMatchValues({ sendDisabledReason: 'Add a subject first' })
+
+ templateLogic.actions.setTemplateValue('content.email.subject', 'Welcome')
+ templateLogic.actions.setTemplateValue('content.email.text', '')
+ templateLogic.actions.setTemplateValue('content.email.html', '')
+ await expectLogic(logic).toMatchValues({ sendDisabledReason: 'Add email content first' })
+
+ templateLogic.actions.setTemplateValue('content.email.text', 'Hello!')
+ logic.actions.setRecipientEmail('not-an-email')
+ await expectLogic(logic).toMatchValues({ sendDisabledReason: 'Enter a valid email address' })
+
+ logic.actions.setRecipientEmail('[email protected]')
+ await expectLogic(logic).toMatchValues({ sendDisabledReason: undefined })
+ })
+
+ it('does not crash when a template has no email content, and disables sending', async () => {
+ templateLogic.actions.setTemplateValue('content.email', undefined)
+
+ await expectLogic(logic).toMatchValues({ sendDisabledReason: 'Add a subject first' })
+ })
+})
diff --git a/products/workflows/frontend/TemplateLibrary/messageTemplateTestSendLogic.ts b/products/workflows/frontend/TemplateLibrary/messageTemplateTestSendLogic.ts
new file mode 100644
index 000000000000..a7efe158ed80
--- /dev/null
+++ b/products/workflows/frontend/TemplateLibrary/messageTemplateTestSendLogic.ts
@@ -0,0 +1,264 @@
+import { MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+import { loaders } from 'kea-loaders'
+
+import api from 'lib/api'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+import { lemonToast } from 'lib/lemon-ui/LemonToast'
+import { isEmail } from 'lib/utils/url'
+import { teamLogic } from 'scenes/teamLogic'
+import { userLogic } from 'scenes/userLogic'
+
+import { IntegrationType, UserType } from '~/types'
+
+import { HogflowTestResult } from '../Workflows/hogflows/steps/types'
+import { createExampleEvent } from '../Workflows/hogflows/testEventFactory'
+import type { HogFlow, HogFlowAction, HogFlowEdge } from '../Workflows/hogflows/types'
+import { EXIT_NODE_ID, NEW_WORKFLOW, TRIGGER_NODE_ID } from '../Workflows/workflowLogic'
+import { MessageTemplateLogicProps, messageTemplateLogic } from './messageTemplateLogic'
+import { MessageTemplate } from './types'
+
+// Fixed id for the single email action in the synthetic test flow - referenced by the edges
+// below and passed as `current_action_id` so the CDP worker executes just this one node.
+const TEST_EMAIL_ACTION_ID = 'send_test_email'
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface messageTemplateTestSendLogicValues {
+ integrations: IntegrationType[] | null // integrationsLogic
+ integrationsLoading: boolean // integrationsLogic
+ template: MessageTemplate // messageTemplateLogic
+ currentTeamId: number | null // teamLogic
+ user: UserType | null // userLogic
+ emailIntegrations: IntegrationType[]
+ isModalOpen: boolean
+ recipientEmail: string
+ sendDisabledReason: string | undefined
+ senderIntegrationId: number | null
+ senderIntegrationIdOverride: number | null
+ testSendResult: HogflowTestResult | null
+ testSendResultLoading: boolean
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface messageTemplateTestSendLogicActions {
+ clearTestSendResult: () => {
+ value: true
+ }
+ clearTestSendResultFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ clearTestSendResultSuccess: (
+ testSendResult: null,
+ payload?: {
+ value: true
+ }
+ ) => {
+ testSendResult: null
+ payload?: {
+ value: true
+ }
+ }
+ sendTestEmail: () => any
+ sendTestEmailFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ sendTestEmailSuccess: (
+ testSendResult: HogflowTestResult,
+ payload?: any
+ ) => {
+ testSendResult: HogflowTestResult
+ payload?: any
+ }
+ setModalOpen: (open: boolean) => {
+ open: boolean
+ }
+ setRecipientEmail: (email: string) => {
+ email: string
+ }
+ setSenderIntegrationId: (id: number | null) => {
+ id: number | null
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface messageTemplateTestSendLogicMeta {
+ key: string
+ __keaTypeGenInternalSelectorTypes: {
+ emailIntegrations: (integrations: IntegrationType[] | null) => IntegrationType[]
+ senderIntegrationId: (
+ senderIntegrationIdOverride: number | null,
+ emailIntegrations: IntegrationType[]
+ ) => number | null
+ sendDisabledReason: (
+ template: MessageTemplate,
+ recipientEmail: string,
+ senderIntegrationId: number | null
+ ) => string | undefined
+ }
+}
+
+export type messageTemplateTestSendLogicType = MakeLogicType<
+ messageTemplateTestSendLogicValues,
+ messageTemplateTestSendLogicActions,
+ MessageTemplateLogicProps,
+ messageTemplateTestSendLogicMeta
+>
+
+export const messageTemplateTestSendLogic = kea<messageTemplateTestSendLogicType>([
+ path((key) => ['products', 'workflows', 'frontend', 'TemplateLibrary', 'messageTemplateTestSendLogic', key]),
+ props({} as MessageTemplateLogicProps),
+ key(({ id }) => id ?? 'new'),
+ connect((props: MessageTemplateLogicProps) => ({
+ values: [
+ messageTemplateLogic(props),
+ ['template'],
+ userLogic,
+ ['user'],
+ teamLogic,
+ ['currentTeamId'],
+ integrationsLogic,
+ ['integrations', 'integrationsLoading'],
+ ],
+ })),
+ actions({
+ setModalOpen: (open: boolean) => ({ open }),
+ setRecipientEmail: (email: string) => ({ email }),
+ setSenderIntegrationId: (id: number | null) => ({ id }),
+ clearTestSendResult: true,
+ }),
+ reducers({
+ isModalOpen: [false, { setModalOpen: (_, { open }) => open }],
+ recipientEmail: ['', { setRecipientEmail: (_, { email }) => email }],
+ senderIntegrationIdOverride: [null as number | null, { setSenderIntegrationId: (_, { id }) => id }],
+ }),
+ loaders(({ values }) => ({
+ testSendResult: [
+ null as HogflowTestResult | null,
+ {
+ clearTestSendResult: () => null,
+ sendTestEmail: async (): Promise<HogflowTestResult> => {
+ const { template, recipientEmail, senderIntegrationId, currentTeamId } = values
+
+ const emailAction: HogFlowAction = {
+ id: TEST_EMAIL_ACTION_ID,
+ type: 'function_email',
+ name: 'Send test email',
+ description: '',
+ created_at: 0,
+ updated_at: 0,
+ config: {
+ template_id: 'template-email',
+ inputs: {
+ email: {
+ value: {
+ ...template.content.email,
+ // A test send has exactly one visible recipient - never carry over a
+ // cc/bcc that happened to be on the copied source content.
+ cc: '',
+ bcc: '',
+ from: { integrationId: senderIntegrationId ?? undefined },
+ to: { email: recipientEmail, name: '' },
+ },
+ templating: template.content.templating === 'hog' ? 'hog' : 'liquid',
+ },
+ },
+ },
+ }
+
+ const edges: HogFlowEdge[] = [
+ { from: TRIGGER_NODE_ID, to: TEST_EMAIL_ACTION_ID, type: 'continue' },
+ { from: TEST_EMAIL_ACTION_ID, to: EXIT_NODE_ID, type: 'continue' },
+ ]
+
+ const configuration: HogFlow = {
+ ...NEW_WORKFLOW,
+ team_id: currentTeamId ?? NEW_WORKFLOW.team_id,
+ name: template.name || 'Test email',
+ actions: [NEW_WORKFLOW.actions[0], emailAction, NEW_WORKFLOW.actions[1]],
+ edges,
+ }
+
+ return await api.hogFlows.createTestInvocation('new', {
+ configuration,
+ globals: createExampleEvent(
+ currentTeamId ?? undefined,
+ configuration.name,
+ '$pageview',
+ recipientEmail
+ ),
+ mock_async_functions: false,
+ current_action_id: TEST_EMAIL_ACTION_ID,
+ })
+ },
+ },
+ ],
+ })),
+ selectors({
+ emailIntegrations: [
+ (s) => [s.integrations],
+ (integrations: IntegrationType[] | null): IntegrationType[] =>
+ integrations?.filter(
+ (integration) => integration.kind === 'email' && integration.config?.verified === true
+ ) ?? [],
+ ],
+ senderIntegrationId: [
+ (s) => [s.senderIntegrationIdOverride, s.emailIntegrations],
+ (override: number | null, emailIntegrations: IntegrationType[]): number | null =>
+ override ?? emailIntegrations[0]?.id ?? null,
+ ],
+ sendDisabledReason: [
+ (s) => [s.template, s.recipientEmail, s.senderIntegrationId],
+ (
+ template: MessageTemplate,
+ recipientEmail: string,
+ senderIntegrationId: number | null
+ ): string | undefined => {
+ if (!template.content.email?.subject) {
+ return 'Add a subject first'
+ }
+ if (!template.content.email.text && !template.content.email.html) {
+ return 'Add email content first'
+ }
+ if (!recipientEmail || !isEmail(recipientEmail)) {
+ return 'Enter a valid email address'
+ }
+ if (!senderIntegrationId) {
+ return 'Connect an email sender first'
+ }
+ return undefined
+ },
+ ],
+ }),
+ listeners(({ actions, values }) => ({
+ setModalOpen: ({ open }) => {
+ if (!open) {
+ return
+ }
+ actions.clearTestSendResult()
+ if (!values.recipientEmail && values.user?.email) {
+ actions.setRecipientEmail(values.user.email)
+ }
+ },
+ sendTestEmailSuccess: ({ testSendResult }) => {
+ if (testSendResult.status === 'success') {
+ lemonToast.success(`Test email sent to ${values.recipientEmail}`)
+ actions.setModalOpen(false)
+ actions.clearTestSendResult()
+ } else if (testSendResult.status === 'skipped') {
+ lemonToast.warning('Test email skipped, see details below')
+ } else {
+ lemonToast.error('Failed to send test email')
+ }
+ },
+ sendTestEmailFailure: () => {
+ lemonToast.error('Failed to send test email')
+ },
+ })),
+])
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/hogFlowOutputMappingLogic.ts b/products/workflows/frontend/Workflows/hogflows/panel/hogFlowOutputMappingLogic.ts
index ab10a5932450..50ed79be17ec 100644
--- a/products/workflows/frontend/Workflows/hogflows/panel/hogFlowOutputMappingLogic.ts
+++ b/products/workflows/frontend/Workflows/hogflows/panel/hogFlowOutputMappingLogic.ts
@@ -9,9 +9,10 @@ import { OutputMappingSuggestion } from '../hogFlowEditorLogic'
import { hogFlowEditorLogic } from '../hogFlowEditorLogic'
import { getRegisteredActionNodeCategories } from '../registry/actions/actionNodeRegistry'
import type { HogflowTestResult } from '../steps/types'
+import { createExampleEvent } from '../testEventFactory'
import type { HogFlowAction } from '../types'
import type { HogFlow, HogFlowActionNode } from '../types'
-import { createExampleEvent, hogFlowEditorTestLogic } from './testing/hogFlowEditorTestLogic'
+import { hogFlowEditorTestLogic } from './testing/hogFlowEditorTestLogic'
export type OutputMapping = { key: string; result_path: string; spread?: boolean | null }
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorNotificationTestLogic.ts b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorNotificationTestLogic.ts
index 4be9699706b6..0a3e3623ea1b 100644
--- a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorNotificationTestLogic.ts
+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorNotificationTestLogic.ts
@@ -17,8 +17,9 @@ import { CyclotronJobInvocationGlobals, FilterLogicalOperator, PersonType, Prope
import { WorkflowLogicProps, workflowLogic } from '../../../workflowLogic'
import { hogFlowEditorLogic } from '../../hogFlowEditorLogic'
import { HogflowTestResult } from '../../steps/types'
+import { createExampleEvent } from '../../testEventFactory'
import type { HogFlow } from '../../types'
-import { createExampleEvent, createGlobalsFromResponse } from './hogFlowEditorTestLogic'
+import { createGlobalsFromResponse } from './hogFlowEditorTestLogic'
import type { HogflowTestInvocation } from './hogFlowEditorTestLogic'
// Time range constants for event search
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts
index 0a94f471bb61..3d8c22883172 100644
--- a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts
+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts
@@ -9,7 +9,6 @@ import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
import { dayjs } from 'lib/dayjs'
import { groupsAccessLogic } from 'lib/introductions/groupsAccessLogic'
-import { uuid } from 'lib/utils/dom'
import { performWideEventsQueryInTwoPhases } from 'scenes/hog-functions/sampleEventsQuery'
import { groupsModel } from '~/models/groupsModel'
@@ -30,6 +29,7 @@ import { WorkflowLogicProps, workflowLogic } from '../../../workflowLogic'
import type { TriggerAction } from '../../../workflowLogic'
import { hogFlowEditorLogic } from '../../hogFlowEditorLogic'
import { HogflowTestResult } from '../../steps/types'
+import { createExampleEvent } from '../../testEventFactory'
import type { HogFlow } from '../../types'
// Time range constants for event search
@@ -43,51 +43,6 @@ export interface HogflowTestInvocation {
mock_async_functions: boolean
}
-export const createExampleEvent = (
- teamId?: number,
- workflowName?: string | null,
- eventName: string = '$pageview',
- email: string = '[email protected]'
-): CyclotronJobInvocationGlobals => {
- const resolvedTeamId = teamId || 1
- const projectUrl = `${window.location.origin}/project/${resolvedTeamId}`
- const eventUuid = uuid()
- const eventTimestamp = dayjs().toISOString()
- return {
- event: {
- uuid: eventUuid,
- distinct_id: uuid(),
- timestamp: eventTimestamp,
- elements_chain: '',
- url: `${projectUrl}/events/${encodeURIComponent(eventUuid)}/${encodeURIComponent(eventTimestamp)}`,
- event: eventName,
- properties: {
- $current_url: window.location.href.split('#')[0],
- $browser: 'Chrome',
- this_is_an_example_event: true,
- },
- },
- person: {
- id: uuid(),
- properties: {
- email,
- },
- name: 'Example person',
- url: `${window.location.origin}/person/${uuid()}`,
- },
- groups: {},
- project: {
- id: resolvedTeamId,
- name: 'Default project',
- url: projectUrl,
- },
- source: {
- name: workflowName ?? 'Unnamed',
- url: window.location.href.split('#')[0],
- },
- }
-}
-
// HogQL tuple columns appended to the events query so we can resolve each group type's
// key + properties for the sample, mirroring real execution which resolves them from $groups.
export const groupSelectColumns = (groupTypes: Map<GroupTypeIndex, GroupType>): string[] => {
diff --git a/products/workflows/frontend/Workflows/hogflows/testEventFactory.ts b/products/workflows/frontend/Workflows/hogflows/testEventFactory.ts
new file mode 100644
index 000000000000..0659a8d9ad3e
--- /dev/null
+++ b/products/workflows/frontend/Workflows/hogflows/testEventFactory.ts
@@ -0,0 +1,51 @@
+import { dayjs } from 'lib/dayjs'
+import { uuid } from 'lib/utils/dom'
+
+import { CyclotronJobInvocationGlobals } from '~/types'
+
+// A pure, kea-free factory for a synthetic test event/person - kept out of hogFlowEditorTestLogic
+// so callers that only need example data don't pull in the workflow editor's kea logic graph.
+export const createExampleEvent = (
+ teamId?: number,
+ workflowName?: string | null,
+ eventName: string = '$pageview',
+ email: string = '[email protected]'
+): CyclotronJobInvocationGlobals => {
+ const resolvedTeamId = teamId || 1
+ const projectUrl = `${window.location.origin}/project/${resolvedTeamId}`
+ const eventUuid = uuid()
+ const eventTimestamp = dayjs().toISOString()
+ return {
+ event: {
+ uuid: eventUuid,
+ distinct_id: uuid(),
+ timestamp: eventTimestamp,
+ elements_chain: '',
+ url: `${projectUrl}/events/${encodeURIComponent(eventUuid)}/${encodeURIComponent(eventTimestamp)}`,
+ event: eventName,
+ properties: {
+ $current_url: window.location.href.split('#')[0],
+ $browser: 'Chrome',
+ this_is_an_example_event: true,
+ },
+ },
+ person: {
+ id: uuid(),
+ properties: {
+ email,
+ },
+ name: 'Example person',
+ url: `${window.location.origin}/person/${uuid()}`,
+ },
+ groups: {},
+ project: {
+ id: resolvedTeamId,
+ name: 'Default project',
+ url: projectUrl,
+ },
+ source: {
+ name: workflowName ?? 'Unnamed',
+ url: window.location.href.split('#')[0],
+ },
+ }
+}