-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore image fallbacks (#11307)
* add fallback image and use in ThreeUpImageLayout * add fallback image in places we added url checks * few missed images * fix imports * add test for fallback image
- Loading branch information
1 parent
465b008
commit 1d1f97e
Showing
15 changed files
with
117 additions
and
65 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
23 changes: 23 additions & 0 deletions
23
src/app/Components/ImageWithFallback/ImageWithFallback.tests.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,23 @@ | ||
import { ImageWithFallback } from "app/Components/ImageWithFallback/ImageWithFallback" | ||
import { renderWithWrappers } from "app/utils/tests/renderWithWrappers" | ||
|
||
describe("ImageWithFallback", () => { | ||
it("renders without error", () => { | ||
renderWithWrappers(<ImageWithFallback />) | ||
}) | ||
|
||
it("renders the image when a url is passed", async () => { | ||
const view = renderWithWrappers( | ||
<ImageWithFallback src="https://example.com/image.jpg" width={100} height={100} /> | ||
) | ||
const image = await view.findByTestId("image") | ||
expect(image).toBeTruthy() | ||
}) | ||
|
||
it("renders the fallback when a url is not passed", async () => { | ||
const view = renderWithWrappers(<ImageWithFallback width={100} height={100} />) | ||
|
||
const fallbackImage = await view.findByTestId("fallback-image") | ||
expect(fallbackImage).toBeTruthy() | ||
}) | ||
}) |
27 changes: 27 additions & 0 deletions
27
src/app/Components/ImageWithFallback/ImageWithFallback.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,27 @@ | ||
import { Box, Image, ImageProps } from "@artsy/palette-mobile" | ||
|
||
// Extend ImageProps but make `src` optional | ||
type ImageWithFallbackProps = Omit<ImageProps, "src"> & { | ||
src?: string | null | ||
} | ||
|
||
export const ImageWithFallback: React.FC<ImageWithFallbackProps> = ({ | ||
src, | ||
width, | ||
height, | ||
...props | ||
}) => { | ||
if (!src) { | ||
return ( | ||
<Box | ||
testID="fallback-image" | ||
width={width} | ||
height={height} | ||
backgroundColor="black10" | ||
borderRadius="md" | ||
/> | ||
) | ||
} | ||
|
||
return <Image testID="image" {...props} src={src} width={width} height={height} /> | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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