-
Notifications
You must be signed in to change notification settings - Fork 4
Align notification avatars with IPFS gateway fallback #2229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6fde3d4
Align notification avatars with IPFS gateway fallback
prxt6529 8efff79
WIP
prxt6529 ce80f3c
WIP
prxt6529 8ac7d97
WIP
prxt6529 9df5b24
WIP
prxt6529 da5f878
Merge branch 'main' into notifications-ipfs-avatar-fallback
prxt6529 9ab7242
WIP
prxt6529 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
__tests__/components/brain/notifications/subcomponents/NotificationHeader.test.tsx
This file contains hidden or 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,99 @@ | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import type { ComponentProps, ReactNode } from "react"; | ||
| import NotificationHeader from "@/components/brain/notifications/subcomponents/NotificationHeader"; | ||
|
|
||
| type MockNextImageProps = ComponentProps<"img"> & { | ||
| readonly fill?: boolean | undefined; | ||
| readonly unoptimized?: boolean | undefined; | ||
| }; | ||
|
|
||
| jest.mock("next/image", () => ({ | ||
| __esModule: true, | ||
| default: ({ | ||
| fill: _fill, | ||
| unoptimized, | ||
| alt, | ||
| ...props | ||
| }: MockNextImageProps) => ( | ||
| // eslint-disable-next-line @next/next/no-img-element | ||
| <img | ||
| alt={alt ?? ""} | ||
| data-unoptimized={unoptimized ? "true" : "false"} | ||
| {...props} | ||
| /> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock("next/link", () => ({ | ||
| __esModule: true, | ||
| default: ({ | ||
| href, | ||
| children, | ||
| ...props | ||
| }: { | ||
| href: string; | ||
| children: ReactNode; | ||
| }) => ( | ||
| <a href={href} {...props}> | ||
| {children} | ||
| </a> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock("@/components/utils/tooltip/UserProfileTooltipWrapper", () => ({ | ||
| __esModule: true, | ||
| default: ({ children }: { children: ReactNode }) => <>{children}</>, | ||
| })); | ||
|
|
||
| jest.mock("@/components/nft-image/utils/gateway-fallback", () => ({ | ||
| getArweaveGatewayFallbackUrls: (url: string) => | ||
| url === "ipfs://gelato" | ||
| ? ["https://ipfs.6529.io/ipfs/gelato", "https://ipfs.io/ipfs/gelato"] | ||
| : [url], | ||
| })); | ||
|
|
||
| describe("NotificationHeader", () => { | ||
| it("prefers the configured ipfs gateway and falls back to ipfs.io on failure", () => { | ||
| render( | ||
| <NotificationHeader | ||
| author={ | ||
| { | ||
| id: "gelato-id", | ||
| handle: "GelatoGenesis", | ||
| pfp: "ipfs://gelato", | ||
| } as any | ||
| } | ||
| > | ||
| <span>posted</span> | ||
| </NotificationHeader> | ||
| ); | ||
|
|
||
| const firstAttempt = screen.getByRole("img", { | ||
| name: "GelatoGenesis", | ||
| }); | ||
| expect(firstAttempt).toHaveAttribute( | ||
| "src", | ||
| "https://ipfs.6529.io/ipfs/gelato" | ||
| ); | ||
| expect(firstAttempt).toHaveAttribute("data-unoptimized", "false"); | ||
|
|
||
| fireEvent.error(firstAttempt); | ||
|
|
||
| const secondAttempt = screen.getByRole("img", { | ||
| name: "GelatoGenesis", | ||
| }); | ||
| expect(secondAttempt).toHaveAttribute( | ||
| "src", | ||
| "https://ipfs.6529.io/ipfs/gelato" | ||
| ); | ||
| expect(secondAttempt).toHaveAttribute("data-unoptimized", "true"); | ||
|
|
||
| fireEvent.error(secondAttempt); | ||
|
|
||
| const thirdAttempt = screen.getByRole("img", { | ||
| name: "GelatoGenesis", | ||
| }); | ||
| expect(thirdAttempt).toHaveAttribute("src", "https://ipfs.io/ipfs/gelato"); | ||
| expect(thirdAttempt).toHaveAttribute("data-unoptimized", "false"); | ||
| }); | ||
| }); |
111 changes: 111 additions & 0 deletions
111
__tests__/components/common/OverlappingAvatars.test.tsx
This file contains hidden or 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,111 @@ | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import type { ReactNode } from "react"; | ||
| import OverlappingAvatars from "@/components/common/OverlappingAvatars"; | ||
|
|
||
| jest.mock("next/image", () => ({ | ||
| __esModule: true, | ||
| default: ({ | ||
| unoptimized, | ||
| alt, | ||
| ...props | ||
| }: { | ||
| unoptimized?: boolean; | ||
| alt?: string; | ||
| [key: string]: unknown; | ||
| }) => ( | ||
| // eslint-disable-next-line @next/next/no-img-element | ||
| <img | ||
| alt={alt ?? ""} | ||
| data-unoptimized={unoptimized ? "true" : "false"} | ||
| {...props} | ||
| /> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock("react-tooltip", () => ({ | ||
| Tooltip: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| })); | ||
|
|
||
| jest.mock("@/hooks/useIsTouchDevice", () => ({ | ||
| __esModule: true, | ||
| default: () => false, | ||
| })); | ||
|
|
||
| jest.mock("@/components/nft-image/utils/gateway-fallback", () => ({ | ||
| getArweaveGatewayFallbackUrls: (url: string) => | ||
| url === "ipfs://gpebbles" | ||
| ? ["https://ipfs.6529.io/ipfs/gpebbles", "https://ipfs.io/ipfs/gpebbles"] | ||
| : [url], | ||
| })); | ||
|
|
||
| describe("OverlappingAvatars", () => { | ||
| it("retries an optimized avatar load with unoptimized mode before showing fallback", () => { | ||
| render( | ||
| <OverlappingAvatars | ||
| items={[ | ||
| { | ||
| key: "gpebbles", | ||
| pfpUrl: "https://cdn.warpcast.com/avatars/gpebbles.png", | ||
| ariaLabel: "View @gpebbles", | ||
| fallback: "GP", | ||
| }, | ||
| ]} | ||
| /> | ||
| ); | ||
|
|
||
| const firstAttempt = screen.getByRole("img", { name: "View @gpebbles" }); | ||
| expect(firstAttempt).toHaveAttribute("data-unoptimized", "false"); | ||
|
|
||
| fireEvent.error(firstAttempt); | ||
|
|
||
| const retryAttempt = screen.getByRole("img", { name: "View @gpebbles" }); | ||
| expect(retryAttempt).toHaveAttribute("data-unoptimized", "true"); | ||
|
|
||
| fireEvent.error(retryAttempt); | ||
|
|
||
| expect(screen.getByText("GP")).toBeInTheDocument(); | ||
| expect( | ||
| screen.queryByRole("img", { name: "View @gpebbles" }) | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("falls back from the configured ipfs gateway to ipfs.io", () => { | ||
| render( | ||
| <OverlappingAvatars | ||
| items={[ | ||
| { | ||
| key: "gpebbles", | ||
| pfpUrl: "ipfs://gpebbles", | ||
| ariaLabel: "View @gpebbles", | ||
| fallback: "GP", | ||
| }, | ||
| ]} | ||
| /> | ||
| ); | ||
|
|
||
| const firstAttempt = screen.getByRole("img", { name: "View @gpebbles" }); | ||
| expect(firstAttempt).toHaveAttribute( | ||
| "src", | ||
| "https://ipfs.6529.io/ipfs/gpebbles" | ||
| ); | ||
| expect(firstAttempt).toHaveAttribute("data-unoptimized", "false"); | ||
|
|
||
| fireEvent.error(firstAttempt); | ||
|
|
||
| const secondAttempt = screen.getByRole("img", { name: "View @gpebbles" }); | ||
| expect(secondAttempt).toHaveAttribute( | ||
| "src", | ||
| "https://ipfs.6529.io/ipfs/gpebbles" | ||
| ); | ||
| expect(secondAttempt).toHaveAttribute("data-unoptimized", "true"); | ||
|
|
||
| fireEvent.error(secondAttempt); | ||
|
|
||
| const thirdAttempt = screen.getByRole("img", { name: "View @gpebbles" }); | ||
| expect(thirdAttempt).toHaveAttribute( | ||
| "src", | ||
| "https://ipfs.io/ipfs/gpebbles" | ||
| ); | ||
| expect(thirdAttempt).toHaveAttribute("data-unoptimized", "false"); | ||
| }); | ||
| }); |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.