family-members.joinRequestCardInfo.test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Contract tests for capability key `family.invite.joinRequestCardInfo`
  3. * (spec: docs/superpowers/specs/2026-11-07-family-join-required-info.md §5 WI-4)
  4. *
  5. * AC4.1 待审批卡片显示申请人真实姓名、出生日期、性别。
  6. * AC4.2 任一字段缺失时优雅回退(不报错、不显示乱码)。
  7. *
  8. * TDD phase: RED. These tests target the REAL `family-members.vue` join-request
  9. * card. The current implementation only renders the requester's name
  10. * (`requesterRealName || requesterNickname`); it does NOT render the applicant's
  11. * birthday or gender. Therefore the AC4.1 assertions are expected to FAIL until
  12. * WI-4 is implemented (approval card shows birthday + gender).
  13. *
  14. * Note: `@jest-environment jsdom` is required because @vue/test-utils `mount`
  15. * needs a DOM; the default `node` env does not provide one.
  16. *
  17. * @jest-environment jsdom
  18. */
  19. import { mount } from '@vue/test-utils'
  20. import FamilyMembers from '@/pages/profile-extra/family-members.vue'
  21. // A fully-populated pending join request (FamilyJoinRequestDTO shape).
  22. const fullRequest = {
  23. id: 1001,
  24. requesterUserId: 200,
  25. requesterRealName: '张三',
  26. requesterNickname: 'zhangsan',
  27. requesterBirthday: '1990-01-01',
  28. requesterGender: 'male',
  29. requesterAvatar: '/static/avatar.jpg'
  30. }
  31. async function mountWithRequests(requests) {
  32. const wrapper = mount(FamilyMembers, {
  33. stubs: { 'generation-picker': true }
  34. })
  35. wrapper.setData({ joinRequests: requests || [] })
  36. await wrapper.vm.$nextTick()
  37. return wrapper
  38. }
  39. describe('family.invite.joinRequestCardInfo (WI-4 审批卡片展示三项信息)', () => {
  40. it('AC4.1: 审批卡片显示申请人真实姓名、出生日期、性别', async () => {
  41. const wrapper = await mountWithRequests([fullRequest])
  42. const section = wrapper.find('.join-request-section')
  43. expect(section.exists()).toBe(true)
  44. const text = section.text()
  45. // 真实姓名(AC4.1 第一项)
  46. expect(text).toContain('张三')
  47. // 出生日期(AC4.1 第二项)
  48. expect(text).toContain('1990-01-01')
  49. // 性别(AC4.1 第三项):male/female 或其中文标签 男/女 均可
  50. expect(text).toMatch(/(male|female|男|女)/)
  51. })
  52. it('AC4.1: 性别为 female 时卡片仍展示性别信息', async () => {
  53. const wrapper = await mountWithRequests([
  54. Object.assign({}, fullRequest, { requesterGender: 'female', requesterRealName: '李四', requesterBirthday: '1985-06-15' })
  55. ])
  56. const text = wrapper.find('.join-request-section').text()
  57. expect(text).toContain('李四')
  58. expect(text).toContain('1985-06-15')
  59. expect(text).toMatch(/(female|男|女)/)
  60. })
  61. it('AC4.2: 出生日期/性别缺失时不报错、不显示 undefined/null 乱码,且真实姓名仍展示', async () => {
  62. const partialRequest = {
  63. id: 1002,
  64. requesterUserId: 201,
  65. requesterRealName: '王五',
  66. requesterNickname: 'wangwu'
  67. // requesterBirthday / requesterGender 缺失(null/undefined)
  68. }
  69. // 组件应正常挂载渲染(抛错即失败)
  70. const wrapper = await mountWithRequests([partialRequest])
  71. const text = wrapper.find('.join-request-section').text()
  72. expect(text).toContain('王五')
  73. // 优雅回退:不允许把缺失值渲染成字面 'undefined' / 'null'
  74. expect(text).not.toContain('undefined')
  75. expect(text).not.toContain('null')
  76. })
  77. it('AC4.2: 真实姓名缺失时回退展示昵称(不显示空白/乱码)', async () => {
  78. const noRealName = {
  79. id: 1003,
  80. requesterUserId: 202,
  81. requesterRealName: '',
  82. requesterNickname: 'nick_fallback',
  83. requesterBirthday: '2000-12-31',
  84. requesterGender: 'female'
  85. }
  86. const wrapper = await mountWithRequests([noRealName])
  87. const text = wrapper.find('.join-request-section').text()
  88. expect(text).toContain('nick_fallback')
  89. expect(text).not.toContain('undefined')
  90. })
  91. it('边界: 无待处理加入申请时不渲染审批卡片区块', async () => {
  92. const wrapper = await mountWithRequests([])
  93. expect(wrapper.find('.join-request-section').exists()).toBe(false)
  94. })
  95. })