Newer
Older
navi-1 / webclient / tests / unit / components / chat / recallInfoModal.test.js
// @vitest-environment jsdom
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { mount, flushPromises } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'

vi.mock('@/api/index.js', () => ({
  getSessionRecall: vi.fn(),
  cancelSessionRecall: vi.fn(),
  skipSessionRecall: vi.fn(),
}))

import * as api from '@/api/index.js'
import { useChatStore } from '@/stores/chat.js'
import { setLocale } from '@/i18n/index.js'
import RecallInfoModal from '@/components/chat/RecallInfoModal.vue'

const RECALL = {
  id: 'r1',
  call_type: 'recurring',
  trigger_at: '2026-11-02T14:00:00+00:00',
  interval_seconds: 1800,
  internal_comment: 'Check build logs',
  additional_context_message: 'Read /tmp/build.log\nReport the tail.',
  status: 'pending',
  created_at: '2026-11-02T13:30:00+00:00',
}

let wrapper = null

async function mountDialog(recall = RECALL) {
  setActivePinia(createPinia())
  const store = useChatStore()
  store.currentId = 's1'
  store.recall = recall
  api.getSessionRecall.mockResolvedValue({ recall })

  wrapper = mount(RecallInfoModal, {
    props: { open: true },
    attachTo: document.body,
  })
  await flushPromises()
  return store
}

beforeEach(() => {
  setLocale('en')
  vi.clearAllMocks()
})

afterEach(() => {
  wrapper?.unmount()
  wrapper = null
  document.body.innerHTML = ''
})

describe('RecallInfoModal', () => {
  it('shows the kind, the times and the repeat interval', async () => {
    await mountDialog()
    const text = document.body.textContent

    expect(text).toContain('recurring')
    expect(text).toContain('Repeats')
    expect(text).toContain('30 min')
    expect(text).toContain('Created')
  })

  it('shows the system message verbatim', async () => {
    await mountDialog()

    const message = document.body.querySelector('.ri-message')
    expect(message?.textContent).toBe('Read /tmp/build.log\nReport the tail.')
  })

  it('offers skip only for a recurring recall', async () => {
    await mountDialog({ ...RECALL, call_type: 'once', interval_seconds: null })

    expect(document.body.textContent).not.toContain('Skip next')
    expect(document.body.textContent).toContain('Cancel call')
  })
})