cardRenderer.spec.ts 4.8 KB

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