|
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import { render, screen } from "../../../../../../test/src/react-render.js"; |
| 3 | +import { useSocialProfiles } from "../../../../core/social/useSocialProfiles.js"; |
| 4 | +import { useProfiles } from "../../../hooks/wallets/useProfiles.js"; |
| 5 | +import { LinkedProfilesScreen } from "./LinkedProfilesScreen.jsx"; |
| 6 | + |
| 7 | +// Mock the hooks |
| 8 | +vi.mock("../../../hooks/wallets/useProfiles"); |
| 9 | +vi.mock("../../../../core/social/useSocialProfiles"); |
| 10 | +vi.mock("../../components/Img", () => ({ |
| 11 | + Img: () => <div data-testid="mock-img">Mock Image</div>, |
| 12 | +})); |
| 13 | + |
| 14 | +describe("LinkedProfilesScreen", () => { |
| 15 | + const mockClient = { |
| 16 | + clientId: "test-client-id", |
| 17 | + secretKey: undefined, |
| 18 | + }; |
| 19 | + |
| 20 | + const mockProps = { |
| 21 | + onBack: vi.fn(), |
| 22 | + setScreen: vi.fn(), |
| 23 | + locale: { |
| 24 | + manageWallet: { |
| 25 | + linkedProfiles: "Linked Profiles", |
| 26 | + linkProfile: "Link Profile", |
| 27 | + }, |
| 28 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 29 | + } as any, |
| 30 | + client: mockClient, |
| 31 | + }; |
| 32 | + |
| 33 | + beforeEach(() => { |
| 34 | + vi.mocked(useSocialProfiles).mockReturnValue({ |
| 35 | + data: undefined, |
| 36 | + isLoading: false, |
| 37 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 38 | + } as any); |
| 39 | + }); |
| 40 | + |
| 41 | + describe("getProfileDisplayName", () => { |
| 42 | + it("should display email for email profile type", () => { |
| 43 | + vi.mocked(useProfiles).mockReturnValue({ |
| 44 | + data: [{ type: "email", details: { email: "test@example.com" } }], |
| 45 | + isLoading: false, |
| 46 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 47 | + } as any); |
| 48 | + |
| 49 | + render(<LinkedProfilesScreen {...mockProps} />); |
| 50 | + expect(screen.getByText("test@example.com")).toBeInTheDocument(); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should display email for google profile type", () => { |
| 54 | + vi.mocked(useProfiles).mockReturnValue({ |
| 55 | + data: [{ type: "google", details: { email: "google@example.com" } }], |
| 56 | + isLoading: false, |
| 57 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 58 | + } as any); |
| 59 | + |
| 60 | + render(<LinkedProfilesScreen {...mockProps} />); |
| 61 | + expect(screen.getByText("google@example.com")).toBeInTheDocument(); |
| 62 | + }); |
| 63 | + |
| 64 | + it("should display phone number for phone profile type", () => { |
| 65 | + vi.mocked(useProfiles).mockReturnValue({ |
| 66 | + data: [{ type: "phone", details: { phone: "+1234567890" } }], |
| 67 | + isLoading: false, |
| 68 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 69 | + } as any); |
| 70 | + |
| 71 | + render(<LinkedProfilesScreen {...mockProps} />); |
| 72 | + expect(screen.getByText("+1234567890")).toBeInTheDocument(); |
| 73 | + }); |
| 74 | + |
| 75 | + it("should display shortened address when address is present", () => { |
| 76 | + vi.mocked(useProfiles).mockReturnValue({ |
| 77 | + data: [ |
| 78 | + { |
| 79 | + type: "wallet", |
| 80 | + details: { address: "0x1234567890abcdef1234567890abcdef12345678" }, |
| 81 | + }, |
| 82 | + ], |
| 83 | + isLoading: false, |
| 84 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 85 | + } as any); |
| 86 | + |
| 87 | + render(<LinkedProfilesScreen {...mockProps} />); |
| 88 | + expect(screen.getByText("0x123456...345678")).toBeInTheDocument(); |
| 89 | + }); |
| 90 | + |
| 91 | + it("should display email for cognito profile type", () => { |
| 92 | + vi.mocked(useProfiles).mockReturnValue({ |
| 93 | + data: [{ type: "cognito", details: { email: "cognito@example.com" } }], |
| 94 | + isLoading: false, |
| 95 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 96 | + } as any); |
| 97 | + |
| 98 | + render(<LinkedProfilesScreen {...mockProps} />); |
| 99 | + expect(screen.getByText("cognito@example.com")).toBeInTheDocument(); |
| 100 | + }); |
| 101 | + |
| 102 | + it("should display Custom Profile for custom_auth_endpoint", () => { |
| 103 | + vi.mocked(useProfiles).mockReturnValue({ |
| 104 | + data: [{ type: "Custom_auth_endpoint", details: {} }], |
| 105 | + isLoading: false, |
| 106 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 107 | + } as any); |
| 108 | + |
| 109 | + render(<LinkedProfilesScreen {...mockProps} />); |
| 110 | + expect(screen.getByText("Custom Profile")).toBeInTheDocument(); |
| 111 | + }); |
| 112 | + |
| 113 | + it("should capitalize unknown profile types", () => { |
| 114 | + vi.mocked(useProfiles).mockReturnValue({ |
| 115 | + data: [{ type: "unknown", details: {} }], |
| 116 | + isLoading: false, |
| 117 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 118 | + } as any); |
| 119 | + |
| 120 | + render(<LinkedProfilesScreen {...mockProps} />); |
| 121 | + expect(screen.getByText("Unknown")).toBeInTheDocument(); |
| 122 | + }); |
| 123 | + |
| 124 | + it("should not display guest profiles", () => { |
| 125 | + vi.mocked(useProfiles).mockReturnValue({ |
| 126 | + data: [{ type: "guest", details: {} }], |
| 127 | + isLoading: false, |
| 128 | + // biome-ignore lint/suspicious/noExplicitAny: Mocking data |
| 129 | + } as any); |
| 130 | + |
| 131 | + render(<LinkedProfilesScreen {...mockProps} />); |
| 132 | + expect(screen.queryByText("Guest")).not.toBeInTheDocument(); |
| 133 | + }); |
| 134 | + }); |
| 135 | +}); |
0 commit comments