toolTrace.test.ts 1.4 KB

12345678910111213141516171819202122232425
  1. import { flushPromises, mount } from '@vue/test-utils'
  2. import { afterEach, expect, it, vi } from 'vitest'
  3. import ToolTrace from '@/components/messages/ToolTrace.vue'
  4. import { apiRequest } from '@/api/client'
  5. vi.mock('@/api/client', () => ({ apiRequest: vi.fn() }))
  6. afterEach(() => vi.clearAllMocks())
  7. it('fetches tool details only when expanded, reuses them, and loads a new revision without showing stale output', async () => {
  8. vi.mocked(apiRequest).mockResolvedValue({ input: 'input', output: 'complete output' })
  9. const tool = { id: 'tool', name: 'read', status: 'success' as const, detailsUrl: '/api/app/tool?revision=1' }
  10. const wrapper = mount(ToolTrace, { props: { tool } })
  11. expect(apiRequest).not.toHaveBeenCalled()
  12. await wrapper.get('button').trigger('click'); await flushPromises()
  13. expect(apiRequest).toHaveBeenCalledTimes(1)
  14. expect(wrapper.text()).toContain('complete output')
  15. await wrapper.get('button').trigger('click'); await wrapper.get('button').trigger('click'); await flushPromises()
  16. expect(apiRequest).toHaveBeenCalledTimes(1)
  17. vi.mocked(apiRequest).mockResolvedValue({ output: 'new revision' })
  18. await wrapper.setProps({ tool: { ...tool, detailsUrl: '/api/app/tool?revision=2' } }); await flushPromises()
  19. expect(apiRequest).toHaveBeenCalledTimes(2)
  20. expect(wrapper.text()).toContain('new revision')
  21. expect(wrapper.text()).not.toContain('complete output')
  22. wrapper.unmount()
  23. })