From 5da7ecfcfda6f01f0133d63946b51631a7a83681 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 29 May 2026 12:32:16 +0800 Subject: [PATCH] test(frontend): ProfileSecurityPage ContactBindingsSection contract coverage - Add test verifying ContactBindingsSection receives correct capability props - Test userId, emailBindingEnabled, phoneBindingEnabled, refreshSessionUser - Lock regression: prevent future removal of prop-passing while keeping render Refs: review-fix-closure-2026-05-28 ProfileSecurityPage component contract --- .../ProfileSecurityPage.behavior.test.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/frontend/admin/src/pages/admin/ProfileSecurityPage/ProfileSecurityPage.behavior.test.tsx b/frontend/admin/src/pages/admin/ProfileSecurityPage/ProfileSecurityPage.behavior.test.tsx index 9f8904c..b418847 100644 --- a/frontend/admin/src/pages/admin/ProfileSecurityPage/ProfileSecurityPage.behavior.test.tsx +++ b/frontend/admin/src/pages/admin/ProfileSecurityPage/ProfileSecurityPage.behavior.test.tsx @@ -192,8 +192,10 @@ vi.mock('@/services/operation-logs', () => ({ listMyOperationLogs: () => listMyOperationLogsMock(), })) +const contactBindingsSectionMock = vi.fn(() =>
) + vi.mock('./ContactBindingsSection', () => ({ - ContactBindingsSection: () =>
, + ContactBindingsSection: (props: unknown) => contactBindingsSectionMock(props), })) function buildDevice(id: number, name: string, status: 0 | 1, isTrusted = false): Device { @@ -318,6 +320,7 @@ describe('ProfileSecurityPage behavior', () => { created_at: '2026-03-27 09:10:00', }], }) + contactBindingsSectionMock.mockClear() vi.spyOn(window, 'getComputedStyle').mockImplementation((element) => { return originalGetComputedStyle.call(window, element) @@ -467,6 +470,24 @@ describe('ProfileSecurityPage behavior', () => { expect(message.success).toHaveBeenCalledWith('密码修改成功') }) + it('passes contact binding capabilities to ContactBindingsSection', async () => { + render() + + await waitFor(() => expect(contactBindingsSectionMock).toHaveBeenCalled()) + const latestProps = contactBindingsSectionMock.mock.calls.at(-1)?.[0] as { + userId: number + emailBindingEnabled: boolean + phoneBindingEnabled: boolean + refreshSessionUser: () => Promise + } + + expect(latestProps.userId).toBe(1) + expect(latestProps.emailBindingEnabled).toBe(true) + expect(latestProps.phoneBindingEnabled).toBe(true) + await latestProps.refreshSessionUser() + expect(refreshUserMock).toHaveBeenCalledTimes(1) + }) + it('toggles device status, refetches the list, and deletes devices', async () => { const user = userEvent.setup()