-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] Fix: Custom auth profile label (#5660)
<!-- start pr-codex --> ## PR-Codex overview This PR focuses on improving the display of linked profiles in the `LinkedProfilesScreen` component by correctly handling the "Custom Auth" profile type and enhancing unit tests for various profile types. ### Detailed summary - Updated the label for the "Custom Auth" profile type to "Custom Profile". - Added unit tests for various profile types including email, google, phone, wallet address, cognito, custom_auth_endpoint, and unknown types. - Ensured guest profiles are not displayed. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
1 parent
dcd5822
commit d5a68c8
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"thirdweb": patch | ||
--- | ||
|
||
Fix: Correctly cleans the "Custom Auth" profile type label |
135 changes: 135 additions & 0 deletions
135
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/LinkedProfilesScreen.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
import { render, screen } from "../../../../../../test/src/react-render.js"; | ||
import { useSocialProfiles } from "../../../../core/social/useSocialProfiles.js"; | ||
import { useProfiles } from "../../../hooks/wallets/useProfiles.js"; | ||
import { LinkedProfilesScreen } from "./LinkedProfilesScreen.jsx"; | ||
|
||
// Mock the hooks | ||
vi.mock("../../../hooks/wallets/useProfiles"); | ||
vi.mock("../../../../core/social/useSocialProfiles"); | ||
vi.mock("../../components/Img", () => ({ | ||
Img: () => <div data-testid="mock-img">Mock Image</div>, | ||
})); | ||
|
||
describe("LinkedProfilesScreen", () => { | ||
const mockClient = { | ||
clientId: "test-client-id", | ||
secretKey: undefined, | ||
}; | ||
|
||
const mockProps = { | ||
onBack: vi.fn(), | ||
setScreen: vi.fn(), | ||
locale: { | ||
manageWallet: { | ||
linkedProfiles: "Linked Profiles", | ||
linkProfile: "Link Profile", | ||
}, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any, | ||
client: mockClient, | ||
}; | ||
|
||
beforeEach(() => { | ||
vi.mocked(useSocialProfiles).mockReturnValue({ | ||
data: undefined, | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
}); | ||
|
||
describe("getProfileDisplayName", () => { | ||
it("should display email for email profile type", () => { | ||
vi.mocked(useProfiles).mockReturnValue({ | ||
data: [{ type: "email", details: { email: "test@example.com" } }], | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
|
||
render(<LinkedProfilesScreen {...mockProps} />); | ||
expect(screen.getByText("test@example.com")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display email for google profile type", () => { | ||
vi.mocked(useProfiles).mockReturnValue({ | ||
data: [{ type: "google", details: { email: "google@example.com" } }], | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
|
||
render(<LinkedProfilesScreen {...mockProps} />); | ||
expect(screen.getByText("google@example.com")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display phone number for phone profile type", () => { | ||
vi.mocked(useProfiles).mockReturnValue({ | ||
data: [{ type: "phone", details: { phone: "+1234567890" } }], | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
|
||
render(<LinkedProfilesScreen {...mockProps} />); | ||
expect(screen.getByText("+1234567890")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display shortened address when address is present", () => { | ||
vi.mocked(useProfiles).mockReturnValue({ | ||
data: [ | ||
{ | ||
type: "wallet", | ||
details: { address: "0x1234567890abcdef1234567890abcdef12345678" }, | ||
}, | ||
], | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
|
||
render(<LinkedProfilesScreen {...mockProps} />); | ||
expect(screen.getByText("0x123456...345678")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display email for cognito profile type", () => { | ||
vi.mocked(useProfiles).mockReturnValue({ | ||
data: [{ type: "cognito", details: { email: "cognito@example.com" } }], | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
|
||
render(<LinkedProfilesScreen {...mockProps} />); | ||
expect(screen.getByText("cognito@example.com")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display Custom Profile for custom_auth_endpoint", () => { | ||
vi.mocked(useProfiles).mockReturnValue({ | ||
data: [{ type: "Custom_auth_endpoint", details: {} }], | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
|
||
render(<LinkedProfilesScreen {...mockProps} />); | ||
expect(screen.getByText("Custom Profile")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should capitalize unknown profile types", () => { | ||
vi.mocked(useProfiles).mockReturnValue({ | ||
data: [{ type: "unknown", details: {} }], | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
|
||
render(<LinkedProfilesScreen {...mockProps} />); | ||
expect(screen.getByText("Unknown")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should not display guest profiles", () => { | ||
vi.mocked(useProfiles).mockReturnValue({ | ||
data: [{ type: "guest", details: {} }], | ||
isLoading: false, | ||
// biome-ignore lint/suspicious/noExplicitAny: Mocking data | ||
} as any); | ||
|
||
render(<LinkedProfilesScreen {...mockProps} />); | ||
expect(screen.queryByText("Guest")).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters