|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { |
| 3 | + fireEvent, |
| 4 | + render, |
| 5 | + screen, |
| 6 | +} from "../../../../../test/src/react-render.js"; |
| 7 | +import { TEST_CLIENT } from "../../../../../test/src/test-clients.js"; |
| 8 | +import { createWallet } from "../../../../wallets/create-wallet.js"; |
| 9 | +import { ConnectWalletSocialOptions } from "./ConnectWalletSocialOptions.js"; |
| 10 | +import en from "./locale/en.js"; |
| 11 | + |
| 12 | +describe("ConnectWalletSocialOptions", () => { |
| 13 | + const mockSelect = vi.fn(); |
| 14 | + const mockDone = vi.fn(); |
| 15 | + |
| 16 | + const defaultProps = { |
| 17 | + select: mockSelect, |
| 18 | + done: mockDone, |
| 19 | + locale: en, |
| 20 | + chain: undefined, |
| 21 | + client: TEST_CLIENT, |
| 22 | + size: "compact" as const, |
| 23 | + isLinking: false, |
| 24 | + disabled: false, |
| 25 | + }; |
| 26 | + |
| 27 | + it("renders Sign in with Wallet button when enabled and not linking", () => { |
| 28 | + render( |
| 29 | + <ConnectWalletSocialOptions |
| 30 | + {...defaultProps} |
| 31 | + wallet={createWallet("inApp", { |
| 32 | + auth: { |
| 33 | + options: ["wallet"], |
| 34 | + }, |
| 35 | + })} |
| 36 | + />, |
| 37 | + ); |
| 38 | + |
| 39 | + const walletButton = screen.getByRole("button", { |
| 40 | + name: /sign in with wallet/i, |
| 41 | + }); |
| 42 | + |
| 43 | + expect(walletButton).toBeInTheDocument(); |
| 44 | + expect(walletButton).toHaveTextContent("Sign in with Wallet"); |
| 45 | + }); |
| 46 | + |
| 47 | + it("does not render Sign in with Wallet button when isLinking is true", () => { |
| 48 | + render( |
| 49 | + <ConnectWalletSocialOptions |
| 50 | + {...defaultProps} |
| 51 | + isLinking={true} |
| 52 | + wallet={createWallet("inApp", { |
| 53 | + auth: { |
| 54 | + options: ["wallet"], |
| 55 | + }, |
| 56 | + })} |
| 57 | + />, |
| 58 | + ); |
| 59 | + |
| 60 | + const walletButton = screen.queryByRole("button", { |
| 61 | + name: /sign in with wallet/i, |
| 62 | + }); |
| 63 | + |
| 64 | + expect(walletButton).not.toBeInTheDocument(); |
| 65 | + }); |
| 66 | + |
| 67 | + it("calls handleWalletLogin when Sign in with Wallet button is clicked", () => { |
| 68 | + render( |
| 69 | + <ConnectWalletSocialOptions |
| 70 | + {...defaultProps} |
| 71 | + wallet={createWallet("inApp", { |
| 72 | + auth: { |
| 73 | + options: ["wallet"], |
| 74 | + }, |
| 75 | + })} |
| 76 | + />, |
| 77 | + ); |
| 78 | + |
| 79 | + const walletButton = screen.getByRole("button", { |
| 80 | + name: /sign in with wallet/i, |
| 81 | + }); |
| 82 | + |
| 83 | + fireEvent.click(walletButton); |
| 84 | + |
| 85 | + expect(mockSelect).toHaveBeenCalled(); |
| 86 | + }); |
| 87 | +}); |
0 commit comments