Newer
Older
navi-1 / webclient / tests / unit / components / messages / assistantMessageContentPublish.test.js
// @vitest-environment jsdom
import { beforeEach, describe, expect, it } from 'vitest'
import { nextTick, reactive } from 'vue'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'

import { setLocale } from '@/i18n/index.js'
import AssistantMessage from '@/components/messages/AssistantMessage.vue'

function publishCard() {
  return {
    kind: 'tool',
    id: 'tool_1',
    toolCallId: 'cp1',
    name: 'content_publish',
    args: { filename: 'report.html' },
    result: null,
    success: null,
    pending: true,
    startedAt: Date.now(),
    isSubagent: false,
    steps: [],
  }
}

function streamMsg(tools) {
  return reactive({
    id: 'stream_1',
    role: 'assistant',
    type: 'stream',
    tools,
    thinking: null,
    text: '',
    done: false,
    time: new Date().toISOString(),
    animate: false,
    statusLabel: null,
  })
}

beforeEach(() => {
  setActivePinia(createPinia())
  setLocale('en')
})

describe('AssistantMessage — content_publish live', () => {
  it('shows the running publish as a tool card, not as a failed content card', () => {
    const wrapper = mount(AssistantMessage, { props: { msg: streamMsg([publishCard()]) } })

    expect(wrapper.find('.tool-card').exists()).toBe(true)
    expect(wrapper.find('.content-card').exists()).toBe(false)

    wrapper.unmount()
  })

  it('swaps to the content card as soon as the result lands mid-turn', async () => {
    const msg = streamMsg([publishCard()])
    // The reactive array hands back the proxy a component actually renders.
    const card = msg.tools[0]
    const wrapper = mount(AssistantMessage, { props: { msg } })

    card.pending = false
    card.success = true
    card.metadata = {
      url: 'https://navi.local/api/sessions/s1/content/a.html',
      content_type: 'html',
      title: 'Report',
    }
    await nextTick()

    expect(wrapper.find('.content-card').exists()).toBe(true)
    expect(wrapper.text()).toContain('Report')

    wrapper.unmount()
  })
})