Skip to content
Merged
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
20 changes: 20 additions & 0 deletions src/workbench/extensions/agent/AgentPanelRoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8923,6 +8923,26 @@ describe('AgentPanelRoot workflow binding', () => {
expect(screen.queryByTestId('agent-coach-hold-notice')).toBeNull()
})

it('sends once when another tab finishes the tour during the hold', async () => {
const key = 'Comfy.AgentPanel.onboarded.account-a.workspace-hold'
makeTab('wf-42')
const bodies = mockMessagesEndpoint('wf-42')
renderWithSelectedTarget()
await sendHeldByCoach('build me a workflow')
expect(bodies).toHaveLength(0)

localStorage.setItem(key, 'true')
window.dispatchEvent(
new StorageEvent('storage', {
key,
newValue: 'true',
storageArea: localStorage
})
)

await waitFor(() => expect(bodies).toHaveLength(1))
})

it('sends once when a coach step never finds its target', async () => {
vi.useFakeTimers({ shouldAdvanceTime: true })
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,90 @@ describe('OnboardingCoach', () => {
expect(useOnboardingOverlayStore().active).toBe(true)
})

function mountWithFinished(
storageKey: string,
onFinished: () => void,
steps = STEPS
) {
return render(
{
components: { OnboardingCoach },
setup: () => ({ steps, storageKey, onFinished }),
template:
'<div id="panel" /><div id="composer" /><div id="graph"><div id="toolbar" /></div><div id="history" /><OnboardingCoach :steps="steps" :storage-key="storageKey" @finished="onFinished" />'
},
{ global: { plugins: [i18n] } }
)
}

it('reports the tour finished when another tab completes it', async () => {
const onFinished = vi.fn()
mountWithFinished('coach-elsewhere', onFinished)
await screen.findByRole('dialog', { name: 'Meet the agent' })

localStorage.setItem('coach-elsewhere', 'true')
window.dispatchEvent(
new StorageEvent('storage', {
key: 'coach-elsewhere',
newValue: 'true',
storageArea: localStorage
})
)

await waitFor(() => expect(onFinished).toHaveBeenCalled())
await nextTick()

expect(onFinished).toHaveBeenCalledOnce()
})

it('reports finished once when the user skips', async () => {
const onFinished = vi.fn()
mountWithFinished('coach-skip-once', onFinished)
await userEvent.click(await screen.findByRole('button', { name: 'Skip' }))
await nextTick()
await nextTick()

expect(onFinished).toHaveBeenCalledOnce()
})

it('reports finished once when the user clicks Done', async () => {
const onFinished = vi.fn()
mountWithFinished('coach-done-once', onFinished, [STEPS[0]])
await userEvent.click(await screen.findByRole('button', { name: 'Done' }))
await nextTick()
await nextTick()

expect(onFinished).toHaveBeenCalledOnce()
})

it('reports a later completion in another tab after a replay', async () => {
const onFinished = vi.fn()
const coach = ref<{ restart: () => void } | null>(null)
render(
{
components: { OnboardingCoach },
setup: () => ({ steps: STEPS, coach, onFinished }),
template:
'<div id="panel" /><OnboardingCoach ref="coach" :steps="steps" storage-key="coach-replay-elsewhere" @finished="onFinished" />'
},
{ global: { plugins: [i18n] } }
)
await userEvent.click(await screen.findByRole('button', { name: 'Skip' }))
coach.value?.restart()
await screen.findByRole('dialog', { name: 'Meet the agent' })

localStorage.setItem('coach-replay-elsewhere', 'true')
window.dispatchEvent(
new StorageEvent('storage', {
key: 'coach-replay-elsewhere',
newValue: 'true',
storageArea: localStorage
})
)

await waitFor(() => expect(onFinished).toHaveBeenCalledTimes(2))
})

describe('reporting a step whose target never mounts', () => {
const renderMissing = (target: string) =>
render(OnboardingCoach, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,29 @@ function reportStep(action: AgentOnboardingAction): void {
useTelemetry()?.trackAgentOnboardingStep({ step: index.value + 1, action })
}

let finishedHere = false

function onNext(): void {
const finished = isLast.value
reportStep(isLast.value ? 'finish' : 'next')
if (finished) finishedHere = true
next()
if (finished) emit('finished')
}

function onSkip(): void {
reportStep('skip')
finishedHere = true
finish()
emit('finished')
}

const completed = computed(() => !active.value && !!step.value)
watch(completed, (isCompleted) => {
if (isCompleted && !finishedHere) emit('finished')
finishedHere = false
})

const targetObserver = new MutationObserver(resolveTargets)
targetObserver.observe(document.body, {
childList: true,
Expand Down
Loading