import { buildMemberOptions, dedupeMembers, nextSandboxSelection, resolveSandboxOverall, resolveSandboxScores } from '@/utils/wuxing-sandbox' const familyScores = { bodyScore: 59, mindScore: 0, wisdomScore: 8, actionScore: 0, wealthScore: 8, overallScore: 15 } const personalData = { bodyScore: 75, mindScore: 0, wisdomScore: 3, actionScore: 0, wealthScore: 30, overallScore: 21, members: [{ memberId: 12, memberType: 'parent', name: '他爹' }] } const members = [ { memberId: 12, memberType: 'parent', name: '他爹', bodyScore: 75, mindScore: 0, wisdomScore: 3, actionScore: 0, wealthScore: 30, overallScore: 21 }, { memberId: 34, memberType: 'parent', name: '书宁宁', bodyScore: 78, mindScore: 0, wisdomScore: 10, actionScore: 0, wealthScore: 6, overallScore: 19 }, { memberId: 78, memberType: 'parent', name: '云泽', bodyScore: 0, mindScore: 0, wisdomScore: 0, actionScore: 0, wealthScore: 0, overallScore: 0 }, { memberId: 23, memberType: 'child', name: '老二', bodyScore: 0, mindScore: 0, wisdomScore: 43, actionScore: 0, wealthScore: 21, overallScore: 13 }, // 完全重复的成员记录只能出现一次 { memberId: 34, memberType: 'parent', name: '书宁宁', bodyScore: 78, mindScore: 0, wisdomScore: 10, actionScore: 0, wealthScore: 6, overallScore: 19 } ] describe('wuxing sandbox member selection', () => { test('dedupeMembers removes exact duplicate member rows', () => { expect(dedupeMembers(members).map(m => m.memberId)).toEqual([12, 34, 78, 23]) }) test('buildMemberOptions excludes self, dedupes members and appends family', () => { const options = buildMemberOptions(members, personalData) expect(options.map(o => o.label)).toEqual(['本人', '书宁宁', '云泽', '老二', '全家']) expect(options[0].viewMode).toBe('personal') expect(options[options.length - 1].viewMode).toBe('family') }) test('member view uses the selected member scores instead of personalData', () => { const selected = members[1] expect(resolveSandboxScores('member', familyScores, personalData, selected)).toEqual([78, 0, 10, 0, 6]) expect(resolveSandboxOverall('member', familyScores, personalData, selected)).toBe(19) }) test('personal view keeps the login user scores', () => { expect(resolveSandboxScores('personal', familyScores, personalData, null)).toEqual([75, 0, 3, 0, 30]) expect(resolveSandboxOverall('personal', familyScores, personalData, null)).toBe(21) }) test('family view uses family aggregate scores', () => { expect(resolveSandboxScores('family', familyScores, personalData, null)).toEqual([59, 0, 8, 0, 8]) expect(resolveSandboxOverall('family', familyScores, personalData, null)).toBe(15) }) test('center click cycles personal -> other members -> family -> personal', () => { const options = buildMemberOptions(members, personalData) expect(nextSandboxSelection(options, 'personal', null)).toMatchObject({ viewMode: 'member', memberId: 34 }) expect(nextSandboxSelection(options, 'member', 34)).toMatchObject({ viewMode: 'member', memberId: 78 }) expect(nextSandboxSelection(options, 'member', 23)).toMatchObject({ viewMode: 'family' }) expect(nextSandboxSelection(options, 'family', null)).toMatchObject({ viewMode: 'personal' }) }) test('only family and self falls back to self instead of showing an empty member', () => { const onlySelf = { ...personalData, members: [{ memberId: 12, memberType: 'parent', name: '他爹' }] } const options = buildMemberOptions([], onlySelf) expect(options.map(o => o.viewMode)).toEqual(['personal', 'family']) expect(nextSandboxSelection(options, 'personal', null)).toMatchObject({ viewMode: 'family' }) }) })