cardRenderer.spec.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // @vitest-environment jsdom
  2. import { mount } from '@vue/test-utils';
  3. import { createPinia, setActivePinia } from 'pinia';
  4. import { beforeEach, describe, expect, it } from 'vitest';
  5. import CardRenderer from '../../src/cards/CardRenderer.vue';
  6. describe('CardRenderer', () => {
  7. beforeEach(() => setActivePinia(createPinia()));
  8. it('renders department card by cardKey', () => {
  9. const wrapper = mount(CardRenderer, {
  10. props: {
  11. card: {
  12. cardInstanceId: 'card_department',
  13. cardKey: 'department-selection',
  14. status: 'active',
  15. cardData: { departments: [{ departmentId: 'neurology', name: '神经内科', reason: '头痛伴恶心' }] },
  16. actions: [{ actionName: 'select_department', label: '选择科室' }]
  17. }
  18. }
  19. });
  20. expect(wrapper.text()).toContain('推荐');
  21. expect(wrapper.text()).toContain('神经内科');
  22. });
  23. it('renders doctor selection card', () => {
  24. const wrapper = mount(CardRenderer, {
  25. props: {
  26. card: {
  27. cardInstanceId: 'card_doctor',
  28. cardKey: 'doctor-selection',
  29. status: 'active',
  30. cardData: { doctors: [{ doctorId: 'DOC001', name: '李明', title: '主任医师', specialty: '头痛', room: '302' }] },
  31. actions: [{ actionName: 'select_doctor', label: '选择医生' }]
  32. }
  33. }
  34. });
  35. expect(wrapper.text()).toContain('推荐');
  36. expect(wrapper.text()).toContain('李明');
  37. expect(wrapper.text()).toContain('主任医师');
  38. });
  39. it('renders time slot selection card', () => {
  40. const wrapper = mount(CardRenderer, {
  41. props: {
  42. card: {
  43. cardInstanceId: 'card_slot',
  44. cardKey: 'time-slot-selection',
  45. status: 'active',
  46. cardData: { slots: [{ slotId: 's1', timePeriod: '明天 09:30-09:45', remaining: 3 }] },
  47. actions: [{ actionName: 'select_time_slot', label: '选择时间' }]
  48. }
  49. }
  50. });
  51. expect(wrapper.text()).toContain('6月5日');
  52. expect(wrapper.text()).toContain('明天 09:30-09:45');
  53. });
  54. it('renders confirm appointment card', () => {
  55. const wrapper = mount(CardRenderer, {
  56. props: {
  57. card: {
  58. cardInstanceId: 'card_confirm',
  59. cardKey: 'confirm-appointment',
  60. status: 'active',
  61. cardData: { summary: { departmentName: '神经内科', doctorName: '李明', visitTime: '明天 09:30', amount: 25 } },
  62. actions: [{ actionName: 'confirm_appointment', label: '确认挂号', requiredConfirm: true }]
  63. }
  64. }
  65. });
  66. expect(wrapper.text()).toContain('确认预约信息');
  67. expect(wrapper.text()).toContain('神经内科');
  68. expect(wrapper.text()).toContain('¥25');
  69. });
  70. it('renders payment QR card with mock label', () => {
  71. const wrapper = mount(CardRenderer, {
  72. props: {
  73. card: {
  74. cardInstanceId: 'card_payment',
  75. cardKey: 'payment-qrcode',
  76. status: 'active',
  77. cardData: { orderId: 'PAY001', amount: 25, qrContent: 'demo-payment://test', mock: true },
  78. actions: [{ actionName: 'mock_payment_paid', label: '模拟支付完成', requiredConfirm: true }]
  79. }
  80. }
  81. });
  82. expect(wrapper.text()).toContain('联调演示 · Mock 支付');
  83. expect(wrapper.text()).toContain('模拟支付完成');
  84. });
  85. it('renders appointment success card with mock label', () => {
  86. const wrapper = mount(CardRenderer, {
  87. props: {
  88. card: {
  89. cardInstanceId: 'card_success',
  90. cardKey: 'appointment-success',
  91. status: 'completed',
  92. cardData: { appointmentNo: 'A023', departmentName: '神经内科', doctorName: '李明', visitTime: '明天 09:30', room: '302', mock: true },
  93. actions: []
  94. }
  95. }
  96. });
  97. expect(wrapper.text()).toContain('挂号成功');
  98. expect(wrapper.text()).toContain('A023');
  99. expect(wrapper.text()).toContain('联调演示');
  100. });
  101. it('renders error card for unknown card key', () => {
  102. const wrapper = mount(CardRenderer, {
  103. props: {
  104. card: {
  105. cardInstanceId: 'card_unknown',
  106. cardKey: 'unknown-type',
  107. status: 'active',
  108. cardData: {},
  109. actions: []
  110. }
  111. }
  112. });
  113. expect(wrapper.text()).toContain('暂不支持的卡片类型');
  114. });
  115. it('emits action event when card button is clicked', async () => {
  116. const wrapper = mount(CardRenderer, {
  117. props: {
  118. card: {
  119. cardInstanceId: 'card_department',
  120. cardKey: 'department-selection',
  121. status: 'active',
  122. cardData: { departments: [{ departmentId: 'neurology', name: '神经内科', reason: '头痛伴恶心' }] },
  123. actions: [{ actionName: 'select_department', label: '选择科室' }]
  124. }
  125. }
  126. });
  127. await wrapper.find('.dept-full').trigger('click');
  128. expect(wrapper.emitted('action')).toBeTruthy();
  129. expect(wrapper.emitted('action')![0]).toEqual([{
  130. actionName: 'select_department',
  131. payload: { departmentId: 'neurology', departmentName: '神经内科' },
  132. }]);
  133. });
  134. });