interactionCard.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930
  1. import { expect, it } from 'vitest'
  2. import { mount } from '@vue/test-utils'
  3. import InteractionCard from '@/components/messages/InteractionCard.vue'
  4. it('submits a selected clarification option and exposes the selected state', async () => {
  5. const wrapper = mount(InteractionCard, { props: { interaction: {
  6. id: 'clarify-1', kind: 'clarification', prompt: '先创建草稿,还是继续调整?', options: ['先创建草稿', '继续调整'],
  7. } } })
  8. const inputs = wrapper.findAll('input[type="radio"]')
  9. await inputs[0]!.setValue(true)
  10. expect((inputs[0]!.element as HTMLInputElement).checked).toBe(true)
  11. expect(wrapper.findAll('.interaction-card__options label')[0]!.classes()).toContain('selected')
  12. await wrapper.get('form').trigger('submit')
  13. expect(wrapper.emitted('clarify')).toEqual([['先创建草稿']])
  14. })
  15. it('prefers a custom clarification answer and resets the draft for the next question', async () => {
  16. const wrapper = mount(InteractionCard, { props: { interaction: {
  17. id: 'clarify-1', kind: 'clarification', prompt: '需要哪种格式?', options: ['文档'],
  18. } } })
  19. await wrapper.get('textarea').setValue('请同时提供 PDF')
  20. await wrapper.get('form').trigger('submit')
  21. expect(wrapper.emitted('clarify')).toEqual([['请同时提供 PDF']])
  22. await wrapper.setProps({ interaction: { id: 'clarify-2', kind: 'clarification', prompt: '是否继续?' } })
  23. expect(wrapper.get('textarea').element.value).toBe('')
  24. expect(wrapper.get('button[type="submit"]').attributes('disabled')).toBeDefined()
  25. })